|
|
|
|
@ -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() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|