|
|
|
|
@ -18,6 +18,7 @@ import net.pokeranalytics.android.calculus.ComputedResults |
|
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
|
import net.pokeranalytics.android.model.comparison.Comparator |
|
|
|
|
import net.pokeranalytics.android.model.comparison.combined |
|
|
|
|
import net.pokeranalytics.android.model.filter.QueryCondition |
|
|
|
|
import net.pokeranalytics.android.ui.activity.CalendarDetailsActivity |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
|
@ -27,10 +28,7 @@ import net.pokeranalytics.android.ui.view.CalendarTabs |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowViewType |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable |
|
|
|
|
import net.pokeranalytics.android.util.extensions.getDateMonth |
|
|
|
|
import net.pokeranalytics.android.util.extensions.getDateYear |
|
|
|
|
import net.pokeranalytics.android.util.extensions.startOfMonth |
|
|
|
|
import net.pokeranalytics.android.util.extensions.startOfYear |
|
|
|
|
import net.pokeranalytics.android.util.extensions.* |
|
|
|
|
import timber.log.Timber |
|
|
|
|
import java.util.* |
|
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
|
@ -38,11 +36,7 @@ import kotlin.coroutines.CoroutineContext |
|
|
|
|
|
|
|
|
|
class CalendarFragment : SessionObserverFragment(), CoroutineScope, StaticRowRepresentableDataSource, RowRepresentableDelegate { |
|
|
|
|
|
|
|
|
|
private enum class SessionType { |
|
|
|
|
ALL, CASH, TOURNAMENT |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private enum class TimeFilter { |
|
|
|
|
enum class TimeFilter { |
|
|
|
|
MONTH, YEAR |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -70,8 +64,8 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope, StaticRowRep |
|
|
|
|
private var sortedYearlyReports: SortedMap<Date, ComputedResults> = HashMap<Date, ComputedResults>().toSortedMap() |
|
|
|
|
private var datesForRows: HashMap<CustomizableRowRepresentable, Date> = HashMap() |
|
|
|
|
|
|
|
|
|
private var currentSessionType = SessionType.ALL |
|
|
|
|
private var currentTimeFilter = TimeFilter.MONTH |
|
|
|
|
private var sessionTypeCondition: QueryCondition? = null |
|
|
|
|
private var currentTimeFilter: TimeFilter = TimeFilter.MONTH |
|
|
|
|
private var currentStat = Stat.NETRESULT |
|
|
|
|
|
|
|
|
|
// Life Cycle |
|
|
|
|
@ -93,8 +87,21 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope, StaticRowRep |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
|
|
|
|
Timber.d("Open ${datesForRows[row]}") |
|
|
|
|
CalendarDetailsActivity.newInstance(requireContext()) |
|
|
|
|
|
|
|
|
|
when (currentTimeFilter) { |
|
|
|
|
TimeFilter.MONTH -> { |
|
|
|
|
val date = datesForRows[row] |
|
|
|
|
sortedMonthlyReports[datesForRows[row]]?.let { |
|
|
|
|
CalendarDetailsActivity.newInstance(requireContext(), it, sessionTypeCondition, date?.getMonthAndYear()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
TimeFilter.YEAR -> { |
|
|
|
|
val date = datesForRows[row] |
|
|
|
|
sortedYearlyReports[datesForRows[row]]?.let { |
|
|
|
|
CalendarDetailsActivity.newInstance(requireContext(), it, sessionTypeCondition, date?.getDateYear()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun sessionsChanged() { |
|
|
|
|
@ -145,31 +152,31 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope, StaticRowRep |
|
|
|
|
// Manage session type filter |
|
|
|
|
filterSessionAll.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
if (isChecked) { |
|
|
|
|
currentSessionType = SessionType.ALL |
|
|
|
|
sessionTypeCondition = null |
|
|
|
|
filterSessionCash.isChecked = false |
|
|
|
|
filterSessionTournament.isChecked = false |
|
|
|
|
launchStatComputation() |
|
|
|
|
} else if (currentSessionType == SessionType.ALL) { |
|
|
|
|
} else if (sessionTypeCondition == null) { |
|
|
|
|
filterSessionAll.isChecked = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
filterSessionCash.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
if (isChecked) { |
|
|
|
|
currentSessionType = SessionType.CASH |
|
|
|
|
sessionTypeCondition = QueryCondition.CASH |
|
|
|
|
filterSessionAll.isChecked = false |
|
|
|
|
filterSessionTournament.isChecked = false |
|
|
|
|
launchStatComputation() |
|
|
|
|
} else if (currentSessionType == SessionType.CASH) { |
|
|
|
|
} else if (sessionTypeCondition == QueryCondition.CASH) { |
|
|
|
|
filterSessionCash.isChecked = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
filterSessionTournament.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
if (isChecked) { |
|
|
|
|
currentSessionType = SessionType.TOURNAMENT |
|
|
|
|
sessionTypeCondition = QueryCondition.TOURNAMENT |
|
|
|
|
filterSessionAll.isChecked = false |
|
|
|
|
filterSessionCash.isChecked = false |
|
|
|
|
launchStatComputation() |
|
|
|
|
} else if (currentSessionType == SessionType.TOURNAMENT) { |
|
|
|
|
} else if (sessionTypeCondition == QueryCondition.TOURNAMENT) { |
|
|
|
|
filterSessionTournament.isChecked = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -225,10 +232,10 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope, StaticRowRep |
|
|
|
|
|
|
|
|
|
// Compute data per YEAR and MONTH |
|
|
|
|
|
|
|
|
|
val monthConditions = when (currentSessionType) { |
|
|
|
|
SessionType.ALL -> listOf(Comparator.YEAR, Comparator.MONTH_OF_YEAR).combined() |
|
|
|
|
SessionType.CASH -> listOf(Comparator.YEAR, Comparator.MONTH_OF_YEAR, Comparator.CASH).combined() |
|
|
|
|
SessionType.TOURNAMENT -> listOf(Comparator.YEAR, Comparator.MONTH_OF_YEAR, Comparator.TOURNAMENT).combined() |
|
|
|
|
val monthConditions = when (sessionTypeCondition) { |
|
|
|
|
QueryCondition.CASH -> listOf(Comparator.YEAR, Comparator.MONTH_OF_YEAR, Comparator.CASH).combined() |
|
|
|
|
QueryCondition.TOURNAMENT -> listOf(Comparator.YEAR, Comparator.MONTH_OF_YEAR, Comparator.TOURNAMENT).combined() |
|
|
|
|
else -> listOf(Comparator.YEAR, Comparator.MONTH_OF_YEAR).combined() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
monthConditions.forEach { conditions -> |
|
|
|
|
@ -253,10 +260,10 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope, StaticRowRep |
|
|
|
|
calendar.time = Date().startOfYear() |
|
|
|
|
|
|
|
|
|
// Compute data per YEAR |
|
|
|
|
val yearConditions = when (currentSessionType) { |
|
|
|
|
SessionType.ALL -> listOf(Comparator.YEAR).combined() |
|
|
|
|
SessionType.CASH -> listOf(Comparator.YEAR, Comparator.CASH).combined() |
|
|
|
|
SessionType.TOURNAMENT -> listOf(Comparator.YEAR, Comparator.TOURNAMENT).combined() |
|
|
|
|
val yearConditions = when (sessionTypeCondition) { |
|
|
|
|
QueryCondition.CASH -> listOf(Comparator.YEAR, Comparator.CASH).combined() |
|
|
|
|
QueryCondition.TOURNAMENT -> listOf(Comparator.YEAR, Comparator.TOURNAMENT).combined() |
|
|
|
|
else -> listOf(Comparator.YEAR).combined() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
yearConditions.forEach { conditions -> |
|
|
|
|
|