From ecfbb87a42282027bfe5f2d9ce8d498372aac7f3 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 4 Jan 2021 15:11:23 +0100 Subject: [PATCH] Might fix crash, at least give better logs --- .../android/ui/fragment/GraphFragment.kt | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt index 40484a78..a9b845d4 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/GraphFragment.kt @@ -55,14 +55,24 @@ class GraphFragment : RealmFragment(), OnChartValueSelectedListener { return this.graphDataProvider.stat } - private var _defaultStyle: Graph.Style? = null - /*** * Uses forced style first, or the style set */ private val style: Graph.Style get() { - return this.graphDataProvider.style ?: this._defaultStyle ?: throw PAIllegalStateException("Graph style undefined") + val style = this.graphDataProvider.style + if (style != null) { + return style + } + + this.arguments?.let { bundle -> + if (bundle.containsKey(BundleKey.STYLE.value)) { + val styleIndex = bundle.getInt(BundleKey.STYLE.value) + return Graph.Style.values()[styleIndex] + } else { + throw PAIllegalStateException("Style not defined for $this") + } + } ?: throw PAIllegalStateException("Style and bundle not defined for $this") } private lateinit var legendView: LegendView @@ -93,13 +103,6 @@ class GraphFragment : RealmFragment(), OnChartValueSelectedListener { } private fun initData() { - - this.arguments?.let { bundle -> - if (bundle.containsKey(BundleKey.STYLE.value)) { - this._defaultStyle = Graph.Style.values()[bundle.getInt(BundleKey.STYLE.value)] - } - } - this.graphDataProvider = (requireActivity() as ViewModelHolder).model as GraphDataProvider }