forked from upstream-mirrors/quik
135 lines
5.0 KiB
Kotlin
135 lines
5.0 KiB
Kotlin
/*
|
|
* Copyright (C) 2017 Moez Bhatti <moez.bhatti@gmail.com>
|
|
*
|
|
* This file is part of QKSMS.
|
|
*
|
|
* QKSMS is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* QKSMS is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with QKSMS. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
package dev.octoshrimpy.quik.common
|
|
|
|
import android.app.Activity
|
|
import android.app.Application
|
|
import android.app.Service
|
|
import android.content.BroadcastReceiver
|
|
import androidx.core.provider.FontRequest
|
|
import androidx.emoji.text.EmojiCompat
|
|
import androidx.emoji.text.FontRequestEmojiCompatConfig
|
|
import com.moez.QKSMS.manager.HousekeepingWorkManager
|
|
import com.moez.QKSMS.manager.SpeakManager
|
|
import dev.octoshrimpy.quik.R
|
|
import dev.octoshrimpy.quik.common.util.CrashlyticsTree
|
|
import dev.octoshrimpy.quik.common.util.FileLoggingTree
|
|
import dev.octoshrimpy.quik.injection.AppComponentManager
|
|
import dev.octoshrimpy.quik.injection.appComponent
|
|
import dev.octoshrimpy.quik.manager.AnalyticsManager
|
|
import dev.octoshrimpy.quik.manager.BillingManager
|
|
import dev.octoshrimpy.quik.manager.ReferralManager
|
|
import dev.octoshrimpy.quik.migration.QkMigration
|
|
import dev.octoshrimpy.quik.migration.QkRealmMigration
|
|
import dev.octoshrimpy.quik.util.NightModeManager
|
|
import com.uber.rxdogtag.RxDogTag
|
|
import com.uber.rxdogtag.autodispose.AutoDisposeConfigurer
|
|
import dagger.android.AndroidInjector
|
|
import dagger.android.DispatchingAndroidInjector
|
|
import dagger.android.HasActivityInjector
|
|
import dagger.android.HasBroadcastReceiverInjector
|
|
import dagger.android.HasServiceInjector
|
|
import dev.octoshrimpy.quik.interactor.SpeakThreads
|
|
import io.realm.Realm
|
|
import io.realm.RealmConfiguration
|
|
import kotlinx.coroutines.Dispatchers
|
|
import kotlinx.coroutines.GlobalScope
|
|
import kotlinx.coroutines.launch
|
|
import timber.log.Timber
|
|
import javax.inject.Inject
|
|
|
|
class QKApplication : Application(), HasActivityInjector, HasBroadcastReceiverInjector, HasServiceInjector {
|
|
|
|
/**
|
|
* Inject these so that they are forced to initialize
|
|
*/
|
|
@Suppress("unused")
|
|
@Inject lateinit var analyticsManager: AnalyticsManager
|
|
@Suppress("unused")
|
|
@Inject lateinit var qkMigration: QkMigration
|
|
|
|
@Inject lateinit var billingManager: BillingManager
|
|
@Inject lateinit var dispatchingActivityInjector: DispatchingAndroidInjector<Activity>
|
|
@Inject lateinit var dispatchingBroadcastReceiverInjector: DispatchingAndroidInjector<BroadcastReceiver>
|
|
@Inject lateinit var dispatchingServiceInjector: DispatchingAndroidInjector<Service>
|
|
@Inject lateinit var fileLoggingTree: FileLoggingTree
|
|
@Inject lateinit var nightModeManager: NightModeManager
|
|
@Inject lateinit var realmMigration: QkRealmMigration
|
|
@Inject lateinit var referralManager: ReferralManager
|
|
|
|
override fun onCreate() {
|
|
super.onCreate()
|
|
|
|
// set application context for SpeakManager
|
|
SpeakManager.setContext(this)
|
|
|
|
// set translated "no messages" string for speakThreads interactor
|
|
SpeakThreads.setNoMessagesString(getString(R.string.speak_no_messages))
|
|
|
|
AppComponentManager.init(this)
|
|
appComponent.inject(this)
|
|
|
|
Realm.init(this)
|
|
Realm.setDefaultConfiguration(RealmConfiguration.Builder()
|
|
.compactOnLaunch()
|
|
.migration(realmMigration)
|
|
.schemaVersion(QkRealmMigration.SchemaVersion)
|
|
.build())
|
|
|
|
qkMigration.performMigration()
|
|
|
|
GlobalScope.launch(Dispatchers.IO) {
|
|
referralManager.trackReferrer()
|
|
billingManager.checkForPurchases()
|
|
billingManager.queryProducts()
|
|
}
|
|
|
|
nightModeManager.updateCurrentTheme()
|
|
|
|
val fontRequest = FontRequest(
|
|
"com.google.android.gms.fonts",
|
|
"com.google.android.gms",
|
|
"Noto Color Emoji Compat",
|
|
R.array.com_google_android_gms_fonts_certs)
|
|
|
|
EmojiCompat.init(FontRequestEmojiCompatConfig(this, fontRequest))
|
|
|
|
Timber.plant(Timber.DebugTree(), CrashlyticsTree(), fileLoggingTree)
|
|
|
|
RxDogTag.builder()
|
|
.configureWith(AutoDisposeConfigurer::configure)
|
|
.install()
|
|
|
|
// register, or re-register, once-a-day-housekeeping work manager
|
|
HousekeepingWorkManager.register(applicationContext)
|
|
}
|
|
|
|
override fun activityInjector(): AndroidInjector<Activity> {
|
|
return dispatchingActivityInjector
|
|
}
|
|
|
|
override fun broadcastReceiverInjector(): AndroidInjector<BroadcastReceiver> {
|
|
return dispatchingBroadcastReceiverInjector
|
|
}
|
|
|
|
override fun serviceInjector(): AndroidInjector<Service> {
|
|
return dispatchingServiceInjector
|
|
}
|
|
|
|
} |