Fixes autoselection issue

hh
Laurent 6 years ago
parent 4cd018854c
commit 4b2638a1dc
  1. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  2. 10
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  3. 6
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/CardsRow.kt
  4. 19
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt
  5. 17
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryRow.kt
  6. 12
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  7. 4
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerCardsRow.kt
  8. 4
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRow.kt

@ -60,7 +60,7 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, H
} }
} }
override fun isFieldEmpty(tag: Int, handHistory: HandHistory): Boolean { override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean {
return when (this) { return when (this) {
BLINDS -> { BLINDS -> {
when (tag) { when (tag) {

@ -176,12 +176,12 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.model.isEdited = false this.model.isEdited = false
} }
private fun findNextActionToEdit(index: Int? = null) { private fun findNextActionToEdit(index: Int? = null, userInitiated: Boolean = false) {
val startIndex = index ?: this.model.currentSelection.index val startIndex = index ?: this.model.currentSelection.index
val minTag = if (index != null) null else this.model.currentSelection.tag val minTag = if (index != null) null else this.model.currentSelection.tag
this.model.findSelectionForEdition(startIndex, minTag)?.let { selection -> this.model.findSelectionForEdition(startIndex, minTag, userInitiated)?.let { selection ->
this.scrollToPosition(selection.index) this.scrollToPosition(selection.index)
@ -265,7 +265,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.handHistoryAdapter.notifyItemChanged(index) this.handHistoryAdapter.notifyItemChanged(index)
// Change the focus only for the row, don't look elsewhere // Change the focus only for the row, don't look elsewhere
val anyEmpty = row.tagsForCompletion().any { row.isFieldEmpty(it, this.model.handHistory) } val anyEmpty = row.tagsForCompletion().any { row.isFieldNeedsInput(it, this.model.handHistory) }
if (anyEmpty) { if (anyEmpty) {
this.findNextActionToEdit(index) this.findNextActionToEdit(index)
} }
@ -300,7 +300,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.model.amountValidated() this.model.amountValidated()
} }
// this.handHistoryAdapter.notifyDataSetChanged() // this.handHistoryAdapter.notifyDataSetChanged()
this.findNextActionToEdit() this.findNextActionToEdit(userInitiated = true)
} }
override fun amountChanged(amount: String?) { override fun amountChanged(amount: String?) {
@ -338,7 +338,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
override fun cardSelectionEnded() { override fun cardSelectionEnded() {
this.model.cardSelectionEnded() this.model.cardSelectionEnded()
this.findNextActionToEdit() this.findNextActionToEdit(userInitiated = true)
} }
override fun cardBackSpaceSelected() { override fun cardBackSpaceSelected() {

@ -32,8 +32,8 @@ abstract class CardsRow : HandHistoryRow {
// //
// } // }
override fun isFieldEmpty(tag: Int, handHistory: HandHistory): Boolean { override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean {
return this.cardCount == 0 return this.canAddMoreCards()
} }
// override fun tagForCompletion( // override fun tagForCompletion(
@ -168,7 +168,7 @@ class StreetCardsRow(var street: Street, var handHistory: HandHistory) : CardsRo
return listOf(Street.FLOP.ordinal, Street.TURN.ordinal, Street.RIVER.ordinal) return listOf(Street.FLOP.ordinal, Street.TURN.ordinal, Street.RIVER.ordinal)
} }
override fun isFieldEmpty( override fun isFieldNeedsInput(
tag: Int, tag: Int,
handHistory: HandHistory handHistory: HandHistory
): Boolean { ): Boolean {

@ -6,25 +6,8 @@ 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 net.pokeranalytics.android.ui.modules.handhistory.HandRowType import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
import net.pokeranalytics.android.ui.view.RowRepresentable
import kotlin.math.min import kotlin.math.min
interface HandHistoryRow : RowRepresentable {
/***
* Returns the appropriate keyboard to complete the row content
*/
// fun tagForCompletion(handHistory: HandHistory, minTag: Int?): Int?
fun isFieldEmpty(tag: Int, handHistory: HandHistory): Boolean
fun tagsForCompletion(): List<Int>
fun keyboardForTag(tag: Int): HHKeyboard?
fun amountForTag(handHistory: HandHistory, tag: Int): Double? { return null }
}
/*** /***
* ComputedAction is a convenience class which main role is to represent a hand history Action * ComputedAction is a convenience class which main role is to represent a hand history Action
@ -191,7 +174,7 @@ class ComputedAction(var manager: ActionManager,
// } // }
// } // }
override fun isFieldEmpty( override fun isFieldNeedsInput(
tag: Int, tag: Int,
handHistory: HandHistory handHistory: HandHistory
): Boolean { ): Boolean {

@ -0,0 +1,17 @@
package net.pokeranalytics.android.ui.modules.handhistory.model
import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.ui.view.RowRepresentable
interface HandHistoryRow : RowRepresentable {
fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean
fun tagsForCompletion(): List<Int>
fun keyboardForTag(tag: Int): HHKeyboard?
fun amountForTag(handHistory: HandHistory, tag: Int): Double? { return null }
}

@ -289,8 +289,8 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
/*** /***
* Looks for a row and a keyboard, i.e. a HHSelection, suitable for edition * Looks for a row and a keyboard, i.e. a HHSelection, suitable for edition
*/ */
fun findSelectionForEdition(index: Int, minTag: Int?): HHSelection? { fun findSelectionForEdition(index: Int, minTag: Int?, userInitiated: Boolean): HHSelection? {
val selection = this.getSelectionForFirstIncompleteRow(index, minTag) val selection = this.getSelectionForFirstIncompleteRow(index, minTag, userInitiated)
this.selectionLiveData.value = selection this.selectionLiveData.value = selection
return selection return selection
} }
@ -299,7 +299,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
* Finds the index of the first incomplete action, if existing * Finds the index of the first incomplete action, if existing
* If the same selection is the same than current, pass to the next row * If the same selection is the same than current, pass to the next row
*/ */
private fun getSelectionForFirstIncompleteRow(startIndex: Int, minTag: Int?): HHSelection? { private fun getSelectionForFirstIncompleteRow(startIndex: Int, minTag: Int?, userInitiated: Boolean): HHSelection? {
this.rowRepresentables.forEachIndexed { index, rowRepresentable -> this.rowRepresentables.forEachIndexed { index, rowRepresentable ->
@ -307,15 +307,15 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
val tags = rowRepresentable.tagsForCompletion() val tags = rowRepresentable.tagsForCompletion()
when { when {
index == startIndex && minTag != null -> { userInitiated && minTag != null && index == startIndex -> {
tags.firstOrNull { tags.firstOrNull {
it > minTag && rowRepresentable.isFieldEmpty(it, this.handHistory) it > minTag && rowRepresentable.isFieldNeedsInput(it, this.handHistory)
}?.let { }?.let {
return HHSelection(index, it) return HHSelection(index, it)
} }
} }
index >= startIndex -> { index >= startIndex -> {
tags.firstOrNull { rowRepresentable.isFieldEmpty(it, this.handHistory) }?.let { tag -> tags.firstOrNull { rowRepresentable.isFieldNeedsInput(it, this.handHistory) }?.let { tag ->
return HHSelection(index, tag) return HHSelection(index, tag)
} }
} }

@ -51,8 +51,4 @@ open class PlayerCardsRow(private var playerSetupCreationListener: PlayerSetupCr
return listOf(Tag.CARDS.ordinal) return listOf(Tag.CARDS.ordinal)
} }
override fun isFieldEmpty(tag: Int, handHistory: HandHistory): Boolean {
return super.isFieldEmpty(tag, handHistory)
}
} }

@ -85,9 +85,9 @@ class PlayerSetupRow(var hero: Boolean = false,
// return null // return null
// } // }
override fun isFieldEmpty(tag: Int, handHistory: HandHistory): Boolean { override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean {
return when(tag) { return when(tag) {
Tag.HAND.ordinal -> super.isFieldEmpty(tag, handHistory) Tag.HAND.ordinal -> super.isFieldNeedsInput(tag, handHistory)
Tag.STACK.ordinal -> this.playerSetup?.stack == null Tag.STACK.ordinal -> this.playerSetup?.stack == null
else -> false else -> false
} }

Loading…
Cancel
Save