Improvement and fixes

powerreport
Laurent 3 years ago
parent 74f7e8d422
commit 54467e34cc
  1. 42
      app/src/main/java/net/pokeranalytics/android/calculus/ReportWhistleBlower.kt
  2. 2
      app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/model/LiveOnline.kt
  4. 7
      app/src/main/java/net/pokeranalytics/android/model/realm/Performance.kt
  5. 47
      app/src/main/java/net/pokeranalytics/android/ui/fragment/ReportsFragment.kt
  6. 2
      app/src/main/java/net/pokeranalytics/android/ui/view/RowViewType.kt
  7. 2
      app/src/main/java/net/pokeranalytics/android/ui/view/rows/StaticReport.kt

@ -1,7 +1,6 @@
package net.pokeranalytics.android.calculus
import android.content.Context
import android.os.CountDownTimer
import io.realm.Realm
import io.realm.RealmResults
import kotlinx.coroutines.CoroutineScope
@ -9,16 +8,13 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import net.pokeranalytics.android.calculus.optimalduration.CashGameOptimalDurationCalculator
import net.pokeranalytics.android.model.LiveOnline
import net.pokeranalytics.android.model.realm.CustomField
import net.pokeranalytics.android.model.realm.Performance
import net.pokeranalytics.android.model.realm.Result
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.fragment.PerformanceKey
import net.pokeranalytics.android.model.realm.*
import net.pokeranalytics.android.ui.view.rows.StaticReport
import net.pokeranalytics.android.util.extensions.formattedHourlyDuration
import timber.log.Timber
import kotlin.coroutines.CoroutineContext
interface NewPerformanceListener {
fun newBestPerformanceHandler()
}
@ -28,11 +24,9 @@ class ReportWhistleBlower(var context: Context) {
private var sessions: RealmResults<Session>? = null
private var results: RealmResults<Result>? = null
private var timer: CountDownTimer? = null
private var currentTask: ReportTask? = null
private val currentNotifications: MutableList<String> = mutableListOf()
private val currentNotifications: MutableList<String> = mutableListOf() // Performance.id
private val listeners: MutableList<NewPerformanceListener> = mutableListOf()
@ -42,12 +36,12 @@ class ReportWhistleBlower(var context: Context) {
this.sessions = realm.where(Session::class.java).findAll()
this.sessions?.addChangeListener { _ ->
requestReportLaunch()
launchReport()
}
this.results = realm.where(Result::class.java).findAll()
this.results?.addChangeListener { _ ->
requestReportLaunch()
launchReport()
}
}
@ -55,31 +49,17 @@ class ReportWhistleBlower(var context: Context) {
this.listeners.add(newPerformanceListener)
}
private fun requestReportLaunch() {
private fun launchReport() {
Timber.d(">>> Launch report")
synchronized(this) {
this.timer?.cancel()
val launch = 100L
this.timer = object : CountDownTimer(launch, launch) {
override fun onTick(p0: Long) { }
override fun onFinish() {
launchReport()
timer = null
}
}
this.timer?.start()
this.currentTask?.cancel()
val reportTask = ReportTask(this, this.context)
this.currentTask = reportTask
reportTask.start()
}
}
fun launchReport() {
Timber.d(">>> Launch report")
this.currentTask?.cancel()
val reportTask = ReportTask(this, this.context)
this.currentTask = reportTask
reportTask.start()
}
fun has(performanceId: String): Boolean {

@ -4,7 +4,7 @@ import android.content.Context
import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.FormattingException
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.ui.fragment.PerformanceKey
import net.pokeranalytics.android.model.realm.PerformanceKey
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowViewType
import net.pokeranalytics.android.util.NULL_TEXT

@ -1,7 +1,7 @@
package net.pokeranalytics.android.model
import net.pokeranalytics.android.R
import net.pokeranalytics.android.ui.fragment.PerformanceKey
import net.pokeranalytics.android.model.realm.PerformanceKey
import net.pokeranalytics.android.util.enumerations.IntIdentifiable
import net.pokeranalytics.android.util.enumerations.IntSearchable

@ -4,12 +4,17 @@ import io.realm.Realm
import io.realm.RealmObject
import net.pokeranalytics.android.calculus.Stat
import net.pokeranalytics.android.model.LiveOnline
import net.pokeranalytics.android.ui.fragment.PerformanceKey
import net.pokeranalytics.android.ui.view.rows.StaticReport
import net.pokeranalytics.android.util.NULL_TEXT
import net.pokeranalytics.android.util.extensions.lookupForNameInAllTablesById
import java.util.*
interface PerformanceKey {
val resId: Int?
val value: Int
}
open class Performance() : RealmObject() {
var id: String = UUID.randomUUID().toString()

@ -43,13 +43,24 @@ import net.pokeranalytics.android.util.Preferences
import timber.log.Timber
import java.util.*
interface PerformanceKey {
val resId: Int?
val value: Int
data class ReportSection(val report: StaticReport, var performances: MutableList<PerformanceRow>) {
fun getDisplayName(context: Context): String {
return when (report) {
is StaticReport.CustomFieldList -> {
report.customField.name
}
else -> {
this.report.resId?.let { context.getString(it) } ?: NULL_TEXT
}
}
}
}
data class ReportSection(var report: StaticReport, var performances: MutableList<PerformanceRow>)
data class PerformanceRow(var performance: Performance, var report: StaticReport, var badge: Boolean): RowRepresentable {
data class PerformanceRow(val performance: Performance, val report: StaticReport): RowRepresentable {
override val resId: Int? = this.performance.resId
@ -59,6 +70,7 @@ data class PerformanceRow(var performance: Performance, var report: StaticReport
class ReportsFragment : DeletableItemFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate, NewPerformanceListener {
private lateinit var reportSetups: RealmResults<ReportSetup>
private lateinit var performances: RealmResults<Performance>
private var adapterRows = mutableListOf<RowRepresentable>()
override fun deletableItems(): List<Deletable> {
@ -130,7 +142,7 @@ class ReportsFragment : DeletableItemFragment(), StaticRowRepresentableDataSourc
}
override fun selectedTab() {
this.updateRows()
// this.updateRows()
this.dataListAdapter.notifyDataSetChanged()
}
@ -144,6 +156,11 @@ class ReportsFragment : DeletableItemFragment(), StaticRowRepresentableDataSourc
this.reportSetups.addChangeListener { _, _ ->
this.updateRows()
}
this.performances = getRealm().where(Performance::class.java).findAll()
this.performances.addChangeListener { _, _ ->
this.updateRows()
}
}
/**
@ -190,7 +207,8 @@ class ReportsFragment : DeletableItemFragment(), StaticRowRepresentableDataSourc
val sections = buildReportSections()
for (section in sections) {
adapterRows.add(CustomizableRowRepresentable(customViewType = RowViewType.HEADER_TITLE, resId = section.report.resId))
adapterRows.add(CustomizableRowRepresentable(customViewType = RowViewType.HEADER_TITLE, title = section.getDisplayName(requireContext())))
for (performance in section.performances) {
adapterRows.add(performance)
}
@ -206,10 +224,8 @@ class ReportsFragment : DeletableItemFragment(), StaticRowRepresentableDataSourc
for (performance in performances) {
val report = performance.toStaticReport(getRealm())
val badge = Preferences.showInAppBadges(requireContext())
&& (this.paApplication?.reportWhistleBlower?.has(performance.id) ?: false)
val reportRow = PerformanceRow(performance, report, badge)
val reportRow = PerformanceRow(performance, report)
sections.firstOrNull { it.report == report }?.let { section ->
section.performances.add(reportRow)
@ -235,6 +251,15 @@ class ReportsFragment : DeletableItemFragment(), StaticRowRepresentableDataSourc
}
}
/**
* Returns whether the row should display a badge
*/
override fun boolForRow(row: RowRepresentable): Boolean {
val reportRow = row as PerformanceRow
return Preferences.showInAppBadges(requireContext())
&& (this.paApplication?.reportWhistleBlower?.has(reportRow.performance.id) ?: false)
}
override fun onRowSelected(position: Int, row: RowRepresentable, tag: Int) {
super.onRowSelected(position, row, tag)
@ -304,7 +329,7 @@ class ReportsFragment : DeletableItemFragment(), StaticRowRepresentableDataSourc
Timber.d("newBestPerformanceHandler called")
requireActivity().runOnUiThread {
this.updateRows()
// this.updateRows()
this.dataListAdapter.notifyDataSetChanged()
}

@ -684,7 +684,7 @@ enum class RowViewType(private var layoutRes: Int) : ViewIdentifier {
it.text = adapter.dataSource.charSequenceForRow(row, itemView.context)
}
itemView.findViewById<AppCompatImageView>(R.id.badge)?.let {
it.isVisible = row.badge
it.isVisible = adapter.dataSource.boolForRow(row)
}
itemView.findViewById<AppCompatImageView>(R.id.nextArrow)?.let {
it.visibility = if (row.report.hasGraph) {

@ -27,7 +27,7 @@ sealed class StaticReport(override var uniqueIdentifier: Int) : RowRepresentable
object Duration : StaticReport(9)
object OptimalDuration : StaticReport(10)
data class CustomFieldList(var customField: CustomField) : StaticReport(11)
data class CustomFieldList(val customField: CustomField) : StaticReport(11)
companion object {

Loading…
Cancel
Save