|
|
|
|
@ -1,5 +1,7 @@ |
|
|
|
|
package net.pokeranalytics.android.ui.fragment |
|
|
|
|
|
|
|
|
|
import android.app.Activity |
|
|
|
|
import android.content.Intent |
|
|
|
|
import android.os.Bundle |
|
|
|
|
import android.view.LayoutInflater |
|
|
|
|
import android.view.View |
|
|
|
|
@ -17,8 +19,10 @@ import net.pokeranalytics.android.calculus.Calculator |
|
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
|
import net.pokeranalytics.android.model.Criteria |
|
|
|
|
import net.pokeranalytics.android.model.combined |
|
|
|
|
import net.pokeranalytics.android.ui.activity.ComparisonReportActivity |
|
|
|
|
import net.pokeranalytics.android.ui.activity.ReportCreationActivity |
|
|
|
|
import net.pokeranalytics.android.ui.activity.ReportDetailsActivity |
|
|
|
|
import net.pokeranalytics.android.ui.activity.ProgressReportActivity |
|
|
|
|
import net.pokeranalytics.android.ui.activity.TableReportActivity |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableAdapter |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate |
|
|
|
|
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource |
|
|
|
|
@ -65,6 +69,17 @@ class ReportsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSour |
|
|
|
|
initUI() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { |
|
|
|
|
super.onActivityResult(requestCode, resultCode, data) |
|
|
|
|
|
|
|
|
|
if (requestCode == ReportCreationActivity.RequestCode.NEW_REPORT.ordinal && resultCode == Activity.RESULT_OK) { |
|
|
|
|
ReportCreationActivity.options?.let { options -> |
|
|
|
|
this.launchReportWithOptions(options, options.defaultName) |
|
|
|
|
} |
|
|
|
|
ReportCreationActivity.options = null |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Rows |
|
|
|
|
|
|
|
|
|
override fun adapterRows(): List<RowRepresentable>? { |
|
|
|
|
@ -79,7 +94,6 @@ class ReportsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSour |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Business |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
@ -104,7 +118,7 @@ class ReportsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSour |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.addButton.setOnClickListener { |
|
|
|
|
ReportCreationActivity.newInstance(requireContext()) |
|
|
|
|
ReportCreationActivity.newInstanceForResult(this, requireContext()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
@ -119,6 +133,20 @@ class ReportsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSour |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
val requiredStats: List<Stat> = listOf(Stat.NET_RESULT) |
|
|
|
|
val options = Calculator.Options( |
|
|
|
|
display = Calculator.Options.Display.COMPARISON, |
|
|
|
|
evolutionValues = Calculator.Options.EvolutionValues.STANDARD, |
|
|
|
|
stats = requiredStats, |
|
|
|
|
criterias = criteriaList |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
this.launchReportWithOptions(options, reportName) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun launchReportWithOptions(options: Calculator.Options, reportName: String) { |
|
|
|
|
|
|
|
|
|
showLoader() |
|
|
|
|
|
|
|
|
|
GlobalScope.launch { |
|
|
|
|
@ -126,13 +154,6 @@ class ReportsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSour |
|
|
|
|
val startDate = Date() |
|
|
|
|
val realm = Realm.getDefaultInstance() |
|
|
|
|
|
|
|
|
|
val requiredStats: List<Stat> = listOf(Stat.NET_RESULT) |
|
|
|
|
val options = Calculator.Options( |
|
|
|
|
evolutionValues = Calculator.Options.EvolutionValues.STANDARD, |
|
|
|
|
stats = requiredStats, |
|
|
|
|
criterias = criteriaList |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
val report = Calculator.computeStats(realm, options = options) |
|
|
|
|
|
|
|
|
|
Timber.d("launchComputation: ${System.currentTimeMillis() - startDate.time}ms") |
|
|
|
|
@ -140,12 +161,27 @@ class ReportsFragment : PokerAnalyticsFragment(), StaticRowRepresentableDataSour |
|
|
|
|
launch(Dispatchers.Main) { |
|
|
|
|
if (!isDetached) { |
|
|
|
|
hideLoader() |
|
|
|
|
ReportDetailsActivity.newInstance(requireContext(), report, reportName) |
|
|
|
|
|
|
|
|
|
when (options.display) { |
|
|
|
|
Calculator.Options.Display.TABLE -> { |
|
|
|
|
TableReportActivity.newInstance(requireContext(), report, reportName) |
|
|
|
|
} |
|
|
|
|
Calculator.Options.Display.PROGRESS -> { |
|
|
|
|
ProgressReportActivity.newInstance(requireContext(), options.stats.first(), report) |
|
|
|
|
} |
|
|
|
|
Calculator.Options.Display.COMPARISON -> { |
|
|
|
|
ComparisonReportActivity.newInstance(requireContext(), report, reportName) |
|
|
|
|
} |
|
|
|
|
else -> { |
|
|
|
|
Timber.d("Report type not handled at the moment") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
realm.close() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |