|
|
|
|
@ -20,6 +20,7 @@ import net.pokeranalytics.android.databinding.FragmentCalendarBinding |
|
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
|
import net.pokeranalytics.android.model.Criteria |
|
|
|
|
import net.pokeranalytics.android.model.combined |
|
|
|
|
import net.pokeranalytics.android.model.filter.Query |
|
|
|
|
import net.pokeranalytics.android.model.filter.QueryCondition |
|
|
|
|
import net.pokeranalytics.android.model.realm.ComputableResult |
|
|
|
|
import net.pokeranalytics.android.model.realm.UserConfig |
|
|
|
|
@ -67,6 +68,12 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
private var sortedMonthlyReports: SortedMap<Date, ComputedResults> = HashMap<Date, ComputedResults>().toSortedMap() |
|
|
|
|
private var sortedYearlyReports: SortedMap<Date, ComputedResults> = HashMap<Date, ComputedResults>().toSortedMap() |
|
|
|
|
|
|
|
|
|
private val slidingMonthQuery = Query(QueryCondition.PastDay(30)) |
|
|
|
|
private val slidingYearQuery = Query(QueryCondition.PastDay(365)) |
|
|
|
|
|
|
|
|
|
private var slidingMonthResults: ComputedResults? = null |
|
|
|
|
private var slidingYearResults: ComputedResults? = null |
|
|
|
|
|
|
|
|
|
private var datesForRows: HashMap<CustomizableRowRepresentable, Date> = HashMap() |
|
|
|
|
|
|
|
|
|
private var sessionTypeCondition: QueryCondition? = null |
|
|
|
|
@ -213,7 +220,7 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
binding.filterTimeAll?.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
binding.filterTimeAll.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
selectTimeFilter(TimeFilter.ALL, isChecked) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -260,7 +267,7 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
TimeFilter.values().forEach { tf -> |
|
|
|
|
if (tf != timeFilter) { |
|
|
|
|
when (tf) { |
|
|
|
|
TimeFilter.ALL -> binding.filterTimeAll?.isChecked = false |
|
|
|
|
TimeFilter.ALL -> binding.filterTimeAll.isChecked = false |
|
|
|
|
TimeFilter.MONTH -> binding.filterTimeMonth.isChecked = false |
|
|
|
|
TimeFilter.YEAR -> binding.filterTimeYear.isChecked = false |
|
|
|
|
} |
|
|
|
|
@ -269,7 +276,7 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
displayData() |
|
|
|
|
} else if (currentTimeFilter == timeFilter) { |
|
|
|
|
when (timeFilter) { |
|
|
|
|
TimeFilter.ALL -> binding.filterTimeAll?.isChecked = true |
|
|
|
|
TimeFilter.ALL -> binding.filterTimeAll.isChecked = true |
|
|
|
|
TimeFilter.MONTH -> binding.filterTimeMonth.isChecked = true |
|
|
|
|
TimeFilter.YEAR -> binding.filterTimeYear.isChecked = true |
|
|
|
|
} |
|
|
|
|
@ -317,6 +324,15 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
val allReport = Calculator.computeStats(realm, options = allOptions) |
|
|
|
|
this.allComputedResults = allReport.results.first() |
|
|
|
|
|
|
|
|
|
// Sliding Month [sm] |
|
|
|
|
val smOptions = Calculator.Options( |
|
|
|
|
progressValues = Calculator.Options.ProgressValues.STANDARD, |
|
|
|
|
stats = requiredStats, |
|
|
|
|
query = this.slidingMonthQuery) |
|
|
|
|
|
|
|
|
|
val smReport = Calculator.computeStats(realm, options = smOptions) |
|
|
|
|
this.slidingMonthResults = smReport.results.first() |
|
|
|
|
|
|
|
|
|
// Month |
|
|
|
|
val monthlyReports: HashMap<Date, ComputedResults> = HashMap() |
|
|
|
|
|
|
|
|
|
@ -351,6 +367,15 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Sliding Year [sm] |
|
|
|
|
val syOptions = Calculator.Options( |
|
|
|
|
progressValues = Calculator.Options.ProgressValues.STANDARD, |
|
|
|
|
stats = requiredStats, |
|
|
|
|
query = this.slidingYearQuery) |
|
|
|
|
|
|
|
|
|
val syReport = Calculator.computeStats(realm, options = syOptions) |
|
|
|
|
this.slidingYearResults = syReport.results.first() |
|
|
|
|
|
|
|
|
|
calendar.time = Date().startOfYear() |
|
|
|
|
|
|
|
|
|
// Year |
|
|
|
|
@ -431,6 +456,17 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
|
|
|
|
|
// MONTH |
|
|
|
|
TimeFilter.MONTH -> { |
|
|
|
|
|
|
|
|
|
slidingMonthResults?.computedStat(this.currentStat)?.let { computedStat -> |
|
|
|
|
val row = CustomizableRowRepresentable( |
|
|
|
|
customViewType = RowViewType.TITLE_VALUE_ARROW, |
|
|
|
|
title = this.slidingMonthQuery.getName(requireContext()), |
|
|
|
|
valueTextFormat = computedStat.textFormat, |
|
|
|
|
isSelectable = true |
|
|
|
|
) |
|
|
|
|
rows.add(row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val years: ArrayList<String> = ArrayList() |
|
|
|
|
sortedMonthlyReports.keys.forEach { date -> |
|
|
|
|
if (!years.contains(date.getDateYear())) { |
|
|
|
|
@ -452,16 +488,27 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
isSelectable = true |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
rows.add(row) |
|
|
|
|
datesForRows[row] = date |
|
|
|
|
this.rows.add(row) |
|
|
|
|
this.datesForRows[row] = date |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// YEAR |
|
|
|
|
TimeFilter.YEAR -> { |
|
|
|
|
sortedYearlyReports.keys.forEach { date -> |
|
|
|
|
sortedYearlyReports[date]?.computedStat(currentStat)?.let { computedStat -> |
|
|
|
|
|
|
|
|
|
this.slidingYearResults?.computedStat(this.currentStat)?.let { computedStat -> |
|
|
|
|
val row = CustomizableRowRepresentable( |
|
|
|
|
customViewType = RowViewType.TITLE_VALUE_ARROW, |
|
|
|
|
title = this.slidingYearQuery.getName(requireContext()), |
|
|
|
|
valueTextFormat = computedStat.textFormat, |
|
|
|
|
isSelectable = true |
|
|
|
|
) |
|
|
|
|
this.rows.add(row) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.sortedYearlyReports.keys.forEach { date -> |
|
|
|
|
this.sortedYearlyReports[date]?.computedStat(this.currentStat)?.let { computedStat -> |
|
|
|
|
val row = CustomizableRowRepresentable( |
|
|
|
|
customViewType = RowViewType.TITLE_VALUE_ARROW, |
|
|
|
|
title = date.getDateYear(), |
|
|
|
|
@ -469,8 +516,8 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
isSelectable = true |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
rows.add(row) |
|
|
|
|
datesForRows[row] = date |
|
|
|
|
this.rows.add(row) |
|
|
|
|
this.datesForRows[row] = date |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|