|
|
|
|
@ -7,26 +7,24 @@ import androidx.fragment.app.Fragment |
|
|
|
|
import androidx.lifecycle.ViewModelProviders |
|
|
|
|
import net.pokeranalytics.android.calculus.Report |
|
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
|
import net.pokeranalytics.android.exceptions.PAIllegalStateException |
|
|
|
|
import net.pokeranalytics.android.ui.viewmodel.ReportViewModel |
|
|
|
|
import net.pokeranalytics.android.ui.viewmodel.ReportViewModelFactory |
|
|
|
|
import net.pokeranalytics.android.ui.viewmodel.ViewModelHolder |
|
|
|
|
|
|
|
|
|
class ReportParameters(var report: Report, var title: String, var stat: Stat? = null, var showAggregationChoices: Boolean = true) |
|
|
|
|
|
|
|
|
|
abstract class ReportActivity : PokerAnalyticsActivity(), ViewModelHolder { |
|
|
|
|
|
|
|
|
|
private val viewModelFactory: ReportViewModelFactory by lazy { |
|
|
|
|
ReportViewModel.parameters?.let { |
|
|
|
|
val stat = it.stat ?: it.report.options.stats.first() |
|
|
|
|
ReportViewModelFactory(it.report, stat, it.title, it.showAggregationChoices) |
|
|
|
|
} ?: run { |
|
|
|
|
throw PAIllegalStateException("null report parameters") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// private val viewModelFactory: ReportViewModelFactory by lazy { |
|
|
|
|
// ReportViewModel.parameters?.let { |
|
|
|
|
// val stat = it.stat ?: it.report.options.stats.first() |
|
|
|
|
// ReportViewModelFactory(it.report, stat, it.title, it.showAggregationChoices) |
|
|
|
|
// } ?: run { |
|
|
|
|
// throw PAIllegalStateException("null report parameters") |
|
|
|
|
// } |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
override val viewModel: ReportViewModel by lazy { |
|
|
|
|
ViewModelProviders.of(this, viewModelFactory).get(ReportViewModel::class.java) |
|
|
|
|
ViewModelProviders.of(this).get(ReportViewModel::class.java) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
@ -54,7 +52,7 @@ abstract class ReportActivity : PokerAnalyticsActivity(), ViewModelHolder { |
|
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) { |
|
|
|
|
super.onCreate(savedInstanceState) |
|
|
|
|
// this.initViewModelWithParameters() |
|
|
|
|
this.initViewModelWithParameters() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onStart() { |
|
|
|
|
@ -65,11 +63,11 @@ abstract class ReportActivity : PokerAnalyticsActivity(), ViewModelHolder { |
|
|
|
|
private fun initViewModelWithParameters() { |
|
|
|
|
|
|
|
|
|
ReportViewModel.parameters?.let { |
|
|
|
|
// this.viewModel.report = it.report |
|
|
|
|
// this.viewModel.title = it.title |
|
|
|
|
// val stat = it.stat ?: it.report.options.stats.first() |
|
|
|
|
// this.viewModel.stat = stat |
|
|
|
|
// this.viewModel.showAggregationChoices = it.showAggregationChoices |
|
|
|
|
this.viewModel.report = it.report |
|
|
|
|
this.viewModel.title = it.title |
|
|
|
|
val stat = it.stat ?: it.report.options.stats.first() |
|
|
|
|
this.viewModel.stat = stat |
|
|
|
|
this.viewModel.showAggregationChoices = it.showAggregationChoices |
|
|
|
|
|
|
|
|
|
// Crashlytics.log("initViewModelWithParameters, stat = ${stat.uniqueIdentifier}") |
|
|
|
|
|
|
|
|
|
|