From 02ba62654fbe3a263b9447ac9eacfe0a4a8e90cf Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 23 Apr 2021 11:52:34 +0200 Subject: [PATCH] Fixes crash occuring when setting player setups --- .../android/model/realm/handhistory/HandHistory.kt | 2 +- .../ui/modules/handhistory/editor/EditorFragment.kt | 9 ++++++++- .../ui/modules/handhistory/model/EditorViewModel.kt | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt index d238cca1..b2903001 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt @@ -619,7 +619,7 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, } // Check who has best score (EvaluatorBridge gives a lowest score for a better hand) - return results.min()?.let { best -> + return results.minOrNull()?.let { best -> val winners = mutableListOf() results.forEachIndexed { index, i -> if (i == best && i != Int.MAX_VALUE) { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/editor/EditorFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/editor/EditorFragment.kt index b2a98654..89330e71 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/editor/EditorFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/editor/EditorFragment.kt @@ -68,6 +68,8 @@ class EditorFragment : RealmFragment(), RowRepresentableDelegate, KeyboardListen return this.model.isEdited } + private var isKeyboardShown: Boolean = false + private var _binding: FragmentHandHistoryBinding? = null private val binding get() = _binding!! @@ -467,7 +469,7 @@ class EditorFragment : RealmFragment(), RowRepresentableDelegate, KeyboardListen } HandRowType.PLAYER_POSITION -> { this.model.createPlayerSetupForPosition(value as Position) - this.editorAdapter.notifyDataSetChanged() +// this.editorAdapter.notifyDataSetChanged() } is ComputedAction -> { this.model.amountChanged(value as String) @@ -638,6 +640,10 @@ class EditorFragment : RealmFragment(), RowRepresentableDelegate, KeyboardListen */ private fun animateKeyboard(show: Boolean, endHandler: (() -> (Unit))? = null) { + if (show == this.isKeyboardShown) { + return + } + val height = 310.0f.px val start = if (show) 0.0f else height val end = if (show) height else 0.0f @@ -656,6 +662,7 @@ class EditorFragment : RealmFragment(), RowRepresentableDelegate, KeyboardListen this.binding.kbTopGuideline.layoutParams = lp if (lp.guideEnd == end.toInt()) { + this.isKeyboardShown = show endHandler?.invoke() } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/EditorViewModel.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/EditorViewModel.kt index 5fb462e2..8cba02d5 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/EditorViewModel.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/EditorViewModel.kt @@ -966,6 +966,8 @@ class EditorViewModel : ViewModel(), RowRepresentableDataSource, CardCentralizer val positionIndex = this.sortedActions.positions.indexOf(position) this.handHistory.createPlayerSetup(positionIndex) + this.clearSelection() + // refresh rows this.createRowRepresentation() }