Fixes issue with multiple lines appearing

powerreport
Laurent 3 years ago
parent 6eac9137d7
commit 46f8b3ae0d
  1. 34
      app/src/main/java/net/pokeranalytics/android/calculus/ReportWhistleBlower.kt
  2. 2
      app/src/main/java/net/pokeranalytics/android/model/migrations/Patcher.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/ui/view/rows/StaticReport.kt

@ -1,6 +1,7 @@
package net.pokeranalytics.android.calculus
import android.content.Context
import android.os.CountDownTimer
import io.realm.Realm
import io.realm.RealmQuery
import io.realm.RealmResults
@ -33,18 +34,20 @@ class ReportWhistleBlower(var context: Context) {
private var paused: Boolean = false
private var timer: CountDownTimer? = null
init {
val realm = Realm.getDefaultInstance()
this.sessions = realm.where(Session::class.java).findAll()
this.sessions?.addChangeListener { _ ->
launchReportTask()
requestReportLaunch()
}
this.results = realm.where(Result::class.java).findAll()
this.results?.addChangeListener { _ ->
launchReportTask()
requestReportLaunch()
}
realm.close()
@ -58,15 +61,33 @@ class ReportWhistleBlower(var context: Context) {
this.listeners.remove(listener)
}
fun launchReportTask() {
fun requestReportLaunch() {
Timber.d(">>> Launch report")
if (paused) {
return
}
this.timer?.cancel()
val launchStart = 100L
val timer = object: CountDownTimer(launchStart, launchStart) {
override fun onTick(p0: Long) { }
override fun onFinish() {
launchReportTask()
}
}
this.timer = timer
timer.start()
}
private fun launchReportTask() {
synchronized(this) {
this.currentTask?.cancel()
val reportTask = ReportTask(this, this.context)
this.currentTask = reportTask
reportTask.start()
@ -74,13 +95,18 @@ class ReportWhistleBlower(var context: Context) {
}
/**
* Pauses the whistleblower, for example when importing data
*/
fun pause() {
this.paused = true
this.currentTask?.cancel()
this.currentTask = null
}
fun resume() {
this.paused = false
this.launchReportTask()
this.requestReportLaunch()
}
fun has(performanceId: String): Boolean {

@ -195,7 +195,7 @@ class Patcher {
val performanceCount = realm.where<Performance>().findAll().size
if (sessionCount > 1 && performanceCount == 0) {
application.reportWhistleBlower?.launchReportTask()
application.reportWhistleBlower?.requestReportLaunch()
}
realm.close()
}

@ -56,7 +56,7 @@ sealed class StaticReport(override var uniqueIdentifier: Int) : RowRepresentable
}
// val basicReports: Set<StaticReport> = setOf(Stakes, TableSize)
// val basicReports: Set<StaticReport> = setOf(General)
val basicReports: Set<StaticReport> = setOf(General, Stakes, TournamentBuyin,
DayOfWeek, Location, TournamentType, Game, TableSize, Duration, OptimalDuration)
}

Loading…
Cancel
Save