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.
 
 
poker-analytics/app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt

121 lines
3.2 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.CoroutineScope
import kotlinx.coroutines.Dispatchers
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.model.realm.UserConfigObserver
import net.pokeranalytics.android.model.utils.Seed
import net.pokeranalytics.android.calculus.DataManager
import net.pokeranalytics.android.util.*
import net.pokeranalytics.android.util.billing.AppGuard
import timber.log.Timber
import java.util.*
class PokerAnalyticsApplication : Application() {
var backupOperator: BackupOperator? = null
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()
if (!BuildConfig.DEBUG) {
FirebaseApp.initializeApp(this)
}
UserDefaults.init(this)
if (BuildConfig.DEBUG) {
// Logs
Timber.plant(PokerAnalyticsLogs())
}
// AppGuard / Billing services
AppGuard.load(this.applicationContext)
// Realm
Realm.init(this)
val realmConfiguration = RealmConfiguration.Builder()
.name(Realm.DEFAULT_REALM_NAME)
.schemaVersion(15)
// .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")
}
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}")
}
// Patch
Patcher.patchAll(this)
// Processors
DataManager.configure(this.applicationContext)
UserConfigObserver.create()
// this.reportWhistleBlower = ReportWhistleBlower(this.applicationContext)
// Backups
this.backupOperator = BackupOperator(this.applicationContext)
// Infos
val locale = Locale.getDefault()
CrashLogging.log("Country: ${locale.country}, language: ${locale.language}")
// val realm = Realm.getDefaultInstance()
// val v:Int = 0
// val set = realm.where<SessionSet>().equalTo("sessions.type", v).findAll()
// Timber.d("SESSION SET COUNT = ${set.size}")
// Realm.getDefaultInstance().executeTransaction {
// it.delete(Performance::class.java)
// }
}
/**
* 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) {
CoroutineScope(context = Dispatchers.IO).launch {
FakeDataManager.createFakeSessions(500)
}
}
}
}