You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
2.6 KiB
99 lines
2.6 KiB
package net.pokeranalytics.android
|
|
|
|
import android.app.Application
|
|
import android.content.Context
|
|
import android.os.Build
|
|
import com.google.firebase.FirebaseApp
|
|
import io.realm.Realm
|
|
import io.realm.RealmConfiguration
|
|
import io.realm.kotlin.where
|
|
import kotlinx.coroutines.GlobalScope
|
|
import kotlinx.coroutines.launch
|
|
import net.pokeranalytics.android.model.migrations.Patcher
|
|
import net.pokeranalytics.android.model.migrations.PokerAnalyticsMigration
|
|
import net.pokeranalytics.android.model.realm.Session
|
|
import net.pokeranalytics.android.util.CrashLogging
|
|
import net.pokeranalytics.android.model.utils.Seed
|
|
import net.pokeranalytics.android.util.FakeDataManager
|
|
import net.pokeranalytics.android.util.PokerAnalyticsLogs
|
|
import net.pokeranalytics.android.util.UserDefaults
|
|
import net.pokeranalytics.android.util.billing.AppGuard
|
|
import timber.log.Timber
|
|
import java.util.*
|
|
|
|
|
|
class PokerAnalyticsApplication : Application() {
|
|
|
|
companion object {
|
|
|
|
fun timeSinceInstall(context: Context): Long {
|
|
val installTime: Long = context.packageManager.getPackageInfo(context.packageName, 0).firstInstallTime
|
|
return System.currentTimeMillis() - installTime
|
|
}
|
|
|
|
}
|
|
|
|
override fun onCreate() {
|
|
super.onCreate()
|
|
|
|
FirebaseApp.initializeApp(this)
|
|
|
|
UserDefaults.init(this)
|
|
|
|
// AppGuard / Billing services
|
|
AppGuard.load(this.applicationContext)
|
|
|
|
// Realm
|
|
Realm.init(this)
|
|
val realmConfiguration = RealmConfiguration.Builder()
|
|
.name(Realm.DEFAULT_REALM_NAME)
|
|
.schemaVersion(12)
|
|
.allowWritesOnUiThread(true)
|
|
.migration(PokerAnalyticsMigration())
|
|
.initialData(Seed(this))
|
|
.build()
|
|
Realm.setDefaultConfiguration(realmConfiguration)
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
val locales = resources.configuration.locales
|
|
CrashLogging.log("App onCreate. Locales = $locales")
|
|
}
|
|
|
|
if (BuildConfig.DEBUG) {
|
|
// Logs
|
|
Timber.plant(PokerAnalyticsLogs())
|
|
}
|
|
Timber.d("SDK version = ${Build.VERSION.SDK_INT}")
|
|
|
|
if (BuildConfig.DEBUG) {
|
|
Timber.d("UserPreferences.defaultCurrency: ${UserDefaults.currency.symbol}")
|
|
Timber.d("Realm path = ${Realm.getDefaultInstance().path}")
|
|
|
|
// this.createFakeSessions()
|
|
}
|
|
|
|
Patcher.patchAll(this.applicationContext)
|
|
|
|
val locale = Locale.getDefault()
|
|
CrashLogging.log("Country: ${locale.country}, language: ${locale.language}")
|
|
|
|
}
|
|
|
|
/**
|
|
* Create fake sessions if we have less than 10 sessions
|
|
*/
|
|
private fun createFakeSessions() {
|
|
|
|
val realm = Realm.getDefaultInstance()
|
|
val sessionsCount = realm.where<Session>().count()
|
|
realm.close()
|
|
|
|
if (sessionsCount < 10) {
|
|
GlobalScope.launch {
|
|
FakeDataManager.createFakeSessions(500)
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
} |