|
|
|
|
@ -7,6 +7,7 @@ import android.view.LayoutInflater |
|
|
|
|
import android.view.View |
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
import androidx.core.view.isVisible |
|
|
|
|
import androidx.lifecycle.ViewModelProviders |
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
|
import com.github.mikephil.charting.data.BarDataSet |
|
|
|
|
import com.github.mikephil.charting.data.LineDataSet |
|
|
|
|
@ -18,7 +19,6 @@ import kotlinx.coroutines.GlobalScope |
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
import net.pokeranalytics.android.calculus.Calculator |
|
|
|
|
import net.pokeranalytics.android.calculus.ComputedResults |
|
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
|
import net.pokeranalytics.android.model.filter.Query |
|
|
|
|
import net.pokeranalytics.android.model.filter.QueryCondition |
|
|
|
|
@ -32,12 +32,17 @@ import net.pokeranalytics.android.ui.view.RowViewType |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.GraphRow |
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.StatDoubleRow |
|
|
|
|
import net.pokeranalytics.android.ui.viewmodel.CalendarDetailsViewModel |
|
|
|
|
import timber.log.Timber |
|
|
|
|
import java.util.* |
|
|
|
|
import kotlin.collections.ArrayList |
|
|
|
|
|
|
|
|
|
class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate { |
|
|
|
|
|
|
|
|
|
val viewModel: CalendarDetailsViewModel by lazy { |
|
|
|
|
ViewModelProviders.of(requireActivity()).get(CalendarDetailsViewModel::class.java) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
fun newInstance(context: Context) { |
|
|
|
|
val intent = Intent(context, CalendarDetailsFragment::class.java) |
|
|
|
|
@ -47,24 +52,21 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable |
|
|
|
|
|
|
|
|
|
private lateinit var statsAdapter: RowRepresentableAdapter |
|
|
|
|
|
|
|
|
|
private var title: String? = "" |
|
|
|
|
private var computedResults: ComputedResults? = null |
|
|
|
|
private var sessionTypeCondition: QueryCondition? = null |
|
|
|
|
private var rowRepresentables: ArrayList<RowRepresentable> = ArrayList() |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Set data |
|
|
|
|
*/ |
|
|
|
|
fun setData(computedResults: ComputedResults?, sessionTypeCondition: QueryCondition?, title: String?) { |
|
|
|
|
|
|
|
|
|
this.computedResults = computedResults |
|
|
|
|
this.sessionTypeCondition = sessionTypeCondition |
|
|
|
|
this.title = title |
|
|
|
|
|
|
|
|
|
displayData() |
|
|
|
|
launchStatComputation() |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
// fun setData(computedResults: ComputedResults?, sessionTypeCondition: QueryCondition?, title: String?) { |
|
|
|
|
// |
|
|
|
|
// this.computedResults = computedResults |
|
|
|
|
// this.sessionTypeCondition = sessionTypeCondition |
|
|
|
|
// this.title = title |
|
|
|
|
// |
|
|
|
|
// displayData() |
|
|
|
|
// launchStatComputation() |
|
|
|
|
// |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
|
return inflater.inflate(R.layout.fragment_calendar_details, container, false) |
|
|
|
|
@ -73,6 +75,7 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable |
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
|
initUI() |
|
|
|
|
launchStatComputation() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -80,10 +83,12 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable |
|
|
|
|
*/ |
|
|
|
|
private fun initUI() { |
|
|
|
|
|
|
|
|
|
setToolbarTitle(this.viewModel.detailsTitle) |
|
|
|
|
|
|
|
|
|
setDisplayHomeAsUpEnabled(true) |
|
|
|
|
|
|
|
|
|
var tabIndexToSelect = 0 |
|
|
|
|
sessionTypeCondition?.let { |
|
|
|
|
this.viewModel.sessionTypeCondition?.let { |
|
|
|
|
tabIndexToSelect = when (it) { |
|
|
|
|
QueryCondition.IsCash -> 1 |
|
|
|
|
QueryCondition.IsTournament -> 2 |
|
|
|
|
@ -96,9 +101,9 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable |
|
|
|
|
tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { |
|
|
|
|
override fun onTabSelected(tab: TabLayout.Tab) { |
|
|
|
|
when (tab.position) { |
|
|
|
|
0 -> sessionTypeCondition = null |
|
|
|
|
1 -> sessionTypeCondition = QueryCondition.IsCash |
|
|
|
|
2 -> sessionTypeCondition = QueryCondition.IsTournament |
|
|
|
|
0 -> viewModel.sessionTypeCondition = null |
|
|
|
|
1 -> viewModel.sessionTypeCondition = QueryCondition.IsCash |
|
|
|
|
2 -> viewModel.sessionTypeCondition = QueryCondition.IsTournament |
|
|
|
|
} |
|
|
|
|
launchStatComputation() |
|
|
|
|
} |
|
|
|
|
@ -123,13 +128,6 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Display data |
|
|
|
|
*/ |
|
|
|
|
private fun displayData() { |
|
|
|
|
setToolbarTitle(title) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// StaticRowRepresentableDataSource |
|
|
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
|
@ -168,7 +166,7 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable |
|
|
|
|
progressBar.animate().alpha(1f).start() |
|
|
|
|
recyclerView.animate().alpha(0f).start() |
|
|
|
|
|
|
|
|
|
computedResults?.let { computedResults -> |
|
|
|
|
this.viewModel.computedResults?.let { computedResults -> |
|
|
|
|
|
|
|
|
|
GlobalScope.launch { |
|
|
|
|
|
|
|
|
|
@ -179,7 +177,7 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable |
|
|
|
|
val query = Query().merge(computedResults.group.query) |
|
|
|
|
query.remove(QueryCondition.IsCash) |
|
|
|
|
query.remove(QueryCondition.IsTournament) |
|
|
|
|
when (sessionTypeCondition) { |
|
|
|
|
when (viewModel.sessionTypeCondition) { |
|
|
|
|
QueryCondition.IsCash -> query.add(QueryCondition.IsCash) |
|
|
|
|
QueryCondition.IsTournament -> query.add(QueryCondition.IsTournament) |
|
|
|
|
} |
|
|
|
|
@ -222,7 +220,6 @@ class CalendarDetailsFragment : PokerAnalyticsFragment(), StaticRowRepresentable |
|
|
|
|
rowRepresentables.add(StatDoubleRow(it.computedStat(Stat.DAYS_PLAYED), it.computedStat(Stat.MAXIMUM_DURATION))) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
launch(Dispatchers.Main) { |
|
|
|
|
statsAdapter.notifyDataSetChanged() |
|
|
|
|
progressBar.animate().cancel() |
|
|
|
|
|