2018-07-18 14:13:57 -05:00
|
|
|
package io.github.wulkanowy
|
|
|
|
|
2021-03-02 17:34:25 -06:00
|
|
|
import android.annotation.SuppressLint
|
2020-08-02 11:29:41 -05:00
|
|
|
import android.app.Application
|
2018-08-22 15:31:17 -05:00
|
|
|
import android.content.Context
|
2020-02-22 14:24:06 -06:00
|
|
|
import android.util.Log.DEBUG
|
2019-06-06 15:32:43 -05:00
|
|
|
import android.util.Log.INFO
|
|
|
|
import android.util.Log.VERBOSE
|
2021-01-31 15:38:30 -06:00
|
|
|
import android.webkit.WebView
|
2021-03-02 17:34:25 -06:00
|
|
|
import androidx.fragment.app.FragmentManager
|
2020-08-02 11:29:41 -05:00
|
|
|
import androidx.hilt.work.HiltWorkerFactory
|
2018-10-20 13:59:46 -05:00
|
|
|
import androidx.multidex.MultiDex
|
2019-03-09 03:13:36 -06:00
|
|
|
import androidx.work.Configuration
|
2019-11-03 05:37:03 -06:00
|
|
|
import com.yariksoffice.lingver.Lingver
|
2020-08-02 11:29:41 -05:00
|
|
|
import dagger.hilt.android.HiltAndroidApp
|
2020-02-22 14:24:06 -06:00
|
|
|
import fr.bipi.tressence.file.FileLoggerTree
|
2021-01-03 17:13:50 -06:00
|
|
|
import io.github.wulkanowy.data.repositories.PreferencesRepository
|
2019-08-26 13:54:20 -05:00
|
|
|
import io.github.wulkanowy.ui.base.ThemeManager
|
2019-04-26 16:53:02 -05:00
|
|
|
import io.github.wulkanowy.utils.ActivityLifecycleLogger
|
2020-12-26 15:40:21 -06:00
|
|
|
import io.github.wulkanowy.utils.AnalyticsHelper
|
2019-06-06 15:32:43 -05:00
|
|
|
import io.github.wulkanowy.utils.AppInfo
|
2020-10-29 07:58:56 -05:00
|
|
|
import io.github.wulkanowy.utils.CrashLogExceptionTree
|
|
|
|
import io.github.wulkanowy.utils.CrashLogTree
|
2018-10-03 14:28:23 -05:00
|
|
|
import io.github.wulkanowy.utils.DebugLogTree
|
2018-07-18 14:13:57 -05:00
|
|
|
import timber.log.Timber
|
2018-11-10 16:24:33 -06:00
|
|
|
import javax.inject.Inject
|
2018-07-18 14:13:57 -05:00
|
|
|
|
2020-08-02 11:29:41 -05:00
|
|
|
@HiltAndroidApp
|
|
|
|
class WulkanowyApp : Application(), Configuration.Provider {
|
2018-07-18 14:13:57 -05:00
|
|
|
|
2019-03-09 03:13:36 -06:00
|
|
|
@Inject
|
2020-08-02 11:29:41 -05:00
|
|
|
lateinit var workerFactory: HiltWorkerFactory
|
2019-03-09 03:13:36 -06:00
|
|
|
|
2019-08-26 13:54:20 -05:00
|
|
|
@Inject
|
|
|
|
lateinit var themeManager: ThemeManager
|
|
|
|
|
2019-06-06 15:32:43 -05:00
|
|
|
@Inject
|
|
|
|
lateinit var appInfo: AppInfo
|
|
|
|
|
2020-12-26 15:40:21 -06:00
|
|
|
@Inject
|
|
|
|
lateinit var preferencesRepository: PreferencesRepository
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
lateinit var analyticsHelper: AnalyticsHelper
|
|
|
|
|
2018-08-22 15:31:17 -05:00
|
|
|
override fun attachBaseContext(base: Context?) {
|
|
|
|
super.attachBaseContext(base)
|
|
|
|
MultiDex.install(this)
|
|
|
|
}
|
2018-07-18 14:13:57 -05:00
|
|
|
|
2021-03-02 17:34:25 -06:00
|
|
|
@SuppressLint("UnsafeOptInUsageWarning")
|
2018-07-18 14:13:57 -05:00
|
|
|
override fun onCreate() {
|
|
|
|
super.onCreate()
|
2021-03-02 17:34:25 -06:00
|
|
|
FragmentManager.enableNewStateManager(false)
|
2019-04-19 16:52:34 -05:00
|
|
|
|
2021-01-31 15:38:30 -06:00
|
|
|
initializeAppLanguage()
|
|
|
|
themeManager.applyDefaultTheme()
|
2019-04-19 16:52:34 -05:00
|
|
|
initLogging()
|
2021-01-31 15:38:30 -06:00
|
|
|
fixWebViewLocale()
|
2019-06-06 15:32:43 -05:00
|
|
|
}
|
|
|
|
|
2019-04-19 16:52:34 -05:00
|
|
|
private fun initLogging() {
|
2019-06-06 15:32:43 -05:00
|
|
|
if (appInfo.isDebug) {
|
2020-02-22 14:24:06 -06:00
|
|
|
Timber.plant(DebugLogTree())
|
2021-01-31 15:38:30 -06:00
|
|
|
Timber.plant(
|
|
|
|
FileLoggerTree.Builder()
|
|
|
|
.withFileName("wulkanowy.%g.log")
|
|
|
|
.withDirName(applicationContext.filesDir.absolutePath)
|
|
|
|
.withFileLimit(10)
|
|
|
|
.withMinPriority(DEBUG)
|
|
|
|
.build()
|
2020-02-22 14:24:06 -06:00
|
|
|
)
|
2019-04-19 16:52:34 -05:00
|
|
|
} else {
|
2020-10-29 07:58:56 -05:00
|
|
|
Timber.plant(CrashLogExceptionTree())
|
|
|
|
Timber.plant(CrashLogTree())
|
2019-04-19 16:52:34 -05:00
|
|
|
}
|
2019-04-26 16:53:02 -05:00
|
|
|
registerActivityLifecycleCallbacks(ActivityLifecycleLogger())
|
2018-07-18 14:13:57 -05:00
|
|
|
}
|
|
|
|
|
2021-01-31 15:38:30 -06:00
|
|
|
private fun initializeAppLanguage() {
|
|
|
|
Lingver.init(this)
|
|
|
|
|
|
|
|
if (preferencesRepository.appLanguage == "system") {
|
|
|
|
Lingver.getInstance().setFollowSystemLocale(this)
|
|
|
|
analyticsHelper.logEvent("language", "startup" to appInfo.systemLanguage)
|
2020-12-26 15:40:21 -06:00
|
|
|
} else {
|
2021-01-31 15:38:30 -06:00
|
|
|
analyticsHelper.logEvent("language", "startup" to preferencesRepository.appLanguage)
|
2020-12-26 15:40:21 -06:00
|
|
|
}
|
2021-01-31 15:38:30 -06:00
|
|
|
}
|
2020-12-26 15:40:21 -06:00
|
|
|
|
2021-01-31 15:38:30 -06:00
|
|
|
private fun fixWebViewLocale() {
|
|
|
|
//https://stackoverflow.com/questions/40398528/android-webview-language-changes-abruptly-on-android-7-0-and-above
|
2021-02-03 13:59:24 -06:00
|
|
|
try {
|
|
|
|
WebView(this).destroy()
|
|
|
|
} catch (e: Exception) {
|
|
|
|
//Ignore exceptions
|
|
|
|
}
|
2020-12-26 15:40:21 -06:00
|
|
|
}
|
|
|
|
|
2019-09-01 06:24:21 -05:00
|
|
|
override fun getWorkManagerConfiguration() = Configuration.Builder()
|
|
|
|
.setWorkerFactory(workerFactory)
|
|
|
|
.setMinimumLoggingLevel(if (appInfo.isDebug) VERBOSE else INFO)
|
|
|
|
.build()
|
2018-07-18 14:13:57 -05:00
|
|
|
}
|