From 716586782ec57b84ea8e19e0aa1b1b7f2d91f4dd Mon Sep 17 00:00:00 2001 From: Laurent Date: Thu, 23 Jan 2020 18:17:19 +0100 Subject: [PATCH] Adds row refresh of automatically set actions --- .../android/model/handhistory/HHBuilder.kt | 10 ++++++---- .../android/model/realm/handhistory/Action.kt | 2 +- .../ui/modules/handhistory/HandHistoryFragment.kt | 6 ++++-- .../ui/modules/handhistory/HandHistoryViewModel.kt | 6 ++++-- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt b/app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt index e71fabf0..809b7e5c 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt @@ -5,8 +5,8 @@ import net.pokeranalytics.android.exceptions.PAIllegalStateException import net.pokeranalytics.android.model.realm.handhistory.Action import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.ui.modules.handhistory.HandRowType -import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.modules.handhistory.views.StreetCardHeader +import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable import timber.log.Timber import java.util.* @@ -146,8 +146,9 @@ class HHBuilder { * If the user changes the current action, * for convenience we remove all the following actions to avoid managing complex cases * Also calculates the player effective amounts in proper cases + * Returns the list of modified action indexes that are not the action at [index] */ - fun selectAction(index: Int, actionType: Action.Type) : Boolean { + fun selectAction(index: Int, actionType: Action.Type) : List { Timber.d(">>> Sets $actionType at index: $index") @@ -160,8 +161,9 @@ class HHBuilder { dropNextActionsIfNecessary(index) // Automatically sets action for the previous empty actions + val modifiedActions = mutableListOf() getPreviousEmptyActions(index).forEach { - + modifiedActions.add(it) val lastSignificant = getLastSignificantAction(index) if (lastSignificant != null) { it.action.type = Action.Type.FOLD @@ -188,7 +190,7 @@ class HHBuilder { else -> {} } - return computedAction.requiresAmount + return modifiedActions.map { this.currentRowRepresentables.indexOf(it) } } private fun getPreviousEmptyActions(index: Int) : List { diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt index 301efc51..00407157 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt @@ -28,7 +28,7 @@ open class Action : RealmObject() { val isSignificant: Boolean get() { return when (this) { - POST_BB, STRADDLE, BET, RAISE, BET_ALLIN, RAISE_ALLIN -> true + POST_SB, POST_BB, STRADDLE, BET, RAISE, BET_ALLIN, RAISE_ALLIN -> true UNDEFINED_ALLIN -> throw PAIllegalStateException("Can't ask for UNDEFINED_ALLIN") else -> false } 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 20803221..43398bf3 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 @@ -246,8 +246,10 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr override fun actionSelected(action: Action.Type) { Timber.d(">>> action $action selected") - this.model.actionSelected(action) -// this.handHistoryAdapter.notifyDataSetChanged() + val indexesToRefresh = this.model.actionSelected(action) + + indexesToRefresh.forEach { this.handHistoryAdapter.notifyItemChanged(it) } + this.findNextActionToEdit() } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryViewModel.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryViewModel.kt index 8c4237fb..bcd43a15 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryViewModel.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryViewModel.kt @@ -49,8 +49,10 @@ class HandHistoryViewModel : ViewModel() { } ?: throw PAIllegalStateException("No selection") } - fun actionSelected(action: Action.Type) { - builder.value?.selectAction(this.actionIndexForSelection, action) + fun actionSelected(action: Action.Type) : List { + builder.value?.let { + return it.selectAction(this.actionIndexForSelection, action) + } ?: throw PAIllegalStateException("Builder not found") } fun amountValidated() {