2018-07-18 21:13:57 +02:00
|
|
|
package io.github.wulkanowy
|
|
|
|
|
2018-08-22 22:31:17 +02:00
|
|
|
import android.content.Context
|
2018-11-10 23:24:33 +01:00
|
|
|
import androidx.appcompat.app.AppCompatDelegate
|
2018-10-20 20:59:46 +02:00
|
|
|
import androidx.multidex.MultiDex
|
2019-03-09 10:13:36 +01:00
|
|
|
import androidx.work.Configuration
|
|
|
|
import androidx.work.WorkManager
|
2018-07-18 21:13:57 +02:00
|
|
|
import com.crashlytics.android.Crashlytics
|
|
|
|
import com.crashlytics.android.core.CrashlyticsCore
|
|
|
|
import com.jakewharton.threetenabp.AndroidThreeTen
|
|
|
|
import dagger.android.AndroidInjector
|
|
|
|
import dagger.android.support.DaggerApplication
|
|
|
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
2018-10-03 21:28:23 +02:00
|
|
|
import eu.davidea.flexibleadapter.utils.Log
|
2018-07-18 21:13:57 +02:00
|
|
|
import io.fabric.sdk.android.Fabric
|
2018-10-03 21:28:23 +02:00
|
|
|
import io.github.wulkanowy.BuildConfig.DEBUG
|
2019-02-13 21:44:40 +01:00
|
|
|
import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository
|
2018-07-18 21:13:57 +02:00
|
|
|
import io.github.wulkanowy.di.DaggerAppComponent
|
2019-03-09 10:13:36 +01:00
|
|
|
import io.github.wulkanowy.services.sync.SyncWorkerFactory
|
2018-10-03 21:28:23 +02:00
|
|
|
import io.github.wulkanowy.utils.CrashlyticsTree
|
|
|
|
import io.github.wulkanowy.utils.DebugLogTree
|
2019-03-26 14:32:23 +01:00
|
|
|
import io.reactivex.exceptions.UndeliverableException
|
|
|
|
import io.reactivex.plugins.RxJavaPlugins
|
2018-07-18 21:13:57 +02:00
|
|
|
import timber.log.Timber
|
2019-03-26 14:32:23 +01:00
|
|
|
import java.io.IOException
|
|
|
|
import java.lang.Exception
|
2018-11-10 23:24:33 +01:00
|
|
|
import javax.inject.Inject
|
2018-07-18 21:13:57 +02:00
|
|
|
|
|
|
|
class WulkanowyApp : DaggerApplication() {
|
|
|
|
|
2018-11-10 23:24:33 +01:00
|
|
|
@Inject
|
|
|
|
lateinit var prefRepository: PreferencesRepository
|
|
|
|
|
2019-03-09 10:13:36 +01:00
|
|
|
@Inject
|
|
|
|
lateinit var workerFactory: SyncWorkerFactory
|
|
|
|
|
2018-08-22 22:31:17 +02:00
|
|
|
override fun attachBaseContext(base: Context?) {
|
|
|
|
super.attachBaseContext(base)
|
|
|
|
MultiDex.install(this)
|
|
|
|
}
|
2018-07-18 21:13:57 +02:00
|
|
|
|
|
|
|
override fun onCreate() {
|
|
|
|
super.onCreate()
|
|
|
|
AndroidThreeTen.init(this)
|
|
|
|
initializeFabric()
|
2018-10-03 21:28:23 +02:00
|
|
|
if (DEBUG) enableDebugLog()
|
2018-11-10 23:24:33 +01:00
|
|
|
AppCompatDelegate.setDefaultNightMode(prefRepository.currentTheme)
|
2019-03-09 10:13:36 +01:00
|
|
|
WorkManager.initialize(this, Configuration.Builder().setWorkerFactory(workerFactory).build())
|
2019-03-26 14:32:23 +01:00
|
|
|
RxJavaPlugins.setErrorHandler(::onError)
|
2018-07-18 21:13:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun enableDebugLog() {
|
2018-11-03 14:49:20 +01:00
|
|
|
Timber.plant(DebugLogTree())
|
2018-10-03 21:28:23 +02:00
|
|
|
FlexibleAdapter.enableLogs(Log.Level.DEBUG)
|
2018-07-18 21:13:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun initializeFabric() {
|
2018-11-03 14:49:20 +01:00
|
|
|
Fabric.with(Fabric.Builder(this).kits(
|
2018-12-14 00:20:54 +01:00
|
|
|
Crashlytics.Builder().core(CrashlyticsCore.Builder().disabled(!BuildConfig.CRASHLYTICS_ENABLED).build()).build()
|
2018-11-03 14:49:20 +01:00
|
|
|
).debuggable(BuildConfig.DEBUG).build())
|
|
|
|
Timber.plant(CrashlyticsTree())
|
2018-07-18 21:13:57 +02:00
|
|
|
}
|
|
|
|
|
2019-03-26 14:32:23 +01:00
|
|
|
private fun onError(t: Throwable) {
|
|
|
|
if (t is UndeliverableException && t.cause is IOException || t.cause is InterruptedException) {
|
|
|
|
Timber.e(t.cause, "An undeliverable error occurred")
|
|
|
|
} else throw t
|
|
|
|
}
|
|
|
|
|
2018-10-03 21:28:23 +02:00
|
|
|
override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
|
|
|
|
return DaggerAppComponent.builder().create(this)
|
|
|
|
}
|
2018-07-18 21:13:57 +02:00
|
|
|
}
|