@@ -8,19 +8,14 @@ import android.util.Log
88import com.hazz.kotlinmvp.utils.DisplayManager
99import com.orhanobut.logger.AndroidLogAdapter
1010import com.orhanobut.logger.Logger
11- import kotlin.properties.Delegates
12- import com.scwang.smartrefresh.layout.constant.SpinnerStyle
13- import com.scwang.smartrefresh.layout.footer.ClassicsFooter
14- import com.scwang.smartrefresh.layout.api.RefreshLayout
15- import com.scwang.smartrefresh.layout.api.RefreshFooter
16- import com.scwang.smartrefresh.layout.api.DefaultRefreshFooterCreater
17- import com.scwang.smartrefresh.layout.SmartRefreshLayout
18- import com.scwang.smartrefresh.layout.header.ClassicsHeader
19- import com.scwang.smartrefresh.layout.api.RefreshHeader
20- import com.scwang.smartrefresh.layout.api.DefaultRefreshHeaderCreater
2111import com.orhanobut.logger.PrettyFormatStrategy
22- import com.orhanobut.logger.FormatStrategy
2312import com.scwang.smartrefresh.header.MaterialHeader
13+ import com.scwang.smartrefresh.layout.SmartRefreshLayout
14+ import com.squareup.leakcanary.LeakCanary
15+ import com.squareup.leakcanary.RefWatcher
16+ import com.tencent.bugly.crashreport.CrashReport
17+ import kotlinx.android.synthetic.main.fragment_home.*
18+ import kotlin.properties.Delegates
2419
2520
2621/* *
@@ -29,7 +24,7 @@ import com.scwang.smartrefresh.header.MaterialHeader
2924
3025class MyApplication : Application (){
3126
32-
27+ private var refWatcher : RefWatcher ? = null
3328
3429 companion object {
3530
@@ -39,35 +34,31 @@ class MyApplication : Application(){
3934 var context: Context by Delegates .notNull()
4035 private set
4136
42-
43- }
44- init {
45- // static 代码段可以防止内存泄露 (全局的下拉刷新,上拉加载样式)
46- // 设置全局的Header构建器
47- SmartRefreshLayout .setDefaultRefreshHeaderCreater { context, layout ->
48- layout?.setPrimaryColorsId(R .color.colorPrimary, android.R .color.white) // 全局设置主题颜色
49- MaterialHeader (context)
37+ fun getRefWatcher (context : Context ): RefWatcher ? {
38+ val myApplication = context.applicationContext as MyApplication
39+ return myApplication.refWatcher
5040 }
51- // 设置全局的Footer构建器
52- // SmartRefreshLayout.setDefaultRefreshFooterCreater { context, _ ->
53- // //指定为经典Footer,默认是 BallPulseFooter
54- // ClassicsFooter(context).setSpinnerStyle(SpinnerStyle.Scale)
55- // }
56- }
57-
5841
42+ }
5943
6044 override fun onCreate () {
6145 super .onCreate()
62-
6346 context = applicationContext
47+ refWatcher = setupLeakCanary()
6448 initConfig()
6549 DisplayManager .init (this )
6650 registerActivityLifecycleCallbacks(mActivityLifecycleCallbacks)
6751
6852
6953 }
7054
55+ private fun setupLeakCanary (): RefWatcher {
56+ return if (LeakCanary .isInAnalyzerProcess(this )) {
57+ RefWatcher .DISABLED
58+ } else LeakCanary .install(this )
59+ }
60+
61+
7162 /* *
7263 * 初始化配置
7364 */
@@ -84,7 +75,8 @@ class MyApplication : Application(){
8475 return BuildConfig .DEBUG
8576 }
8677 })
87-
78+ // 测试阶段建议设置成true,发布时设置为false。
79+ CrashReport .initCrashReport(applicationContext, Constants .BUGLY_APPID , false )
8880 }
8981
9082
0 commit comments