From 9254c404252b4e4ff69fffc6b7f660a1caef35dc Mon Sep 17 00:00:00 2001 From: Laurent Date: Thu, 13 Feb 2020 11:14:27 +0100 Subject: [PATCH] Fixes various bugs --- .../handhistory/HandHistoryFragment.kt | 42 ++++++++++--------- .../modules/handhistory/model/ActionList.kt | 2 +- .../handhistory/model/ComputedAction.kt | 6 +-- .../handhistory/model/HandHistoryViewModel.kt | 33 ++++++++------- .../handhistory/model/StreetHeaderRow.kt | 28 +++++++++++++ 5 files changed, 72 insertions(+), 39 deletions(-) create mode 100644 app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetHeaderRow.kt diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt index 849934af..f4a17d22 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt @@ -260,7 +260,10 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL this.model.setPlayerSetupPosition(row, value) val index = this.indexOfRowRepresentable(row) this.handHistoryAdapter.notifyItemChanged(index) - this.findNextActionToEdit(index) + + if (row.tagForCompletion(this.model.handHistory) != null) { + this.findNextActionToEdit(index) + } } } } @@ -286,6 +289,25 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL this.findNextActionToEdit() } + override fun amountValidated() { + Timber.d(">>> amount validated") + getRealm().executeTransaction { + this.model.amountValidated() + } +// this.handHistoryAdapter.notifyDataSetChanged() + this.findNextActionToEdit() + } + + override fun amountChanged(amount: String?) { + this.model.amountChanged(amount) + } + + override fun amountCleared() { + getRealm().executeTransaction { + this.model.clearAmount() + } + } + override fun cardValueSelected(value: Card.Value) { getRealm().executeTransaction { this.model.cardValueSelected(value) @@ -321,24 +343,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index) } - override fun amountValidated() { - Timber.d(">>> amount validated") - getRealm().executeTransaction { - this.model.amountValidated() - } -// this.handHistoryAdapter.notifyDataSetChanged() - this.findNextActionToEdit() - } - - override fun amountChanged(amount: String?) { - this.model.amountChanged(amount) - } - - override fun amountCleared() { - getRealm().executeTransaction { - this.model.clearAmount() - } - } /*** * Configures the action keyboard: diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt index b1d41a1c..7c55b074 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt @@ -476,7 +476,7 @@ class ActionList(var listener: ActionListListener) : ArrayList() */ override fun getStreetNextCalls(index: Int): List { val streetNextSignificantIndex = getStreetNextSignificantAction(index)?.action?.index - ?: this.lastIndexOfStreet(index) + ?: this.lastIndexOfStreet(index) + 1 // +1 because of "until" return this.filter { it.action.index in ((index + 1) until streetNextSignificantIndex) && (it.action.type?.isCall ?: false) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt index b15a660f..6ce9960c 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt @@ -113,7 +113,8 @@ class ComputedAction(var manager: ActionManager, Action.Type.POST_BB, Action.Type.BET, Action.Type.RAISE, Action.Type.BET_ALLIN, Action.Type.RAISE_ALLIN -> { getStreetNextCalls().forEach { - it.setEffectiveAmount(amount) + it.updateEffectiveAmount() +// it.setEffectiveAmount(amount) } getPlayerNextActions().forEach { it.updateEffectiveAmount() @@ -131,9 +132,6 @@ class ComputedAction(var manager: ActionManager, } } } - -// getStreetLastSignificantAction(this.street, index - 1)?.action?.amount?.let { -// } } } else -> {} diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt index a55d2dc0..194abf39 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt @@ -222,27 +222,29 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra */ private fun addStreetHeader(rowRepresentables: MutableList, street: Street) { - val firstIndexOfStreet = this.sortedActions.firstOrNull { it.street == street }?.action?.index - ?: this.sortedActions.size - - val potSize = this.handHistory.anteSum + this.sortedActions.take(firstIndexOfStreet).sumByDouble { it.action.effectiveAmount } - val potString = if (potSize > 0) potSize.formatted() else "" // "" required otherwise random values come up - - val headerView = CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = street.resId, value = potString) - rowRepresentables.add(headerView) + rowRepresentables.add(StreetHeaderRow(street)) if (street.totalBoardCards > 0) { // create new StreetCardsRow - val boardView = - StreetCardsRow( - street, - this.handHistory - ) + val boardView = StreetCardsRow(street, this.handHistory) rowRepresentables.add(boardView) } } +// private fun refreshStreetPots() { +// this.rowRepresentables.filterIsInstance().forEach { +// it.value = formattedPotSizeForStreet(it.street) +// } +// } + + private fun formattedPotSizeForStreet(street: Street): String { + val firstIndexOfStreet = this.sortedActions.firstOrNull { it.street == street }?.action?.index + ?: this.sortedActions.size + val potSize = this.handHistory.anteSum + this.sortedActions.take(firstIndexOfStreet).sumByDouble { it.action.effectiveAmount } + return if (potSize > 0) potSize.formatted() else "" // "" required otherwise random values come up + } + /*** * Sets the number of players playing the hand * Defines the appropriate positions for this player count @@ -352,7 +354,8 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra } } is ComputedAction -> { - row.setAmount(amount) + this.sortedActions.setAmount(this.actionIndexForSelection, amount) +// this.refreshStreetPots() } is PlayerSetupRow -> { row.setStack(amount) @@ -360,7 +363,6 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra else -> {} } -// this.sortedActions.setAmount(this.actionIndexForSelection, amount) this.currentAmount = null } } catch (e: NumberFormatException) { @@ -565,6 +567,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra } } is PlayerCardsRow -> row.cardHolder?.cards?.formatted(context) + is StreetHeaderRow -> this.formattedPotSizeForStreet(row.street) else -> throw PAIllegalStateException("Unmanaged case with $row, tag = $tag") } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetHeaderRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetHeaderRow.kt new file mode 100644 index 00000000..91f460c6 --- /dev/null +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetHeaderRow.kt @@ -0,0 +1,28 @@ +package net.pokeranalytics.android.ui.modules.handhistory.model + +import android.content.Context +import net.pokeranalytics.android.model.handhistory.Street +import net.pokeranalytics.android.ui.modules.handhistory.HandRowType +import net.pokeranalytics.android.ui.view.RowRepresentable + + +/** + * A class to display a titleResId (and a value) as a Row Representable object + */ +class StreetHeaderRow(var street: Street) : RowRepresentable { + + override fun localizedTitle(context: Context): String { + this.resId?.let { + return context.getString(it) + } + return "LOCALISATION NOT FOUND" + } + + override val viewType: Int = HandRowType.HEADER.identifier + + override val resId: Int? + get() { + return this.street.resId + } + +}