|
|
|
@ -7,8 +7,6 @@ import android.view.ViewGroup |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import com.google.android.material.tabs.TabLayout |
|
|
|
import com.google.android.material.tabs.TabLayout |
|
|
|
import io.realm.Realm |
|
|
|
import io.realm.Realm |
|
|
|
import io.realm.RealmModel |
|
|
|
|
|
|
|
import io.realm.RealmResults |
|
|
|
|
|
|
|
import kotlinx.android.synthetic.main.fragment_calendar.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_calendar.* |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
import kotlinx.coroutines.CoroutineScope |
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
@ -27,6 +25,7 @@ import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
|
|
|
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
|
|
|
import net.pokeranalytics.android.ui.extensions.hideWithAnimation |
|
|
|
import net.pokeranalytics.android.ui.extensions.hideWithAnimation |
|
|
|
import net.pokeranalytics.android.ui.extensions.showWithAnimation |
|
|
|
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.fragment.components.RealmFragment |
|
|
|
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.RowRepresentable |
|
|
|
@ -35,11 +34,10 @@ import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepres |
|
|
|
import net.pokeranalytics.android.util.extensions.* |
|
|
|
import net.pokeranalytics.android.util.extensions.* |
|
|
|
import timber.log.Timber |
|
|
|
import timber.log.Timber |
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
import kotlin.coroutines.CoroutineContext |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentableDataSource, |
|
|
|
class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentableDataSource, |
|
|
|
RowRepresentableDelegate { |
|
|
|
RowRepresentableDelegate, RealmAsyncListener { |
|
|
|
|
|
|
|
|
|
|
|
enum class TimeFilter { |
|
|
|
enum class TimeFilter { |
|
|
|
MONTH, YEAR |
|
|
|
MONTH, YEAR |
|
|
|
@ -51,8 +49,7 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
* Create new instance |
|
|
|
* Create new instance |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun newInstance(): CalendarFragment { |
|
|
|
fun newInstance(): CalendarFragment { |
|
|
|
val fragment = |
|
|
|
val fragment = CalendarFragment() |
|
|
|
CalendarFragment() |
|
|
|
|
|
|
|
val bundle = Bundle() |
|
|
|
val bundle = Bundle() |
|
|
|
fragment.arguments = bundle |
|
|
|
fragment.arguments = bundle |
|
|
|
return fragment |
|
|
|
return fragment |
|
|
|
@ -61,8 +58,8 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
|
|
|
|
|
|
|
private lateinit var calendarAdapter: RowRepresentableAdapter |
|
|
|
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 rows: ArrayList<CustomizableRowRepresentable> = ArrayList() |
|
|
|
@ -86,11 +83,7 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
initData() |
|
|
|
initData() |
|
|
|
initUI() |
|
|
|
initUI() |
|
|
|
} |
|
|
|
listenAsynchronously(this, ComputableResult::class.java) |
|
|
|
|
|
|
|
|
|
|
|
override fun onResume() { |
|
|
|
|
|
|
|
super.onResume() |
|
|
|
|
|
|
|
launchStatComputation() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
@ -120,11 +113,11 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override val observedEntities: List<Class<out RealmModel>> = listOf(ComputableResult::class.java) |
|
|
|
// override val observedEntities: List<Class<out RealmModel>> = listOf(ComputableResult::class.java) |
|
|
|
|
|
|
|
|
|
|
|
override fun entitiesChanged(clazz: Class<out RealmModel>, results: RealmResults<out RealmModel>) { |
|
|
|
// override fun entitiesChanged(clazz: Class<out RealmModel>, results: RealmResults<out RealmModel>) { |
|
|
|
launchStatComputation() |
|
|
|
// launchAsyncStatComputation() |
|
|
|
} |
|
|
|
// } |
|
|
|
|
|
|
|
|
|
|
|
// Business |
|
|
|
// Business |
|
|
|
|
|
|
|
|
|
|
|
@ -132,6 +125,7 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
* Init data |
|
|
|
* Init data |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun initData() { |
|
|
|
private fun initData() { |
|
|
|
|
|
|
|
launchAsyncStatComputation() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -173,7 +167,7 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
sessionTypeCondition = null |
|
|
|
sessionTypeCondition = null |
|
|
|
filterSessionCash.isChecked = false |
|
|
|
filterSessionCash.isChecked = false |
|
|
|
filterSessionTournament.isChecked = false |
|
|
|
filterSessionTournament.isChecked = false |
|
|
|
launchStatComputation() |
|
|
|
launchAsyncStatComputation() |
|
|
|
} else if (sessionTypeCondition == null) { |
|
|
|
} else if (sessionTypeCondition == null) { |
|
|
|
filterSessionAll.isChecked = true |
|
|
|
filterSessionAll.isChecked = true |
|
|
|
} |
|
|
|
} |
|
|
|
@ -183,7 +177,7 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
sessionTypeCondition = QueryCondition.IsCash |
|
|
|
sessionTypeCondition = QueryCondition.IsCash |
|
|
|
filterSessionAll.isChecked = false |
|
|
|
filterSessionAll.isChecked = false |
|
|
|
filterSessionTournament.isChecked = false |
|
|
|
filterSessionTournament.isChecked = false |
|
|
|
launchStatComputation() |
|
|
|
launchAsyncStatComputation() |
|
|
|
} else if (sessionTypeCondition == QueryCondition.IsCash) { |
|
|
|
} else if (sessionTypeCondition == QueryCondition.IsCash) { |
|
|
|
filterSessionCash.isChecked = true |
|
|
|
filterSessionCash.isChecked = true |
|
|
|
} |
|
|
|
} |
|
|
|
@ -193,7 +187,7 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
sessionTypeCondition = QueryCondition.IsTournament |
|
|
|
sessionTypeCondition = QueryCondition.IsTournament |
|
|
|
filterSessionAll.isChecked = false |
|
|
|
filterSessionAll.isChecked = false |
|
|
|
filterSessionCash.isChecked = false |
|
|
|
filterSessionCash.isChecked = false |
|
|
|
launchStatComputation() |
|
|
|
launchAsyncStatComputation() |
|
|
|
} else if (sessionTypeCondition == QueryCondition.IsTournament) { |
|
|
|
} else if (sessionTypeCondition == QueryCondition.IsTournament) { |
|
|
|
filterSessionTournament.isChecked = true |
|
|
|
filterSessionTournament.isChecked = true |
|
|
|
} |
|
|
|
} |
|
|
|
@ -233,22 +227,35 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Launch stat computation |
|
|
|
* Asynchronously Launch stat computation |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun launchStatComputation() { |
|
|
|
private fun launchAsyncStatComputation() { |
|
|
|
|
|
|
|
|
|
|
|
progressBar?.showWithAnimation() |
|
|
|
progressBar?.showWithAnimation() |
|
|
|
recyclerView?.hideWithAnimation() |
|
|
|
recyclerView?.hideWithAnimation() |
|
|
|
|
|
|
|
|
|
|
|
GlobalScope.launch { |
|
|
|
GlobalScope.launch { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
|
|
|
realm.refresh() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
launchStatComputation(realm) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
realm.close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GlobalScope.launch(Dispatchers.Main) { |
|
|
|
|
|
|
|
displayData() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun launchStatComputation(realm: Realm) { |
|
|
|
|
|
|
|
|
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
val calendar = Calendar.getInstance() |
|
|
|
calendar.time = Date().startOfMonth() |
|
|
|
calendar.time = Date().startOfMonth() |
|
|
|
|
|
|
|
|
|
|
|
val startDate = Date() |
|
|
|
val startDate = Date() |
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val monthlyReports: HashMap<Date, ComputedResults> = HashMap() |
|
|
|
val monthlyReports: HashMap<Date, ComputedResults> = HashMap() |
|
|
|
val yearlyReports: HashMap<Date, ComputedResults> = HashMap() |
|
|
|
val yearlyReports: HashMap<Date, ComputedResults> = HashMap() |
|
|
|
@ -337,19 +344,13 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
Timber.d("$it => ${sortedYearlyReports[it]?.computedStat(Stat.NET_RESULT)?.value}") |
|
|
|
Timber.d("$it => ${sortedYearlyReports[it]?.computedStat(Stat.NET_RESULT)?.value}") |
|
|
|
} |
|
|
|
} |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
realm.close() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GlobalScope.launch(Dispatchers.Main) { |
|
|
|
|
|
|
|
displayData() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Display data |
|
|
|
* Display data |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun displayData() { |
|
|
|
private fun displayData() { |
|
|
|
|
|
|
|
Timber.d("displayData") |
|
|
|
|
|
|
|
|
|
|
|
val startDate = Date() |
|
|
|
val startDate = Date() |
|
|
|
|
|
|
|
|
|
|
|
@ -415,4 +416,13 @@ class CalendarFragment : RealmFragment(), CoroutineScope, StaticRowRepresentable |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun asyncListenedEntityChange(realm: Realm) { |
|
|
|
|
|
|
|
Timber.d("asyncListenedEntityChange") |
|
|
|
|
|
|
|
launchStatComputation(realm) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
activity?.runOnUiThread { |
|
|
|
|
|
|
|
displayData() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |