|
|
|
|
@ -1,7 +1,10 @@ |
|
|
|
|
package net.pokeranalytics.android.ui.modules.calendar |
|
|
|
|
|
|
|
|
|
import android.content.res.ColorStateList |
|
|
|
|
import android.os.Build |
|
|
|
|
import android.os.Bundle |
|
|
|
|
import android.view.* |
|
|
|
|
import androidx.appcompat.widget.Toolbar |
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
|
import com.google.android.material.tabs.TabLayout |
|
|
|
|
import io.realm.Realm |
|
|
|
|
@ -21,6 +24,7 @@ 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.Transaction |
|
|
|
|
import net.pokeranalytics.android.model.realm.UserConfig |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
|
@ -29,6 +33,7 @@ import net.pokeranalytics.android.ui.extensions.hideWithAnimation |
|
|
|
|
import net.pokeranalytics.android.ui.extensions.showWithAnimation |
|
|
|
|
import net.pokeranalytics.android.ui.fragment.components.RealmAsyncListener |
|
|
|
|
import net.pokeranalytics.android.ui.fragment.components.RealmFragment |
|
|
|
|
import net.pokeranalytics.android.ui.modules.settings.TransactionFilterActivity |
|
|
|
|
import net.pokeranalytics.android.ui.view.CalendarTabs |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.RowViewType |
|
|
|
|
@ -36,6 +41,7 @@ import net.pokeranalytics.android.ui.view.rows.CustomizableRowRepresentable |
|
|
|
|
import net.pokeranalytics.android.util.extensions.* |
|
|
|
|
import timber.log.Timber |
|
|
|
|
import java.util.* |
|
|
|
|
import kotlin.collections.set |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentableDataSource, |
|
|
|
|
@ -89,7 +95,6 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
savedInstanceState: Bundle? |
|
|
|
|
): View { |
|
|
|
|
super.onCreateView(inflater, container, savedInstanceState) |
|
|
|
|
setHasOptionsMenu(true) |
|
|
|
|
_binding = FragmentCalendarBinding.inflate(inflater, container, false) |
|
|
|
|
return binding.root |
|
|
|
|
} |
|
|
|
|
@ -101,19 +106,47 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
|
|
|
|
|
addRealmChangeListener(this, UserConfig::class.java) |
|
|
|
|
addRealmChangeListener(this, ComputableResult::class.java) |
|
|
|
|
addRealmChangeListener(this, Transaction::class.java) |
|
|
|
|
} |
|
|
|
|
private var transactionFilterMenuItem: MenuItem? = null |
|
|
|
|
|
|
|
|
|
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { |
|
|
|
|
menu.clear() |
|
|
|
|
inflater.inflate(R.menu.toolbar_calendar, menu) |
|
|
|
|
|
|
|
|
|
super.onCreateOptionsMenu(menu, inflater) |
|
|
|
|
|
|
|
|
|
view?.findViewById<Toolbar>(R.id.toolbar)?.let { toolbar -> |
|
|
|
|
toolbar.menu.removeItem(R.id.menu_item_transaction_filter) |
|
|
|
|
transactionFilterMenuItem = toolbar.menu?.add(0, R.id.menu_item_transaction_filter, 1, R.string.filter) |
|
|
|
|
transactionFilterMenuItem?.setIcon(R.drawable.baseline_payment_24) |
|
|
|
|
transactionFilterMenuItem?.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM) |
|
|
|
|
setTransactionFilterItemColor() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onOptionsItemSelected(item: MenuItem): Boolean { |
|
|
|
|
when (item.itemId) { |
|
|
|
|
R.id.grid -> showGridCalendar() |
|
|
|
|
R.id.menu_item_transaction_filter -> showTransactionFilter() |
|
|
|
|
} |
|
|
|
|
return super.onOptionsItemSelected(item) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun setTransactionFilterItemColor() { |
|
|
|
|
context?.let { |
|
|
|
|
val userConfig = UserConfig.getConfiguration(getRealm()) |
|
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
|
|
|
|
this.transactionFilterMenuItem?.let { item -> |
|
|
|
|
val color = if (userConfig.transactionTypeIds.isNotEmpty()) R.color.red else R.color.white |
|
|
|
|
item.iconTintList = ColorStateList.valueOf(it.getColor(color)) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun showTransactionFilter() { |
|
|
|
|
context?.let { |
|
|
|
|
TransactionFilterActivity.newInstance(it) |
|
|
|
|
} |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onDestroyView() { |
|
|
|
|
@ -180,9 +213,6 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
|
|
|
|
|
override val observedEntities: List<Class<out RealmModel>> = listOf(ComputableResult::class.java) |
|
|
|
|
|
|
|
|
|
// override fun entitiesChanged(clazz: Class<out RealmModel>, results: RealmResults<out RealmModel>) { |
|
|
|
|
// launchAsyncStatComputation() |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
// Business |
|
|
|
|
|
|
|
|
|
@ -283,6 +313,8 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
layoutManager = viewManager |
|
|
|
|
adapter = calendarAdapter |
|
|
|
|
} |
|
|
|
|
setTransactionFilterItemColor() |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun selectTimeFilter(timeFilter: TimeFilter, isChecked: Boolean) { |
|
|
|
|
@ -346,11 +378,14 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
Stat.STANDARD_DEVIATION_HOURLY |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
val transactionTypes = UserConfig.getConfiguration(realm).transactionTypes(realm) |
|
|
|
|
|
|
|
|
|
// All |
|
|
|
|
val allOptions = Calculator.Options( |
|
|
|
|
progressValues = Calculator.Options.ProgressValues.STANDARD, |
|
|
|
|
stats = requiredStats, |
|
|
|
|
query = Query(this.sessionTypeCondition) |
|
|
|
|
query = Query(this.sessionTypeCondition), |
|
|
|
|
includedTransactions = transactionTypes |
|
|
|
|
) |
|
|
|
|
val allReport = Calculator.computeStats(realm, options = allOptions) |
|
|
|
|
this.allComputedResults = allReport.results.first() |
|
|
|
|
@ -359,7 +394,8 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
val smOptions = Calculator.Options( |
|
|
|
|
progressValues = Calculator.Options.ProgressValues.STANDARD, |
|
|
|
|
stats = requiredStats, |
|
|
|
|
query = Query(this.slidingMonthQueryCondition, this.sessionTypeCondition) |
|
|
|
|
query = Query(this.slidingMonthQueryCondition, this.sessionTypeCondition), |
|
|
|
|
includedTransactions = transactionTypes |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
val smReport = Calculator.computeStats(realm, options = smOptions) |
|
|
|
|
@ -378,7 +414,8 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
val options = Calculator.Options( |
|
|
|
|
progressValues = Calculator.Options.ProgressValues.STANDARD, |
|
|
|
|
stats = requiredStats, |
|
|
|
|
query = query |
|
|
|
|
query = query, |
|
|
|
|
includedTransactions = transactionTypes |
|
|
|
|
) |
|
|
|
|
val report = Calculator.computeStats(realm, options = options) |
|
|
|
|
report.results.forEach { computedResults -> |
|
|
|
|
@ -406,7 +443,8 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
val syOptions = Calculator.Options( |
|
|
|
|
progressValues = Calculator.Options.ProgressValues.STANDARD, |
|
|
|
|
stats = requiredStats, |
|
|
|
|
query = Query(this.slidingYearQueryCondition, this.sessionTypeCondition) |
|
|
|
|
query = Query(this.slidingYearQueryCondition, this.sessionTypeCondition), |
|
|
|
|
includedTransactions = transactionTypes |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
val syReport = Calculator.computeStats(realm, options = syOptions) |
|
|
|
|
@ -427,7 +465,8 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
val options = Calculator.Options( |
|
|
|
|
progressValues = Calculator.Options.ProgressValues.STANDARD, |
|
|
|
|
stats = requiredStats, |
|
|
|
|
query = query |
|
|
|
|
query = query, |
|
|
|
|
includedTransactions = transactionTypes |
|
|
|
|
) |
|
|
|
|
val report = Calculator.computeStats(realm, options = options) |
|
|
|
|
report.results.forEach { computedResults -> |
|
|
|
|
@ -451,18 +490,6 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
|
|
|
|
|
Timber.d("Computation: ${System.currentTimeMillis() - startDate.time}ms") |
|
|
|
|
|
|
|
|
|
// Logs |
|
|
|
|
/* |
|
|
|
|
Timber.d("========== AnyYear x AnyMonthOfYear") |
|
|
|
|
sortedMonthlyReports.keys.forEach { |
|
|
|
|
Timber.d("$it => ${sortedMonthlyReports[it]?.computedStat(Stat.NET_RESULT)?.value}") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Timber.d("========== YEARLY") |
|
|
|
|
sortedYearlyReports.keys.forEach { |
|
|
|
|
Timber.d("$it => ${sortedYearlyReports[it]?.computedStat(Stat.NET_RESULT)?.value}") |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -576,7 +603,10 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun asyncListenedEntityChange(realm: Realm) { |
|
|
|
|
launchAsyncStatComputation() |
|
|
|
|
if (isAdded) { // Fixes: java.lang.IllegalStateException Fragment StatisticsFragment{9d3e5ec} not attached to a context. |
|
|
|
|
launchAsyncStatComputation() |
|
|
|
|
setTransactionFilterItemColor() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun showGridCalendar() { |
|
|
|
|
|