Adds row refresh of automatically set actions

hh
Laurent 6 years ago
parent 3287bdff0c
commit 716586782e
  1. 10
      app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt
  2. 2
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt
  3. 6
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  4. 6
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryViewModel.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.Action
import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType 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.modules.handhistory.views.StreetCardHeader
import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable
import timber.log.Timber import timber.log.Timber
import java.util.* import java.util.*
@ -146,8 +146,9 @@ class HHBuilder {
* If the user changes the current action, * If the user changes the current action,
* for convenience we remove all the following actions to avoid managing complex cases * for convenience we remove all the following actions to avoid managing complex cases
* Also calculates the player effective amounts in proper 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<Int> {
Timber.d(">>> Sets $actionType at index: $index") Timber.d(">>> Sets $actionType at index: $index")
@ -160,8 +161,9 @@ class HHBuilder {
dropNextActionsIfNecessary(index) dropNextActionsIfNecessary(index)
// Automatically sets action for the previous empty actions // Automatically sets action for the previous empty actions
val modifiedActions = mutableListOf<ComputedAction>()
getPreviousEmptyActions(index).forEach { getPreviousEmptyActions(index).forEach {
modifiedActions.add(it)
val lastSignificant = getLastSignificantAction(index) val lastSignificant = getLastSignificantAction(index)
if (lastSignificant != null) { if (lastSignificant != null) {
it.action.type = Action.Type.FOLD it.action.type = Action.Type.FOLD
@ -188,7 +190,7 @@ class HHBuilder {
else -> {} else -> {}
} }
return computedAction.requiresAmount return modifiedActions.map { this.currentRowRepresentables.indexOf(it) }
} }
private fun getPreviousEmptyActions(index: Int) : List<ComputedAction> { private fun getPreviousEmptyActions(index: Int) : List<ComputedAction> {

@ -28,7 +28,7 @@ open class Action : RealmObject() {
val isSignificant: Boolean val isSignificant: Boolean
get() { get() {
return when (this) { 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") UNDEFINED_ALLIN -> throw PAIllegalStateException("Can't ask for UNDEFINED_ALLIN")
else -> false else -> false
} }

@ -246,8 +246,10 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDataSource, RowRepr
override fun actionSelected(action: Action.Type) { override fun actionSelected(action: Action.Type) {
Timber.d(">>> action $action selected") Timber.d(">>> action $action selected")
this.model.actionSelected(action) val indexesToRefresh = this.model.actionSelected(action)
// this.handHistoryAdapter.notifyDataSetChanged()
indexesToRefresh.forEach { this.handHistoryAdapter.notifyItemChanged(it) }
this.findNextActionToEdit() this.findNextActionToEdit()
} }

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

Loading…
Cancel
Save