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 6446cd54..e2490371 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 @@ -338,27 +338,31 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL if (row is HandHistoryRow) { - this.model.selectionLiveData.value?.index?.let { oldIndex -> - refreshRowAtIndexAndCurrent(oldIndex) + if (this.model.hasSelection()) { + this.model.amountValidated() // validates any edited amount before possibly clearing action + refreshRowAtIndexAndCurrent(this.model.currentSelection.index) } - this.model.selectionLiveData.value = HHSelection(position, tag) +// this.model.selectionLiveData.value?.index?.let { oldIndex -> +// refreshRowAtIndexAndCurrent(oldIndex) +// } + + val newSelection = HHSelection(position, tag) + this.model.setSelection(newSelection) + +// this.model.selectionLiveData.value = HHSelection(position, tag) } } override fun onRowDeselected(position: Int, row: RowRepresentable) { - this.model.selectionLiveData.value = null + this.model.clearSelection() this.model.currentAmount = null } override fun onRowValueChanged(value: Any?, row: RowRepresentable) { - if (this.model.selectionLiveData.value != null) { - this.model.amountValidated() // validates any edited amount before possibly clearing action - } - when (row) { HandRowType.COMMENT -> { this.model.handHistory.comment = value as? String @@ -489,7 +493,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL */ override fun closeKeyboard() { val currentIndex = this.model.currentSelection.index - this.model.selectionLiveData.value = null + this.model.clearSelection() this.handHistoryAdapter.notifyItemChanged(currentIndex) this.animateKeyboard(false) // this.hideKeyboard() @@ -530,10 +534,16 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL * Refreshes the selected row */ private fun refreshSelectedRow() { - this.model.selectionLiveData.value?.index?.let { - Timber.d("refreshes row at index = $it") - this.handHistoryAdapter.notifyItemChanged(it) + + if (this.model.hasSelection()) { + val index = this.model.currentSelection.index + this.handHistoryAdapter.notifyItemChanged(index) } + +// this.model.selectionLiveData.value?.index?.let { +// Timber.d("refreshes row at index = $it") +// this.handHistoryAdapter.notifyItemChanged(it) +// } } /*** @@ -587,14 +597,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL lp.guideEnd = 0 } - private fun showNextHand() { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - - private fun showPreviousHand() { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } - /*** * Deletes the current hand * Finishes the activity to go back 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 8557d49e..d58c6dbf 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 @@ -5,7 +5,6 @@ import net.pokeranalytics.android.model.handhistory.Position import net.pokeranalytics.android.model.handhistory.Street import net.pokeranalytics.android.model.realm.handhistory.Action import net.pokeranalytics.android.model.realm.handhistory.HandHistory -import timber.log.Timber interface ActionManager { fun selectAction(index: Int, actionType: Action.Type) @@ -428,9 +427,9 @@ class ActionList(var listener: ActionListListener) : ArrayList() val currentStreet = this[index].street + val activePositions = activePositions(index) getStreetLastSignificantAction(currentStreet, index)?.let { significantAction -> - val activePositions = activePositions(index) val activePlayerCount = activePositions.size // don't move this line because of removes // Blinds must act @@ -467,7 +466,7 @@ class ActionList(var listener: ActionListListener) : ArrayList() .all { it.action.type?.isPassive ?: false } if (allPassive) { - return if (currentStreet != Street.RIVER) { + return if (activePositions.size >= 2 && currentStreet != Street.RIVER) { currentStreet.next } else { Street.SUMMARY 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 df719fa4..dfcc8c70 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 @@ -85,10 +85,8 @@ class ComputedAction(var manager: ActionManager, val typeChange = (this.action.type != type && this.action.type != null) this.action.type = type - if (typeChange) { - this.action.amount = null - this.action.effectiveAmount = 0.0 - } + this.action.amount = null + this.action.effectiveAmount = 0.0 // define action amounts if possible when (type) { @@ -123,8 +121,12 @@ class ComputedAction(var manager: ActionManager, */ fun setBetAmount(amount: Double) { - if (amount <= 0) { - return + if (this.action.type == null || this.action.type?.isSignificant == false) { + throw PAIllegalStateException("Attempts to set amount on invalid action. Type = ${this.action.type}, amount = $amount") + } + + if (amount < 0.0) { + throw PAIllegalStateException("Attempts to set a negative amount: $amount") } val minimumAmount = this.manager.minimumBetAmount(this.action.index) 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 0b0dd04f..3f274dd0 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 @@ -28,8 +28,6 @@ import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable import net.pokeranalytics.android.util.extensions.formatted import timber.log.Timber -import java.util.* -import kotlin.collections.LinkedHashSet import kotlin.coroutines.CoroutineContext import kotlin.reflect.KClass @@ -87,6 +85,19 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra * The user selection's live data inside the editor */ var selectionLiveData: MutableLiveData = MutableLiveData() + private set + + fun setSelection(selection: HHSelection) { + this.selectionLiveData.value = selection + } + + fun clearSelection() { + this.selectionLiveData.value = null + } + + fun hasSelection(): Boolean { + return this.selectionLiveData.value != null + } /*** * The current selection @@ -500,7 +511,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra */ fun amountValidated() { - if (this.currentAmount?.isEmpty() == true) { + if (this.currentAmount == null || this.currentAmount?.isEmpty() == true) { return } @@ -1021,8 +1032,4 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra this.createRowRepresentation() } - fun clearSelection() { - this.selectionLiveData.value = null - } - } \ No newline at end of file