|
|
|
|
@ -1,9 +1,7 @@ |
|
|
|
|
package net.pokeranalytics.android.ui.modules.calendar |
|
|
|
|
|
|
|
|
|
import android.os.Bundle |
|
|
|
|
import android.view.LayoutInflater |
|
|
|
|
import android.view.View |
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
import android.view.* |
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
|
import com.google.android.material.tabs.TabLayout |
|
|
|
|
import io.realm.Realm |
|
|
|
|
@ -85,8 +83,13 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
|
|
|
|
|
// Life Cycle |
|
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { |
|
|
|
|
override fun onCreateView( |
|
|
|
|
inflater: LayoutInflater, |
|
|
|
|
container: ViewGroup?, |
|
|
|
|
savedInstanceState: Bundle? |
|
|
|
|
): View { |
|
|
|
|
super.onCreateView(inflater, container, savedInstanceState) |
|
|
|
|
setHasOptionsMenu(true) |
|
|
|
|
_binding = FragmentCalendarBinding.inflate(inflater, container, false) |
|
|
|
|
return binding.root |
|
|
|
|
} |
|
|
|
|
@ -100,6 +103,19 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
addRealmChangeListener(this, ComputableResult::class.java) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { |
|
|
|
|
menu.clear() |
|
|
|
|
inflater.inflate(R.menu.toolbar_calendar, menu) |
|
|
|
|
super.onCreateOptionsMenu(menu, inflater) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean { |
|
|
|
|
when (item.itemId) { |
|
|
|
|
R.id.grid -> showGridCalendar() |
|
|
|
|
} |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onDestroyView() { |
|
|
|
|
super.onDestroyView() |
|
|
|
|
_binding = null |
|
|
|
|
@ -111,31 +127,53 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
return rows |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun showDetails(computedResults: ComputedResults, title: String?) { |
|
|
|
|
CalendarDetailsActivity.newInstance( |
|
|
|
|
requireContext(), |
|
|
|
|
computedResults, |
|
|
|
|
sessionTypeCondition, |
|
|
|
|
title |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onRowSelected(position: Int, row: RowRepresentable, tag: Int) { |
|
|
|
|
|
|
|
|
|
when (currentTimeFilter) { |
|
|
|
|
when (this.currentTimeFilter) { |
|
|
|
|
TimeFilter.MONTH -> { |
|
|
|
|
val date = datesForRows[row] |
|
|
|
|
sortedMonthlyReports[datesForRows[row]]?.let { |
|
|
|
|
CalendarDetailsActivity.newInstance( |
|
|
|
|
requireContext(), |
|
|
|
|
it, |
|
|
|
|
sessionTypeCondition, |
|
|
|
|
date?.getMonthAndYear() |
|
|
|
|
) |
|
|
|
|
when (position) { |
|
|
|
|
0 -> { |
|
|
|
|
this.slidingMonthResults?.let { |
|
|
|
|
showDetails(it, slidingMonthQuery.getName(requireContext())) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
val date = this.datesForRows[row] |
|
|
|
|
this.sortedMonthlyReports[datesForRows[row]]?.let { |
|
|
|
|
showDetails(it, date?.getMonthAndYear()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
TimeFilter.YEAR -> { |
|
|
|
|
val date = datesForRows[row] |
|
|
|
|
sortedYearlyReports[datesForRows[row]]?.let { |
|
|
|
|
CalendarDetailsActivity.newInstance(requireContext(), it, sessionTypeCondition, date?.getDateYear()) |
|
|
|
|
when (position) { |
|
|
|
|
0 -> { |
|
|
|
|
this.slidingYearResults?.let { |
|
|
|
|
showDetails(it, slidingYearQuery.getName(requireContext())) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
val date = datesForRows[row] |
|
|
|
|
sortedYearlyReports[datesForRows[row]]?.let { |
|
|
|
|
showDetails(it, date?.getDateYear()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
TimeFilter.ALL -> { |
|
|
|
|
this.allComputedResults?.let { |
|
|
|
|
CalendarDetailsActivity.newInstance(requireContext(), it, sessionTypeCondition, getString( |
|
|
|
|
R.string.all)) |
|
|
|
|
} ?: throw PAIllegalStateException("all results required to display details but null") |
|
|
|
|
showDetails(it, getString(R.string.all)) |
|
|
|
|
} |
|
|
|
|
?: throw PAIllegalStateException("all results required to display details but null") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -227,26 +265,9 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
// Manage time queryWith |
|
|
|
|
binding.filterTimeMonth.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
selectTimeFilter(TimeFilter.MONTH, isChecked) |
|
|
|
|
// if (isChecked) { |
|
|
|
|
// currentTimeFilter = |
|
|
|
|
// TimeFilter.MONTH |
|
|
|
|
// binding.filterTimeYear.isChecked = false |
|
|
|
|
// displayData() |
|
|
|
|
// } else if (currentTimeFilter == TimeFilter.MONTH) { |
|
|
|
|
// binding.filterTimeMonth.isChecked = true |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
binding.filterTimeYear.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
selectTimeFilter(TimeFilter.YEAR, isChecked) |
|
|
|
|
// if (isChecked) { |
|
|
|
|
// currentTimeFilter = |
|
|
|
|
// TimeFilter.YEAR |
|
|
|
|
// binding.filterTimeMonth.isChecked = false |
|
|
|
|
// displayData() |
|
|
|
|
// } else if (currentTimeFilter == TimeFilter.YEAR) { |
|
|
|
|
// binding.filterTimeYear.isChecked = true |
|
|
|
|
// } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val viewManager = LinearLayoutManager(requireContext()) |
|
|
|
|
@ -314,7 +335,12 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
val startDate = Date() |
|
|
|
|
|
|
|
|
|
val requiredStats: List<Stat> = |
|
|
|
|
listOf(Stat.LOCATIONS_PLAYED, Stat.LONGEST_STREAKS, Stat.DAYS_PLAYED, Stat.STANDARD_DEVIATION_HOURLY) |
|
|
|
|
listOf( |
|
|
|
|
Stat.LOCATIONS_PLAYED, |
|
|
|
|
Stat.LONGEST_STREAKS, |
|
|
|
|
Stat.DAYS_PLAYED, |
|
|
|
|
Stat.STANDARD_DEVIATION_HOURLY |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// All |
|
|
|
|
val allOptions = Calculator.Options( |
|
|
|
|
@ -328,7 +354,8 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
val smOptions = Calculator.Options( |
|
|
|
|
progressValues = Calculator.Options.ProgressValues.STANDARD, |
|
|
|
|
stats = requiredStats, |
|
|
|
|
query = this.slidingMonthQuery) |
|
|
|
|
query = this.slidingMonthQuery |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
val smReport = Calculator.computeStats(realm, options = smOptions) |
|
|
|
|
this.slidingMonthResults = smReport.results.first() |
|
|
|
|
@ -338,7 +365,10 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
|
|
|
|
|
val monthlyQueries = when (sessionTypeCondition) { |
|
|
|
|
QueryCondition.IsCash -> listOf(Criteria.AllMonthsUpToNow, Criteria.Cash).combined() |
|
|
|
|
QueryCondition.IsTournament -> listOf(Criteria.AllMonthsUpToNow, Criteria.Tournament).combined() |
|
|
|
|
QueryCondition.IsTournament -> listOf( |
|
|
|
|
Criteria.AllMonthsUpToNow, |
|
|
|
|
Criteria.Tournament |
|
|
|
|
).combined() |
|
|
|
|
else -> listOf(Criteria.Years, Criteria.MonthsOfYear).combined() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -354,7 +384,10 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
// Set date data |
|
|
|
|
query.conditions.forEach { condition -> |
|
|
|
|
when (condition) { |
|
|
|
|
is QueryCondition.AnyYear -> calendar.set(Calendar.YEAR, condition.listOfValues.first()) |
|
|
|
|
is QueryCondition.AnyYear -> calendar.set( |
|
|
|
|
Calendar.YEAR, |
|
|
|
|
condition.listOfValues.first() |
|
|
|
|
) |
|
|
|
|
is QueryCondition.AnyMonthOfYear -> calendar.set( |
|
|
|
|
Calendar.MONTH, |
|
|
|
|
condition.listOfValues.first() |
|
|
|
|
@ -371,7 +404,8 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
val syOptions = Calculator.Options( |
|
|
|
|
progressValues = Calculator.Options.ProgressValues.STANDARD, |
|
|
|
|
stats = requiredStats, |
|
|
|
|
query = this.slidingYearQuery) |
|
|
|
|
query = this.slidingYearQuery |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
val syReport = Calculator.computeStats(realm, options = syOptions) |
|
|
|
|
this.slidingYearResults = syReport.results.first() |
|
|
|
|
@ -399,7 +433,10 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
// Set date data |
|
|
|
|
query.conditions.forEach { condition -> |
|
|
|
|
when (condition) { |
|
|
|
|
is QueryCondition.AnyYear -> calendar.set(Calendar.YEAR, condition.listOfValues.first()) |
|
|
|
|
is QueryCondition.AnyYear -> calendar.set( |
|
|
|
|
Calendar.YEAR, |
|
|
|
|
condition.listOfValues.first() |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
yearlyReports[calendar.time] = computedResults |
|
|
|
|
@ -508,17 +545,18 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.sortedYearlyReports.keys.forEach { date -> |
|
|
|
|
this.sortedYearlyReports[date]?.computedStat(this.currentStat)?.let { computedStat -> |
|
|
|
|
val row = CustomizableRowRepresentable( |
|
|
|
|
customViewType = RowViewType.TITLE_VALUE_ARROW, |
|
|
|
|
title = date.getDateYear(), |
|
|
|
|
valueTextFormat = computedStat.textFormat, |
|
|
|
|
isSelectable = true |
|
|
|
|
) |
|
|
|
|
this.sortedYearlyReports[date]?.computedStat(this.currentStat) |
|
|
|
|
?.let { computedStat -> |
|
|
|
|
val row = CustomizableRowRepresentable( |
|
|
|
|
customViewType = RowViewType.TITLE_VALUE_ARROW, |
|
|
|
|
title = date.getDateYear(), |
|
|
|
|
valueTextFormat = computedStat.textFormat, |
|
|
|
|
isSelectable = true |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
this.rows.add(row) |
|
|
|
|
this.datesForRows[row] = date |
|
|
|
|
} |
|
|
|
|
this.rows.add(row) |
|
|
|
|
this.datesForRows[row] = date |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -537,5 +575,9 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
launchAsyncStatComputation() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun showGridCalendar() { |
|
|
|
|
GridCalendarActivity.newInstance(requireContext()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|