Fixes #7 : amounts auto validation when selecting somewhere else

hh
Laurent 6 years ago
parent 4d53fd1863
commit 943f05126d
  1. 42
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  2. 5
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt
  3. 14
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt
  4. 21
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt

@ -338,27 +338,31 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
if (row is HandHistoryRow) { if (row is HandHistoryRow) {
this.model.selectionLiveData.value?.index?.let { oldIndex -> if (this.model.hasSelection()) {
refreshRowAtIndexAndCurrent(oldIndex) 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) { override fun onRowDeselected(position: Int, row: RowRepresentable) {
this.model.selectionLiveData.value = null this.model.clearSelection()
this.model.currentAmount = null this.model.currentAmount = null
} }
override fun onRowValueChanged(value: Any?, row: RowRepresentable) { 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) { when (row) {
HandRowType.COMMENT -> { HandRowType.COMMENT -> {
this.model.handHistory.comment = value as? String this.model.handHistory.comment = value as? String
@ -489,7 +493,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
*/ */
override fun closeKeyboard() { override fun closeKeyboard() {
val currentIndex = this.model.currentSelection.index val currentIndex = this.model.currentSelection.index
this.model.selectionLiveData.value = null this.model.clearSelection()
this.handHistoryAdapter.notifyItemChanged(currentIndex) this.handHistoryAdapter.notifyItemChanged(currentIndex)
this.animateKeyboard(false) this.animateKeyboard(false)
// this.hideKeyboard() // this.hideKeyboard()
@ -530,10 +534,16 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
* Refreshes the selected row * Refreshes the selected row
*/ */
private fun refreshSelectedRow() { private fun refreshSelectedRow() {
this.model.selectionLiveData.value?.index?.let {
Timber.d("refreshes row at index = $it") if (this.model.hasSelection()) {
this.handHistoryAdapter.notifyItemChanged(it) 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 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 * Deletes the current hand
* Finishes the activity to go back * Finishes the activity to go back

@ -5,7 +5,6 @@ import net.pokeranalytics.android.model.handhistory.Position
import net.pokeranalytics.android.model.handhistory.Street import net.pokeranalytics.android.model.handhistory.Street
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 timber.log.Timber
interface ActionManager { interface ActionManager {
fun selectAction(index: Int, actionType: Action.Type) fun selectAction(index: Int, actionType: Action.Type)
@ -428,9 +427,9 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
val currentStreet = this[index].street val currentStreet = this[index].street
val activePositions = activePositions(index)
getStreetLastSignificantAction(currentStreet, index)?.let { significantAction -> getStreetLastSignificantAction(currentStreet, index)?.let { significantAction ->
val activePositions = activePositions(index)
val activePlayerCount = activePositions.size // don't move this line because of removes val activePlayerCount = activePositions.size // don't move this line because of removes
// Blinds must act // Blinds must act
@ -467,7 +466,7 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
.all { it.action.type?.isPassive ?: false } .all { it.action.type?.isPassive ?: false }
if (allPassive) { if (allPassive) {
return if (currentStreet != Street.RIVER) { return if (activePositions.size >= 2 && currentStreet != Street.RIVER) {
currentStreet.next currentStreet.next
} else { } else {
Street.SUMMARY Street.SUMMARY

@ -85,10 +85,8 @@ class ComputedAction(var manager: ActionManager,
val typeChange = (this.action.type != type && this.action.type != null) val typeChange = (this.action.type != type && this.action.type != null)
this.action.type = type this.action.type = type
if (typeChange) { this.action.amount = null
this.action.amount = null this.action.effectiveAmount = 0.0
this.action.effectiveAmount = 0.0
}
// define action amounts if possible // define action amounts if possible
when (type) { when (type) {
@ -123,8 +121,12 @@ class ComputedAction(var manager: ActionManager,
*/ */
fun setBetAmount(amount: Double) { fun setBetAmount(amount: Double) {
if (amount <= 0) { if (this.action.type == null || this.action.type?.isSignificant == false) {
return 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) val minimumAmount = this.manager.minimumBetAmount(this.action.index)

@ -28,8 +28,6 @@ import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable
import net.pokeranalytics.android.util.extensions.formatted import net.pokeranalytics.android.util.extensions.formatted
import timber.log.Timber import timber.log.Timber
import java.util.*
import kotlin.collections.LinkedHashSet
import kotlin.coroutines.CoroutineContext import kotlin.coroutines.CoroutineContext
import kotlin.reflect.KClass import kotlin.reflect.KClass
@ -87,6 +85,19 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
* The user selection's live data inside the editor * The user selection's live data inside the editor
*/ */
var selectionLiveData: MutableLiveData<HHSelection> = MutableLiveData() var selectionLiveData: MutableLiveData<HHSelection> = 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 * The current selection
@ -500,7 +511,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
*/ */
fun amountValidated() { fun amountValidated() {
if (this.currentAmount?.isEmpty() == true) { if (this.currentAmount == null || this.currentAmount?.isEmpty() == true) {
return return
} }
@ -1021,8 +1032,4 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
this.createRowRepresentation() this.createRowRepresentation()
} }
fun clearSelection() {
this.selectionLiveData.value = null
}
} }
Loading…
Cancel
Save