|
|
|
@ -5,17 +5,27 @@ import android.content.Intent |
|
|
|
import android.os.Bundle |
|
|
|
import android.os.Bundle |
|
|
|
import androidx.fragment.app.Fragment |
|
|
|
import androidx.fragment.app.Fragment |
|
|
|
import androidx.lifecycle.ViewModelProviders |
|
|
|
import androidx.lifecycle.ViewModelProviders |
|
|
|
import com.crashlytics.android.Crashlytics |
|
|
|
|
|
|
|
import net.pokeranalytics.android.calculus.Report |
|
|
|
import net.pokeranalytics.android.calculus.Report |
|
|
|
import net.pokeranalytics.android.calculus.Stat |
|
|
|
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.ReportViewModel |
|
|
|
|
|
|
|
import net.pokeranalytics.android.ui.viewmodel.ReportViewModelFactory |
|
|
|
|
|
|
|
|
|
|
|
class ReportParameters(var report: Report, var title: String, var stat: Stat? = null, var showAggregationChoices: Boolean = true) |
|
|
|
class ReportParameters(var report: Report, var title: String, var stat: Stat? = null, var showAggregationChoices: Boolean = true) |
|
|
|
|
|
|
|
|
|
|
|
abstract class ReportActivity : PokerAnalyticsActivity() { |
|
|
|
abstract class ReportActivity : PokerAnalyticsActivity() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected 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") |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected val viewModel: ReportViewModel by lazy { |
|
|
|
protected val viewModel: ReportViewModel by lazy { |
|
|
|
ViewModelProviders.of(this).get(ReportViewModel::class.java) |
|
|
|
ViewModelProviders.of(this, viewModelFactory).get(ReportViewModel::class.java) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
companion object { |
|
|
|
@ -43,19 +53,24 @@ abstract class ReportActivity : PokerAnalyticsActivity() { |
|
|
|
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) { |
|
|
|
override fun onCreate(savedInstanceState: Bundle?) { |
|
|
|
super.onCreate(savedInstanceState) |
|
|
|
super.onCreate(savedInstanceState) |
|
|
|
this.initViewModelWithParameters() |
|
|
|
// this.initViewModelWithParameters() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun onStart() { |
|
|
|
|
|
|
|
super.onStart() |
|
|
|
|
|
|
|
ReportViewModel.resetParameters() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun initViewModelWithParameters() { |
|
|
|
private fun initViewModelWithParameters() { |
|
|
|
|
|
|
|
|
|
|
|
ReportViewModel.parameters?.let { |
|
|
|
ReportViewModel.parameters?.let { |
|
|
|
this.viewModel.report = it.report |
|
|
|
// this.viewModel.report = it.report |
|
|
|
this.viewModel.title = it.title |
|
|
|
// this.viewModel.title = it.title |
|
|
|
val stat = it.stat ?: it.report.options.stats.first() |
|
|
|
// val stat = it.stat ?: it.report.options.stats.first() |
|
|
|
this.viewModel.stat = stat |
|
|
|
// this.viewModel.stat = stat |
|
|
|
this.viewModel.showAggregationChoices = it.showAggregationChoices |
|
|
|
// this.viewModel.showAggregationChoices = it.showAggregationChoices |
|
|
|
|
|
|
|
|
|
|
|
Crashlytics.log("initViewModelWithParameters, stat = ${stat.uniqueIdentifier}") |
|
|
|
// Crashlytics.log("initViewModelWithParameters, stat = ${stat.uniqueIdentifier}") |
|
|
|
|
|
|
|
|
|
|
|
ReportViewModel.resetParameters() |
|
|
|
ReportViewModel.resetParameters() |
|
|
|
} |
|
|
|
} |
|
|
|
|