From 3da68955160b84bc38867231aa7b1d5910d14d87 Mon Sep 17 00:00:00 2001 From: Laurent Date: Mon, 13 Apr 2020 15:06:02 +0200 Subject: [PATCH] Fixes #20 --- .../ui/modules/handhistory/model/ActionList.kt | 14 ++++++++++---- .../modules/handhistory/model/ComputedAction.kt | 4 ++++ .../handhistory/model/HandHistoryViewModel.kt | 16 ++++++++-------- 3 files changed, 22 insertions(+), 12 deletions(-) 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 d58c6dbf..9dfdf708 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 @@ -128,12 +128,14 @@ class ActionList(var listener: ActionListListener) : ArrayList() } Action.Type.CALL -> { - getStreetLastSignificantAction(computedAction.street, index - 1)?.action?.amount?.let { betAmount -> + getStreetLastSignificantAction(computedAction.street, index - 1)?.let { + val betAmount = it.action.amount ?: 0.0 val remainingStack = computedAction.stackBeforeActing if (remainingStack != null && remainingStack < betAmount) { type = Action.Type.CALL_ALLIN } - } ?: throw PAIllegalStateException("Can't happen") + } ?: throw PAIllegalStateException("Can't call without a significant action") + } else -> {} } @@ -150,9 +152,13 @@ class ActionList(var listener: ActionListListener) : ArrayList() /*** * Sets the amount for the action at the provided [index] */ - fun setAmount(index: Int, amount: Double) { + fun setAmount(index: Int, amount: Double?) { val computedAction = this[index] - computedAction.setBetAmount(amount) + amount?.let { + computedAction.setBetAmount(amount) + } ?: run { + computedAction.clearAmount() + } this.updateRemainingStacksForPositions(listOf(computedAction.action.position)) } 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 dfcc8c70..64540b3d 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 @@ -263,6 +263,10 @@ class ComputedAction(var manager: ActionManager, return this.manager.getPlayerNextStreetActions(this.action.index) } + fun clearAmount() { + this.action.amount = null + } + /*** * Returns whether the action type can be edited * SB / BB cannot have their action type edited 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 f0f29939..eaa970f7 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 @@ -122,6 +122,10 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra * The current amount edited by the user */ private var currentAmount: String? = null + set(value) { + field = value + Timber.d("currentAmount = $value") + } /*** * The action index @@ -512,9 +516,9 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra */ fun amountValidated() { - if (this.currentAmount == null || this.currentAmount?.isEmpty() == true) { - return - } +// if (this.currentAmount == null || this.currentAmount?.isEmpty() == true) { +// return +// } val amount = try { this.currentAmount?.toDouble() @@ -525,11 +529,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra when (val row = this.rowRepresentables[this.currentSelection.index]) { is ComputedAction -> { - amount?.let { - this.sortedActions.setAmount(this.actionIndexForSelection, amount) - } ?: run { - this.sortedActions.setAmount(this.actionIndexForSelection, this.handHistory.bigBlind ?: 0.0) - } + this.sortedActions.setAmount(this.actionIndexForSelection, amount) } is PlayerSetupRow -> { row.setStack(amount)