/
OFFApplication.kt
90 lines (79 loc) 路 3.21 KB
/
OFFApplication.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* Copyright 2016-2020 Open Food Facts
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package openfoodfacts.github.scrachx.openfood.app
import android.util.Log
import androidx.appcompat.app.AppCompatDelegate
import androidx.hilt.work.HiltWorkerFactory
import androidx.multidex.MultiDexApplication
import androidx.work.Configuration
import dagger.hilt.android.HiltAndroidApp
import io.reactivex.exceptions.UndeliverableException
import io.reactivex.plugins.RxJavaPlugins
import openfoodfacts.github.scrachx.openfood.models.DaoSession
import org.greenrobot.eventbus.EventBus
import org.greenrobot.greendao.query.QueryBuilder
import java.io.IOException
import javax.inject.Inject
import openfoodfacts.github.scrachx.openfood.analytics.SentryAnalytics.init as initAnalytics
@HiltAndroidApp
class OFFApplication : MultiDexApplication(), Configuration.Provider {
@Inject
lateinit var workerFactory: HiltWorkerFactory
@Inject
lateinit var daoSession: DaoSession
override fun getWorkManagerConfiguration() = Configuration.Builder()
.setWorkerFactory(workerFactory)
.build()
override fun onCreate() {
super.onCreate()
_instance = this
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
initAnalytics()
EventBus.builder().addIndex(OFFEventsIndex()).installDefaultEventBus()
// DEBUG
QueryBuilder.LOG_VALUES = DEBUG
QueryBuilder.LOG_SQL = DEBUG
RxJavaPlugins.setErrorHandler {
when (it) {
is UndeliverableException ->
Log.w(LOG_TAG, "Undeliverable exception received, not sure what to do", it.cause)
is IOException -> {
// fine, irrelevant network problem or API that throws on cancellation
Log.i(LOG_TAG, "network exception", it)
return@setErrorHandler
}
is InterruptedException -> {
// fine, some blocking code was interrupted by a dispose call
return@setErrorHandler
}
is NullPointerException, is IllegalArgumentException, is IllegalStateException -> {
// that's likely a bug in the application
Thread.currentThread().uncaughtExceptionHandler!!
.uncaughtException(Thread.currentThread(), it)
return@setErrorHandler
}
}
}
}
companion object {
private const val DEBUG = false
val LOG_TAG = OFFApplication::class.simpleName!!
@Deprecated("Use hilt.")
lateinit var _instance: OFFApplication
@Synchronized
private set
}
}