Manages table refresh when actions drop occur

hh
Laurent 6 years ago
parent 716586782e
commit 20f8151394
  1. 37
      app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt
  2. 6
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryViewModel.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<Int> {
fun selectAction(index: Int, actionType: Action.Type) : List<Int>? {
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<ComputedAction>()
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<ComputedAction>()
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 {

@ -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()
}

@ -49,7 +49,7 @@ class HandHistoryViewModel : ViewModel() {
} ?: throw PAIllegalStateException("No selection")
}
fun actionSelected(action: Action.Type) : List<Int> {
fun actionSelected(action: Action.Type) : List<Int>? {
builder.value?.let {
return it.selectAction(this.actionIndexForSelection, action)
} ?: throw PAIllegalStateException("Builder not found")

Loading…
Cancel
Save