Launch reportwhistleblower if necessary

powerreport
Laurent 3 years ago
parent e0213e4a51
commit 80a617b5ce
  1. 10
      app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt
  2. 7
      app/src/main/java/net/pokeranalytics/android/calculus/ReportWhistleBlower.kt
  3. 42
      app/src/main/java/net/pokeranalytics/android/model/migrations/Patcher.kt

@ -12,7 +12,6 @@ import kotlinx.coroutines.launch
import net.pokeranalytics.android.calculus.ReportWhistleBlower
import net.pokeranalytics.android.model.migrations.Patcher
import net.pokeranalytics.android.model.migrations.PokerAnalyticsMigration
import net.pokeranalytics.android.model.realm.Performance
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.model.utils.Seed
import net.pokeranalytics.android.util.CrashLogging
@ -77,7 +76,7 @@ class PokerAnalyticsApplication : Application() {
}
// Patch
Patcher.patchAll(this.applicationContext)
Patcher.patchAll(this)
// Report
this.reportWhistleBlower = ReportWhistleBlower(this.applicationContext)
@ -86,10 +85,9 @@ class PokerAnalyticsApplication : Application() {
val locale = Locale.getDefault()
CrashLogging.log("Country: ${locale.country}, language: ${locale.language}")
// @TODO remove
Realm.getDefaultInstance().executeTransaction {
it.delete(Performance::class.java)
}
// Realm.getDefaultInstance().executeTransaction {
// it.delete(Performance::class.java)
// }
}

@ -36,12 +36,12 @@ class ReportWhistleBlower(var context: Context) {
this.sessions = realm.where(Session::class.java).findAll()
this.sessions?.addChangeListener { _ ->
launchReport()
launchReportTask()
}
this.results = realm.where(Result::class.java).findAll()
this.results?.addChangeListener { _ ->
launchReport()
launchReportTask()
}
}
@ -49,7 +49,7 @@ class ReportWhistleBlower(var context: Context) {
this.listeners.add(newPerformanceListener)
}
private fun launchReport() {
fun launchReportTask() {
Timber.d(">>> Launch report")
synchronized(this) {
@ -59,7 +59,6 @@ class ReportWhistleBlower(var context: Context) {
reportTask.start()
}
}
fun has(performanceId: String): Boolean {

@ -3,6 +3,7 @@ package net.pokeranalytics.android.model.migrations
import android.content.Context
import io.realm.Realm
import io.realm.kotlin.where
import net.pokeranalytics.android.PokerAnalyticsApplication
import net.pokeranalytics.android.model.filter.Query
import net.pokeranalytics.android.model.filter.QueryCondition
import net.pokeranalytics.android.model.realm.*
@ -17,7 +18,9 @@ class Patcher {
companion object {
fun patchAll(context: Context) {
fun patchAll(application: PokerAnalyticsApplication) {
val context = application.applicationContext
// NOTE: it's more than possible that at one point many patches become redundant
// with each other
@ -54,18 +57,8 @@ class Patcher {
patchZeroTable()
}
}
patchPerformances(application)
private fun patchZeroTable() {
val realm = Realm.getDefaultInstance()
val zero = 0
val sessions = realm.where<Session>().equalTo("numberOfTables", zero).findAll()
realm.executeTransaction {
sessions.forEach { s ->
s.numberOfTables = 1
}
}
realm.close()
}
private fun patchMissingTransactionTypes(context: Context) {
@ -195,6 +188,29 @@ class Patcher {
}
realm.close()
}
}
private fun patchPerformances(application: PokerAnalyticsApplication) {
val realm = Realm.getDefaultInstance()
val sessionCount = realm.where<Session>().findAll().size
val performanceCount = realm.where<Performance>().findAll().size
if (sessionCount > 1 && performanceCount == 0) {
application.reportWhistleBlower?.launchReportTask()
}
realm.close()
}
private fun patchZeroTable() {
val realm = Realm.getDefaultInstance()
val zero = 0
val sessions = realm.where<Session>().equalTo("numberOfTables", zero).findAll()
realm.executeTransaction {
sessions.forEach { s ->
s.numberOfTables = 1
}
}
realm.close()
}
}
}
Loading…
Cancel
Save