|
|
|
@ -5,6 +5,7 @@ import android.view.LayoutInflater |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import android.view.ViewGroup |
|
|
|
import android.view.ViewGroup |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
|
|
|
|
import com.google.android.material.tabs.TabLayout |
|
|
|
import io.realm.Realm |
|
|
|
import io.realm.Realm |
|
|
|
import kotlinx.android.synthetic.main.fragment_calendar.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_calendar.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_stats.recyclerView |
|
|
|
import kotlinx.android.synthetic.main.fragment_stats.recyclerView |
|
|
|
@ -18,14 +19,21 @@ import net.pokeranalytics.android.calculus.ComputedResults |
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
import net.pokeranalytics.android.model.comparison.Comparator |
|
|
|
import net.pokeranalytics.android.model.comparison.Comparator |
|
|
|
import net.pokeranalytics.android.model.comparison.combined |
|
|
|
import net.pokeranalytics.android.model.comparison.combined |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.SessionObserverFragment |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.SessionObserverFragment |
|
|
|
import net.pokeranalytics.android.ui.view.CalendarTabs |
|
|
|
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.shortDate |
|
|
|
import timber.log.Timber |
|
|
|
import timber.log.Timber |
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CalendarFragment : SessionObserverFragment(), CoroutineScope { |
|
|
|
class CalendarFragment : SessionObserverFragment(), CoroutineScope, StaticRowRepresentableDataSource, RowRepresentableDelegate { |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
|
|
@ -40,10 +48,13 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private lateinit var calendarAdapter: RowRepresentableAdapter |
|
|
|
|
|
|
|
|
|
|
|
override val coroutineContext: CoroutineContext |
|
|
|
override val coroutineContext: CoroutineContext |
|
|
|
get() = Dispatchers.Main |
|
|
|
get() = Dispatchers.Main |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private var rows: ArrayList<CustomizableRowRepresentable> = ArrayList() |
|
|
|
private var sortedMonthlyReports: SortedMap<Date, ComputedResults> = HashMap<Date, ComputedResults>().toSortedMap() |
|
|
|
private var sortedMonthlyReports: SortedMap<Date, ComputedResults> = HashMap<Date, ComputedResults>().toSortedMap() |
|
|
|
private var sortedYearlyReports: SortedMap<Date, ComputedResults> = HashMap<Date, ComputedResults>().toSortedMap() |
|
|
|
private var sortedYearlyReports: SortedMap<Date, ComputedResults> = HashMap<Date, ComputedResults>().toSortedMap() |
|
|
|
|
|
|
|
|
|
|
|
@ -61,6 +72,10 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope { |
|
|
|
launchStatComputation() |
|
|
|
launchStatComputation() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
|
|
|
|
return rows |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Business |
|
|
|
// Business |
|
|
|
|
|
|
|
|
|
|
|
@ -68,7 +83,6 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope { |
|
|
|
* Init data |
|
|
|
* Init data |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun initData() { |
|
|
|
private fun initData() { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -82,12 +96,35 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope { |
|
|
|
tabs.addTab(tab) |
|
|
|
tabs.addTab(tab) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { |
|
|
|
|
|
|
|
override fun onTabSelected(tab: TabLayout.Tab) { |
|
|
|
|
|
|
|
when(tab.position) { |
|
|
|
|
|
|
|
0 -> displayData(Stat.NETRESULT) |
|
|
|
|
|
|
|
1 -> displayData(Stat.HOURLY_RATE) |
|
|
|
|
|
|
|
2 -> displayData(Stat.NUMBER_OF_GAMES) |
|
|
|
|
|
|
|
3 -> displayData(Stat.WIN_RATIO) |
|
|
|
|
|
|
|
4 -> displayData(Stat.STANDARD_DEVIATION_HOURLY) |
|
|
|
|
|
|
|
5 -> displayData(Stat.AVERAGE) |
|
|
|
|
|
|
|
6 -> displayData(Stat.AVERAGE_DURATION) |
|
|
|
|
|
|
|
7 -> displayData(Stat.DURATION) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onTabUnselected(tab: TabLayout.Tab) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onTabReselected(tab: TabLayout.Tab) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
val viewManager = LinearLayoutManager(requireContext()) |
|
|
|
val viewManager = LinearLayoutManager(requireContext()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
calendarAdapter = RowRepresentableAdapter(this, this) |
|
|
|
|
|
|
|
|
|
|
|
recyclerView.apply { |
|
|
|
recyclerView.apply { |
|
|
|
setHasFixedSize(true) |
|
|
|
setHasFixedSize(true) |
|
|
|
layoutManager = viewManager |
|
|
|
layoutManager = viewManager |
|
|
|
//adapter = statsAdapter |
|
|
|
adapter = calendarAdapter |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -134,9 +171,6 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
montlyReports[calendar.time] = computedResults |
|
|
|
montlyReports[calendar.time] = computedResults |
|
|
|
|
|
|
|
|
|
|
|
//val statValue = computedResults.computedStat(Stat.NETRESULT)?.value |
|
|
|
|
|
|
|
//Timber.d("======> statValue: $statValue / Number of stats: ${computedResults.numberOfStats()}") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -162,12 +196,6 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
yearlyReports[calendar.time] = computedResults |
|
|
|
yearlyReports[calendar.time] = computedResults |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
|
|
computedResults.computedStat(Stat.NETRESULT)?.let { computedStat -> |
|
|
|
|
|
|
|
Timber.d("======> statValue: ${computedStat.value}") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -186,8 +214,8 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope { |
|
|
|
Timber.d("$it => ${sortedYearlyReports[it]?.computedStat(Stat.NETRESULT)?.value}") |
|
|
|
Timber.d("$it => ${sortedYearlyReports[it]?.computedStat(Stat.NETRESULT)?.value}") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
GlobalScope.launch(coroutineContext) { |
|
|
|
GlobalScope.launch(Dispatchers.Main) { |
|
|
|
displayData() |
|
|
|
displayData(Stat.NETRESULT) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
@ -197,9 +225,27 @@ class CalendarFragment : SessionObserverFragment(), CoroutineScope { |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Display data |
|
|
|
* Display data |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun displayData() { |
|
|
|
private fun displayData(stat: Stat) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rows.clear() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Create yearly reports |
|
|
|
|
|
|
|
sortedYearlyReports.keys.forEach { |
|
|
|
|
|
|
|
Timber.d("$it => ${sortedYearlyReports[it]?.computedStat(Stat.NETRESULT)?.value}") |
|
|
|
|
|
|
|
sortedYearlyReports[it]?.computedStat(stat)?.let { computedStat -> |
|
|
|
|
|
|
|
rows.add( |
|
|
|
|
|
|
|
CustomizableRowRepresentable( |
|
|
|
|
|
|
|
customViewType = RowViewType.TITLE_VALUE_ARROW, |
|
|
|
|
|
|
|
title = it.shortDate(), |
|
|
|
|
|
|
|
value = computedStat.format(requireContext()).text |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Timber.d("Rows: ${rows.size}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
calendarAdapter.notifyDataSetChanged() |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|