|
|
|
@ -1,29 +1,47 @@ |
|
|
|
package net.pokeranalytics.android.ui.fragment |
|
|
|
package net.pokeranalytics.android.ui.fragment |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.app.Activity |
|
|
|
|
|
|
|
import android.content.Intent |
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Bundle |
|
|
|
import android.view.LayoutInflater |
|
|
|
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 io.realm.Realm |
|
|
|
import io.realm.RealmResults |
|
|
|
import io.realm.RealmResults |
|
|
|
import kotlinx.android.synthetic.main.fragment_bankroll.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_bankroll.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_stats.recyclerView |
|
|
|
import kotlinx.android.synthetic.main.fragment_stats.recyclerView |
|
|
|
|
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
|
|
|
|
import kotlinx.coroutines.GlobalScope |
|
|
|
|
|
|
|
import kotlinx.coroutines.delay |
|
|
|
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
import net.pokeranalytics.android.R |
|
|
|
|
|
|
|
import net.pokeranalytics.android.calculus.Calculator |
|
|
|
import net.pokeranalytics.android.calculus.ComputedStat |
|
|
|
import net.pokeranalytics.android.calculus.ComputedStat |
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
import net.pokeranalytics.android.calculus.bankroll.BankrollCalculator |
|
|
|
import net.pokeranalytics.android.calculus.bankroll.BankrollCalculator |
|
|
|
|
|
|
|
import net.pokeranalytics.android.calculus.bankroll.BankrollReport |
|
|
|
import net.pokeranalytics.android.calculus.bankroll.BankrollReportSetup |
|
|
|
import net.pokeranalytics.android.calculus.bankroll.BankrollReportSetup |
|
|
|
|
|
|
|
import net.pokeranalytics.android.model.Criteria |
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
import net.pokeranalytics.android.model.LiveData |
|
|
|
import net.pokeranalytics.android.model.realm.Bankroll |
|
|
|
import net.pokeranalytics.android.model.realm.Bankroll |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.activity.DataListActivity |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.activity.EditableDataActivity |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.activity.StatisticDetailsActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.components.PokerAnalyticsActivity |
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter |
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter |
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
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.toast |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.fragment.DataListFragment.Companion.REQUEST_CODE_DETAILS |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.PokerAnalyticsFragment |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.RowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.RowViewType |
|
|
|
import net.pokeranalytics.android.ui.view.RowViewType |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.GraphRow |
|
|
|
import timber.log.Timber |
|
|
|
import timber.log.Timber |
|
|
|
|
|
|
|
import java.util.* |
|
|
|
|
|
|
|
import kotlin.collections.ArrayList |
|
|
|
|
|
|
|
|
|
|
|
class BankrollFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate { |
|
|
|
class BankrollFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate { |
|
|
|
|
|
|
|
|
|
|
|
@ -42,8 +60,9 @@ class BankrollFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSou |
|
|
|
|
|
|
|
|
|
|
|
private lateinit var parentActivity: PokerAnalyticsActivity |
|
|
|
private lateinit var parentActivity: PokerAnalyticsActivity |
|
|
|
private lateinit var bankrollAdapter: RowRepresentableAdapter |
|
|
|
private lateinit var bankrollAdapter: RowRepresentableAdapter |
|
|
|
private lateinit var bankrolls: RealmResults<Bankroll> |
|
|
|
|
|
|
|
private var rows: ArrayList<RowRepresentable> = ArrayList() |
|
|
|
private var rows: ArrayList<RowRepresentable> = ArrayList() |
|
|
|
|
|
|
|
private var bankrollReportForRow: HashMap<RowRepresentable, BankrollReport> = HashMap() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Life Cycle |
|
|
|
// Life Cycle |
|
|
|
|
|
|
|
|
|
|
|
@ -57,15 +76,40 @@ class BankrollFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSou |
|
|
|
initData() |
|
|
|
initData() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
|
|
|
|
|
|
|
super.onActivityResult(requestCode, resultCode, data) |
|
|
|
|
|
|
|
if (requestCode == REQUEST_CODE_DETAILS && resultCode == Activity.RESULT_OK) { |
|
|
|
|
|
|
|
val needToDeleteItem = data?.getBooleanExtra(DataListActivity.IntentKey.ITEM_DELETED.keyName, false) ?: false |
|
|
|
|
|
|
|
if (needToDeleteItem) { |
|
|
|
|
|
|
|
GlobalScope.launch(Dispatchers.Main) { |
|
|
|
|
|
|
|
delay(300) |
|
|
|
|
|
|
|
//TODO: Delete bankroll |
|
|
|
|
|
|
|
//deleteItem(lastItemClickedPosition) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
Timber.d("adapterRows: ${rows.size}") |
|
|
|
|
|
|
|
return rows |
|
|
|
return rows |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
|
|
|
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
|
|
|
|
|
|
|
Timber.d("onRowSelected: $row") |
|
|
|
|
|
|
|
when(row) { |
|
|
|
|
|
|
|
is GraphRow -> { |
|
|
|
|
|
|
|
row.report.results.firstOrNull()?.group?.let { computableGroup -> |
|
|
|
|
|
|
|
StatisticDetailsActivity.newInstance(requireContext(), row.stat, computableGroup, row.report, false, row.title) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else -> { |
|
|
|
|
|
|
|
if (bankrollReportForRow.containsKey(row)) { |
|
|
|
|
|
|
|
val bankrollReport = bankrollReportForRow[row] |
|
|
|
|
|
|
|
toast("${bankrollReport?.total}") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Business |
|
|
|
// Business |
|
|
|
@ -75,38 +119,55 @@ class BankrollFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSou |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun initData() { |
|
|
|
private fun initData() { |
|
|
|
|
|
|
|
|
|
|
|
// Graph |
|
|
|
rows.clear() |
|
|
|
//rows.add(GraphRow(report, Stat.NET_RESULT)) |
|
|
|
bankrollReportForRow.clear() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GlobalScope.launch { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val startDate = Date() |
|
|
|
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
|
|
|
|
|
|
|
// Global |
|
|
|
// Graph |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val requiredStats: List<Stat> = listOf(Stat.NET_RESULT) |
|
|
|
|
|
|
|
val options = Calculator.Options( |
|
|
|
|
|
|
|
evolutionValues = Calculator.Options.EvolutionValues.STANDARD, |
|
|
|
|
|
|
|
stats = requiredStats, |
|
|
|
|
|
|
|
criterias = listOf(Criteria.Bankrolls) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
val start = System.currentTimeMillis() |
|
|
|
val report = Calculator.computeStats(realm, options = options) |
|
|
|
|
|
|
|
rows.add(0, GraphRow(report, Stat.NET_RESULT)) |
|
|
|
|
|
|
|
|
|
|
|
val globalBankrollReportSetup = BankrollReportSetup() |
|
|
|
val globalBankrollReportSetup = BankrollReportSetup() |
|
|
|
val globalBankrollReport = BankrollCalculator.computeReport(globalBankrollReportSetup) |
|
|
|
val globalBankrollReport = BankrollCalculator.computeReport(globalBankrollReportSetup) |
|
|
|
|
|
|
|
|
|
|
|
Timber.d("bankrollReport: ${globalBankrollReport.total}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rows.add(globalBankrollReport) |
|
|
|
rows.add(globalBankrollReport) |
|
|
|
|
|
|
|
bankrollReportForRow[globalBankrollReport] = globalBankrollReport |
|
|
|
|
|
|
|
|
|
|
|
// Bankrolls |
|
|
|
// Bankrolls |
|
|
|
rows.add(CustomizableRowRepresentable(RowViewType.HEADER_TITLE, resId = R.string.bankrolls)) |
|
|
|
rows.add(CustomizableRowRepresentable(RowViewType.HEADER_TITLE, resId = R.string.bankrolls)) |
|
|
|
|
|
|
|
|
|
|
|
bankrolls = LiveData.BANKROLL.items(getRealm()) as RealmResults<Bankroll> |
|
|
|
val bankrolls = LiveData.BANKROLL.items(realm) as RealmResults<Bankroll> |
|
|
|
Timber.d("Bankrolls: ${bankrolls.size}") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bankrolls.forEach { |
|
|
|
bankrolls.forEach { |
|
|
|
val bankrollReportSetup = BankrollReportSetup(it) |
|
|
|
val bankrollReportSetup = BankrollReportSetup(it) |
|
|
|
val bankrollReport = BankrollCalculator.computeReport(bankrollReportSetup) |
|
|
|
val bankrollReport = BankrollCalculator.computeReport(bankrollReportSetup) |
|
|
|
val computedStat = ComputedStat(Stat.NET_RESULT, bankrollReport.total) |
|
|
|
val computedStat = ComputedStat(Stat.NET_RESULT, bankrollReport.total) |
|
|
|
rows.add(CustomizableRowRepresentable(RowViewType.TITLE_VALUE_ARROW, title = it.name, computedStat = computedStat)) |
|
|
|
val row = CustomizableRowRepresentable(RowViewType.TITLE_VALUE_ARROW, title = it.name, computedStat = computedStat, isSelectable = true) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rows.add(row) |
|
|
|
|
|
|
|
bankrollReportForRow[row] = bankrollReport |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Timber.d("Done in: ${System.currentTimeMillis() - start}ms") |
|
|
|
realm.close() |
|
|
|
Timber.d("initData: ${rows.size} rows") |
|
|
|
Timber.d("initData: ${System.currentTimeMillis() - startDate.time}ms") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
launch(Dispatchers.Main) { |
|
|
|
|
|
|
|
if (!isDetached) { |
|
|
|
|
|
|
|
bankrollAdapter.notifyDataSetChanged() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -130,6 +191,16 @@ class BankrollFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSou |
|
|
|
layoutManager = viewManager |
|
|
|
layoutManager = viewManager |
|
|
|
adapter = bankrollAdapter |
|
|
|
adapter = bankrollAdapter |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
addButton.setOnClickListener { |
|
|
|
|
|
|
|
LiveData.BANKROLL?.let { |
|
|
|
|
|
|
|
EditableDataActivity.newInstance( |
|
|
|
|
|
|
|
requireContext(), |
|
|
|
|
|
|
|
dataType = it.ordinal, |
|
|
|
|
|
|
|
primaryKey = null |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |