From 20f8151394cd568a1439849b49035cff657ee24f Mon Sep 17 00:00:00 2001 From: Laurent Date: Thu, 23 Jan 2020 18:30:33 +0100 Subject: [PATCH] Manages table refresh when actions drop occur --- .../android/model/handhistory/HHBuilder.kt | 37 ++++++++++--------- .../handhistory/HandHistoryFragment.kt | 6 ++- .../handhistory/HandHistoryViewModel.kt | 2 +- 3 files changed, 26 insertions(+), 19 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 809b7e5c..6d8c17b4 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 @@ -148,7 +148,7 @@ class HHBuilder { * 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) : List { + fun selectAction(index: Int, actionType: Action.Type) : List? { Timber.d(">>> Sets $actionType at index: $index") @@ -158,20 +158,6 @@ class HHBuilder { computedAction.action.amount = null } - 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 - } else { - it.action.type = Action.Type.CHECK - } - } - when (actionType) { Action.Type.CALL -> { val significantAction = getLastSignificantAction(index) @@ -190,6 +176,21 @@ class HHBuilder { else -> {} } + val dropedIndex = dropNextActionsIfNecessary(index) // TODO returns the value + + // 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 + } else { + it.action.type = Action.Type.CHECK + } + } + + if (dropedIndex != null) return null return modifiedActions.map { this.currentRowRepresentables.indexOf(it) } } @@ -199,12 +200,14 @@ class HHBuilder { } /*** - * Removes the actions, if necessary (those not automatically created), following an action change + * Removes the actions, not the automatically created ones, + * following an action change. * We want drop all non-auto added rows after the index */ - private fun dropNextActionsIfNecessary(index: Int) { + private fun dropNextActionsIfNecessary(index: Int) : Int? { // val dropIndex = index + 1 // TODO determine dropIndex // this.sortedActions = this.sortedActions.take(dropIndex) + return null } private fun remainingActivePlayerCountAtStreetStart(index: Int) : Int { 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 43398bf3..7a57fcca 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 @@ -248,7 +248,11 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr Timber.d(">>> action $action selected") val indexesToRefresh = this.model.actionSelected(action) - indexesToRefresh.forEach { this.handHistoryAdapter.notifyItemChanged(it) } + indexesToRefresh?.let { indexes -> + indexes.forEach { this.handHistoryAdapter.notifyItemChanged(it) } + } ?: run { + this.handHistoryAdapter.notifyDataSetChanged() + } 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 bcd43a15..4ce62c87 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,7 +49,7 @@ class HandHistoryViewModel : ViewModel() { } ?: throw PAIllegalStateException("No selection") } - fun actionSelected(action: Action.Type) : List { + fun actionSelected(action: Action.Type) : List? { builder.value?.let { return it.selectAction(this.actionIndexForSelection, action) } ?: throw PAIllegalStateException("Builder not found")