|
|
|
|
@ -7,15 +7,14 @@ import android.view.ViewGroup |
|
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
|
import com.google.android.material.tabs.TabLayout |
|
|
|
|
import io.realm.Realm |
|
|
|
|
import kotlinx.android.synthetic.main.fragment_calendar.* |
|
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
|
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.databinding.FragmentCalendarBinding |
|
|
|
|
import net.pokeranalytics.android.model.Criteria |
|
|
|
|
import net.pokeranalytics.android.model.combined |
|
|
|
|
import net.pokeranalytics.android.model.filter.QueryCondition |
|
|
|
|
@ -72,11 +71,15 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
TimeFilter.MONTH |
|
|
|
|
private var currentStat = Stat.NET_RESULT |
|
|
|
|
|
|
|
|
|
private var _binding: FragmentCalendarBinding? = null |
|
|
|
|
private val binding get() = _binding!! |
|
|
|
|
|
|
|
|
|
// Life Cycle |
|
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
|
super.onCreateView(inflater, container, savedInstanceState) |
|
|
|
|
return inflater.inflate(R.layout.fragment_calendar, container, false) |
|
|
|
|
_binding = FragmentCalendarBinding.inflate(inflater, container, false) |
|
|
|
|
return binding.root |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
|
@ -86,7 +89,14 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
listenRealmChanges(this, ComputableResult::class.java) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
|
override fun onDestroyView() { |
|
|
|
|
super.onDestroyView() |
|
|
|
|
_binding = null |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// |
|
|
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable> { |
|
|
|
|
return rows |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -134,12 +144,12 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
private fun initUI() { |
|
|
|
|
|
|
|
|
|
CalendarTabs.values().forEach { |
|
|
|
|
val tab = tabs.newTab() |
|
|
|
|
val tab = binding.tabs.newTab() |
|
|
|
|
tab.text = getString(it.resId) |
|
|
|
|
tabs.addTab(tab) |
|
|
|
|
binding.tabs.addTab(tab) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { |
|
|
|
|
binding.tabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener { |
|
|
|
|
override fun onTabSelected(tab: TabLayout.Tab) { |
|
|
|
|
when (tab.position) { |
|
|
|
|
0 -> currentStat = Stat.NET_RESULT |
|
|
|
|
@ -162,57 +172,57 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
// Manage session type queryWith |
|
|
|
|
filterSessionAll.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
binding.filterSessionAll.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
if (isChecked) { |
|
|
|
|
sessionTypeCondition = null |
|
|
|
|
filterSessionCash.isChecked = false |
|
|
|
|
filterSessionTournament.isChecked = false |
|
|
|
|
binding.filterSessionCash.isChecked = false |
|
|
|
|
binding.filterSessionTournament.isChecked = false |
|
|
|
|
launchAsyncStatComputation() |
|
|
|
|
} else if (sessionTypeCondition == null) { |
|
|
|
|
filterSessionAll.isChecked = true |
|
|
|
|
binding.filterSessionAll.isChecked = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
filterSessionCash.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
binding.filterSessionCash.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
if (isChecked) { |
|
|
|
|
sessionTypeCondition = QueryCondition.IsCash |
|
|
|
|
filterSessionAll.isChecked = false |
|
|
|
|
filterSessionTournament.isChecked = false |
|
|
|
|
binding.filterSessionAll.isChecked = false |
|
|
|
|
binding.filterSessionTournament.isChecked = false |
|
|
|
|
launchAsyncStatComputation() |
|
|
|
|
} else if (sessionTypeCondition == QueryCondition.IsCash) { |
|
|
|
|
filterSessionCash.isChecked = true |
|
|
|
|
binding.filterSessionCash.isChecked = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
filterSessionTournament.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
binding.filterSessionTournament.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
if (isChecked) { |
|
|
|
|
sessionTypeCondition = QueryCondition.IsTournament |
|
|
|
|
filterSessionAll.isChecked = false |
|
|
|
|
filterSessionCash.isChecked = false |
|
|
|
|
binding.filterSessionAll.isChecked = false |
|
|
|
|
binding.filterSessionCash.isChecked = false |
|
|
|
|
launchAsyncStatComputation() |
|
|
|
|
} else if (sessionTypeCondition == QueryCondition.IsTournament) { |
|
|
|
|
filterSessionTournament.isChecked = true |
|
|
|
|
binding.filterSessionTournament.isChecked = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Manage time queryWith |
|
|
|
|
filterTimeMonth.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
binding.filterTimeMonth.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
if (isChecked) { |
|
|
|
|
currentTimeFilter = |
|
|
|
|
TimeFilter.MONTH |
|
|
|
|
filterTimeYear.isChecked = false |
|
|
|
|
binding.filterTimeYear.isChecked = false |
|
|
|
|
displayData() |
|
|
|
|
} else if (currentTimeFilter == TimeFilter.MONTH) { |
|
|
|
|
filterTimeMonth.isChecked = true |
|
|
|
|
binding.filterTimeMonth.isChecked = true |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
filterTimeYear.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
binding.filterTimeYear.setOnCheckedChangeListener { _, isChecked -> |
|
|
|
|
if (isChecked) { |
|
|
|
|
currentTimeFilter = |
|
|
|
|
TimeFilter.YEAR |
|
|
|
|
filterTimeMonth.isChecked = false |
|
|
|
|
binding.filterTimeMonth.isChecked = false |
|
|
|
|
displayData() |
|
|
|
|
} else if (currentTimeFilter == TimeFilter.YEAR) { |
|
|
|
|
filterTimeYear.isChecked = true |
|
|
|
|
binding.filterTimeYear.isChecked = true |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -220,7 +230,7 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
|
|
|
|
|
calendarAdapter = RowRepresentableAdapter(this, this) |
|
|
|
|
|
|
|
|
|
recyclerView.apply { |
|
|
|
|
binding.recyclerView.apply { |
|
|
|
|
setHasFixedSize(true) |
|
|
|
|
layoutManager = viewManager |
|
|
|
|
adapter = calendarAdapter |
|
|
|
|
@ -232,8 +242,8 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
*/ |
|
|
|
|
private fun launchAsyncStatComputation() { |
|
|
|
|
|
|
|
|
|
progressBar?.showWithAnimation() |
|
|
|
|
recyclerView?.hideWithAnimation() |
|
|
|
|
binding.progressBar?.showWithAnimation() |
|
|
|
|
binding.recyclerView?.hideWithAnimation() |
|
|
|
|
|
|
|
|
|
GlobalScope.launch { |
|
|
|
|
|
|
|
|
|
@ -411,8 +421,8 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
|
|
|
|
|
calendarAdapter.notifyDataSetChanged() |
|
|
|
|
|
|
|
|
|
progressBar?.hideWithAnimation() |
|
|
|
|
recyclerView?.showWithAnimation() |
|
|
|
|
binding.progressBar.hideWithAnimation() |
|
|
|
|
binding.recyclerView.showWithAnimation() |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|