|
|
|
|
@ -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 { |
|
|
|
|
|