|
|
|
@ -9,6 +9,7 @@ import android.view.ViewGroup |
|
|
|
import android.widget.Toast |
|
|
|
import android.widget.Toast |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import io.realm.Realm |
|
|
|
import io.realm.Realm |
|
|
|
|
|
|
|
import io.realm.RealmResults |
|
|
|
import kotlinx.android.synthetic.main.fragment_data_list.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_data_list.* |
|
|
|
import kotlinx.android.synthetic.main.fragment_stats.recyclerView |
|
|
|
import kotlinx.android.synthetic.main.fragment_stats.recyclerView |
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
@ -19,21 +20,27 @@ import net.pokeranalytics.android.calculus.Calculator |
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
import net.pokeranalytics.android.model.Criteria |
|
|
|
import net.pokeranalytics.android.model.Criteria |
|
|
|
import net.pokeranalytics.android.model.combined |
|
|
|
import net.pokeranalytics.android.model.combined |
|
|
|
|
|
|
|
import net.pokeranalytics.android.model.realm.ReportSetup |
|
|
|
import net.pokeranalytics.android.ui.activity.ComparisonReportActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.ComparisonReportActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.ReportCreationActivity |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.activity.ProgressReportActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.ProgressReportActivity |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.activity.ReportCreationActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.TableReportActivity |
|
|
|
import net.pokeranalytics.android.ui.activity.TableReportActivity |
|
|
|
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.fragment.components.PokerAnalyticsFragment |
|
|
|
import net.pokeranalytics.android.ui.fragment.components.RealmFragment |
|
|
|
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.rowrepresentable.CustomizableRowRepresentable |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.ReportRow |
|
|
|
import net.pokeranalytics.android.ui.view.rowrepresentable.ReportRow |
|
|
|
import timber.log.Timber |
|
|
|
import timber.log.Timber |
|
|
|
import java.util.* |
|
|
|
import java.util.* |
|
|
|
import kotlin.collections.ArrayList |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ReportsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate { |
|
|
|
class ReportsFragment : RealmFragment(), StaticRowRepresentableDataSource, RowRepresentableDelegate { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private lateinit var reportsAdapter: RowRepresentableAdapter |
|
|
|
|
|
|
|
private lateinit var reportSetups: RealmResults<ReportSetup> |
|
|
|
|
|
|
|
private var adapterRows = mutableListOf<RowRepresentable>() |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
|
|
@ -47,19 +54,12 @@ class ReportsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSour |
|
|
|
return fragment |
|
|
|
return fragment |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val rowRepresentation: List<RowRepresentable> by lazy { |
|
|
|
|
|
|
|
val rows = ArrayList<RowRepresentable>() |
|
|
|
|
|
|
|
rows.addAll(ReportRow.getRows()) |
|
|
|
|
|
|
|
rows |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private lateinit var reportsAdapter: RowRepresentableAdapter |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Life Cycle |
|
|
|
// Life Cycle |
|
|
|
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { |
|
|
|
|
|
|
|
super.onCreateView(inflater, container, savedInstanceState) |
|
|
|
return inflater.inflate(R.layout.fragment_reports, container, false) |
|
|
|
return inflater.inflate(R.layout.fragment_reports, container, false) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -67,6 +67,7 @@ class ReportsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSour |
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
initData() |
|
|
|
initData() |
|
|
|
initUI() |
|
|
|
initUI() |
|
|
|
|
|
|
|
this.updateRows() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
|
|
|
@ -80,19 +81,6 @@ class ReportsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSour |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Rows |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
|
|
|
|
return rowRepresentation |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
|
|
|
|
|
|
|
super.onRowSelected(position, row, fromAction) |
|
|
|
|
|
|
|
if (row is ReportRow) { |
|
|
|
|
|
|
|
val reportName = row.localizedTitle(requireContext()) |
|
|
|
|
|
|
|
launchComputation(row.criteria, reportName) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Business |
|
|
|
// Business |
|
|
|
|
|
|
|
|
|
|
|
@ -100,6 +88,10 @@ class ReportsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSour |
|
|
|
* Init data |
|
|
|
* Init data |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private fun initData() { |
|
|
|
private fun initData() { |
|
|
|
|
|
|
|
this.reportSetups = getRealm().where(ReportSetup::class.java).findAll().sort("name") |
|
|
|
|
|
|
|
this.reportSetups.addChangeListener { _, _ -> |
|
|
|
|
|
|
|
this.updateRows() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -123,6 +115,36 @@ class ReportsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSour |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Rows |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun updateRows() { |
|
|
|
|
|
|
|
this.adapterRows.clear() |
|
|
|
|
|
|
|
if (this.reportSetups.size > 0) { |
|
|
|
|
|
|
|
adapterRows.add(CustomizableRowRepresentable(customViewType = RowViewType.HEADER_TITLE, resId = R.string.custom)) |
|
|
|
|
|
|
|
adapterRows.addAll(this.reportSetups) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
adapterRows.addAll(ReportRow.getRows()) |
|
|
|
|
|
|
|
this.reportsAdapter.notifyDataSetChanged() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
|
|
|
|
return this.adapterRows |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onRowSelected(position: Int, row: RowRepresentable, fromAction: Boolean) { |
|
|
|
|
|
|
|
super.onRowSelected(position, row, fromAction) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
when (row) { |
|
|
|
|
|
|
|
is ReportRow -> { |
|
|
|
|
|
|
|
val reportName = row.localizedTitle(requireContext()) |
|
|
|
|
|
|
|
launchComputation(row.criteria, reportName) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
is ReportSetup -> { |
|
|
|
|
|
|
|
launchReportWithOptions(row.options, row.name) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Launch computation |
|
|
|
* Launch computation |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -145,6 +167,9 @@ class ReportsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSour |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Launch and display a report with some [options] and a [reportName] |
|
|
|
|
|
|
|
*/ |
|
|
|
private fun launchReportWithOptions(options: Calculator.Options, reportName: String) { |
|
|
|
private fun launchReportWithOptions(options: Calculator.Options, reportName: String) { |
|
|
|
|
|
|
|
|
|
|
|
showLoader() |
|
|
|
showLoader() |
|
|
|
@ -176,8 +201,6 @@ class ReportsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSour |
|
|
|
Timber.d("Report type not handled at the moment") |
|
|
|
Timber.d("Report type not handled at the moment") |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
realm.close() |
|
|
|
realm.close() |
|
|
|
|