11package com.appcontrolx
22
33import android.app.Application
4+ import android.util.Log
45import androidx.appcompat.app.AppCompatDelegate
5- import androidx.hilt.work.HiltWorkerFactory
66import androidx.preference.PreferenceManager
7- import androidx.work.Configuration
87import com.appcontrolx.utils.Constants
9- import com.google.firebase.crashlytics.FirebaseCrashlytics
108import com.topjohnwu.superuser.Shell
119import dagger.hilt.android.HiltAndroidApp
12- import timber.log.Timber
13- import javax.inject.Inject
1410
1511@HiltAndroidApp
16- class App : Application (), Configuration.Provider {
17-
18- @Inject
19- lateinit var workerFactory: HiltWorkerFactory
12+ class App : Application () {
2013
2114 companion object {
15+ private const val TAG = " AppControlX"
16+
2217 init {
2318 Shell .enableVerboseLogging = BuildConfig .DEBUG
2419 Shell .setDefaultBuilder(
@@ -31,50 +26,13 @@ class App : Application(), Configuration.Provider {
3126
3227 override fun onCreate () {
3328 super .onCreate()
34- initTimber()
35- initCrashlytics()
3629 applyTheme()
37- }
38-
39- private fun initTimber () {
40- if (BuildConfig .DEBUG ) {
41- Timber .plant(Timber .DebugTree ())
42- } else {
43- Timber .plant(CrashlyticsTree ())
44- }
45- Timber .d(" App initialized" )
46- }
47-
48- private fun initCrashlytics () {
49- FirebaseCrashlytics .getInstance().apply {
50- setCrashlyticsCollectionEnabled(! BuildConfig .DEBUG )
51- setCustomKey(" app_version" , BuildConfig .VERSION_NAME )
52- setCustomKey(" version_code" , BuildConfig .VERSION_CODE )
53- }
30+ Log .d(TAG , " App initialized" )
5431 }
5532
5633 private fun applyTheme () {
5734 val prefs = PreferenceManager .getDefaultSharedPreferences(this )
5835 val theme = prefs.getInt(Constants .PREFS_THEME , AppCompatDelegate .MODE_NIGHT_FOLLOW_SYSTEM )
5936 AppCompatDelegate .setDefaultNightMode(theme)
6037 }
61-
62- override val workManagerConfiguration: Configuration
63- get() = Configuration .Builder ()
64- .setWorkerFactory(workerFactory)
65- .build()
66-
67- /* *
68- * Custom Timber tree that logs to Crashlytics in production
69- */
70- private class CrashlyticsTree : Timber .Tree () {
71- override fun log (priority : Int , tag : String? , message : String , t : Throwable ? ) {
72- if (priority == android.util.Log .ERROR || priority == android.util.Log .WARN ) {
73- FirebaseCrashlytics .getInstance().apply {
74- log(" $tag : $message " )
75- t?.let { recordException(it) }
76- }
77- }
78- }
79- }
8038}
0 commit comments