Fixes issues where Next would not change the focus

hh
Laurent 6 years ago
parent e88700b36b
commit 4cd018854c
  1. 14
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/PlayerSetup.kt
  2. 16
      app/src/main/java/net/pokeranalytics/android/ui/adapter/RowRepresentableDataSource.kt
  3. 202
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  4. 9
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  5. 5
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt
  6. 49
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/CardsRow.kt
  7. 45
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt
  8. 95
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  9. 8
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerCardsRow.kt
  10. 45
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRow.kt

@ -28,12 +28,12 @@ open class PlayerSetup : RealmObject(),
*/ */
override var cards: RealmList<Card> = RealmList() override var cards: RealmList<Card> = RealmList()
fun cardValueSelected(value: Card.Value) { // fun cardValueSelected(value: Card.Value) {
//
} // }
//
fun cardSuitSelected(suit: Card.Suit) { // fun cardSuitSelected(suit: Card.Suit) {
//
} // }
} }

@ -133,10 +133,16 @@ interface DisplayableDataSource {
// return "" // return ""
// } // }
/***
* Returns a CharSequence representation of the [row]
*/
fun charSequenceForRow(row: RowRepresentable, context: Context): CharSequence { fun charSequenceForRow(row: RowRepresentable, context: Context): CharSequence {
return charSequenceForRow(row, context, 0) return charSequenceForRow(row, context, 0)
} }
/***
* Returns a CharSequence representation of the [row] and [tag]
*/
fun charSequenceForRow(row: RowRepresentable, context: Context, tag: Int = 0): CharSequence { fun charSequenceForRow(row: RowRepresentable, context: Context, tag: Int = 0): CharSequence {
return "" return ""
} }
@ -169,10 +175,20 @@ interface DisplayableDataSource {
return true return true
} }
/***
* Returns a list of content for the [row], using a specific [clazz]
*/
fun <T : Any> contentForRow(row: RowRepresentable, context: Context, clazz: KClass<T>) : List<T> { fun <T : Any> contentForRow(row: RowRepresentable, context: Context, clazz: KClass<T>) : List<T> {
return listOf() return listOf()
} }
/***
* Returns if the selection of the [row] + [tag] is focusable
*/
fun isFocusable(position: Int, row: RowRepresentable, tag: Int): Boolean {
return true
}
} }
/** /**

@ -8,12 +8,12 @@ import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Button import android.widget.Button
import android.widget.EditText import android.widget.EditText
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.chip.Chip import com.google.android.material.chip.Chip
import kotlinx.android.synthetic.main.row_hand_action.view.* import kotlinx.android.synthetic.main.row_hand_action.view.*
import kotlinx.android.synthetic.main.row_hand_cards.view.* import kotlinx.android.synthetic.main.row_hand_cards.view.*
import kotlinx.android.synthetic.main.row_hand_player_summary.view.*
import kotlinx.android.synthetic.main.row_hhsettings_blinds.view.* import kotlinx.android.synthetic.main.row_hhsettings_blinds.view.*
import kotlinx.android.synthetic.main.row_hhsettings_player_setup.view.* import kotlinx.android.synthetic.main.row_hhsettings_player_setup.view.*
import kotlinx.android.synthetic.main.row_hhsettings_straddle.view.* import kotlinx.android.synthetic.main.row_hhsettings_straddle.view.*
@ -33,7 +33,6 @@ import net.pokeranalytics.android.ui.modules.handhistory.views.PositionAdapter
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.holder.RowViewHolder import net.pokeranalytics.android.ui.view.holder.RowViewHolder
import net.pokeranalytics.android.ui.view.rowrepresentable.ViewIdentifier import net.pokeranalytics.android.ui.view.rowrepresentable.ViewIdentifier
import timber.log.Timber
enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, HandHistoryRow { enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, HandHistoryRow {
@ -54,19 +53,42 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, H
override val identifier: Int override val identifier: Int
get() { return this.ordinal } get() { return this.ordinal }
override fun tagForCompletion(handHistory: HandHistory): Int? { override fun tagsForCompletion(): List<Int> {
return when (this) {
BLINDS -> listOf(0, 1)
else -> listOf()
}
}
override fun isFieldEmpty(tag: Int, handHistory: HandHistory): Boolean {
return when (this) { return when (this) {
BLINDS -> { BLINDS -> {
when { when (tag) {
handHistory.smallBlind == null -> 0 0 -> (handHistory.smallBlind == null)
handHistory.bigBlind == null -> 1 1 -> (handHistory.bigBlind == null)
else -> null else -> false
} }
} }
else -> null else -> false
} }
} }
// override fun tagForCompletion(
// handHistory: HandHistory,
// minTag: Int?
// ): Int? {
// return when (this) {
// BLINDS -> {
// when {
// handHistory.smallBlind == null -> 0
// handHistory.bigBlind == null -> 1
// else -> null
// }
// }
// else -> null
// }
// }
override fun keyboardForTag(tag: Int): HHKeyboard? { override fun keyboardForTag(tag: Int): HHKeyboard? {
return when (this) { return when (this) {
BLINDS -> HHKeyboard.AMOUNT BLINDS -> HHKeyboard.AMOUNT
@ -168,7 +190,7 @@ class HandHistoryAdapter(
abstract inner class RowHandHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder { abstract inner class RowHandHolder(itemView: View) : RecyclerView.ViewHolder(itemView), BindableHolder {
var currentPosition = 0 protected var currentPosition = 0
fun color(isFocused: Boolean) : Int { fun color(isFocused: Boolean) : Int {
val color = if (isFocused) R.color.kaki_medium else R.color.kaki val color = if (isFocused) R.color.kaki_medium else R.color.kaki
@ -194,21 +216,27 @@ class HandHistoryAdapter(
this.configureEditTexts(index..index, position, row, adapter) this.configureEditTexts(index..index, position, row, adapter)
} }
protected fun configureEditTexts(range: IntRange, position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { protected fun configureEditTexts(tagRange: IntRange, position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
range.forEach { tag -> tagRange.forEach { tag ->
val string = adapter.dataSource.charSequenceForRow(row, itemView.context, tag) val editText = itemView.findViewWithTag<EditText>(tag) ?: throw PAIllegalStateException("Edit Text not found for tag: $tag, class: $this")
// Enabled
editText.isEnabled = adapter.dataSource.isEnabled(row, tag)
// Text // Text
val editText = itemView.findViewWithTag<EditText>(tag) ?: throw PAIllegalStateException("Edit Text not found for tag: $tag, class: $this") val string = adapter.dataSource.charSequenceForRow(row, itemView.context, tag)
editText.setText(string) editText.setText(string)
// Focus // Focus
val selected = adapter.dataSource.isSelected(position, row, tag) val selected = adapter.dataSource.isSelected(position, row, tag)
toggleFocus(editText, selected) toggleFocus(editText, selected)
editText.isFocusable = adapter.dataSource.isFocusable(position, row, tag)
editText.isFocusableInTouchMode = adapter.dataSource.isFocusable(position, row, tag)
// Background // Background
editText.setBackgroundColor(color(selected)) editText.setBackgroundColor(color(selected))
} }
} }
@ -223,7 +251,6 @@ class HandHistoryAdapter(
open fun editTextForTag(tag: Int) : EditText { open fun editTextForTag(tag: Int) : EditText {
return itemView.findViewWithTag(tag) return itemView.findViewWithTag(tag)
// throw PAIllegalStateException("Field at tag: $tag requires to return an EditText in order to connect the keyboard to it. Should be overridden by class : $this")
} }
} }
@ -242,21 +269,6 @@ class HandHistoryAdapter(
super.onBind(position, row, adapter) super.onBind(position, row, adapter)
configureEditTexts(0..2, position, row, adapter) configureEditTexts(0..2, position, row, adapter)
// itemView.smallBlindEditText.setText(adapter.dataSource.charSequenceForRow(row, itemView.context, 0))
// itemView.bigBlindEditText.setText(adapter.dataSource.charSequenceForRow(row, itemView.context, 1))
// itemView.anteEditText.setText(adapter.dataSource.charSequenceForRow(row, itemView.context, 2))
// itemView.bbAnteSwitch.isChecked = adapter.dataSource.isSelected(position, row, 0)
//
// val sbSelected = adapter.dataSource.isSelected(position, row, 0)
// toggleFocus(itemView.smallBlindEditText, sbSelected)
//
// val bbSelected = adapter.dataSource.isSelected(position, row, 1)
// toggleFocus(itemView.bigBlindEditText, bbSelected)
//
// val anteSelected = adapter.dataSource.isSelected(position, row, 2)
// toggleFocus(itemView.anteEditText, anteSelected)
} }
} }
@ -337,10 +349,6 @@ class HandHistoryAdapter(
} }
} }
// override fun editTextForTag(tag: Int): EditText {
// return itemView.amountEditText
// }
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
super.onBind(position, row, adapter) super.onBind(position, row, adapter)
@ -353,7 +361,8 @@ class HandHistoryAdapter(
// Action // Action
itemView.findViewById<Button>(R.id.actionButton)?.let { actionButton -> itemView.findViewById<Button>(R.id.actionButton)?.let { actionButton ->
actionButton.isEnabled = computedAction.actionTypeCanBeEdited // actionButton.isEnabled = computedAction.actionTypeCanBeEdited
actionButton.isEnabled = adapter.dataSource.isEnabled(row, actionButton.tag as Int)
val selected = adapter.dataSource.isSelected(position, row, actionButton.tag as Int) val selected = adapter.dataSource.isSelected(position, row, actionButton.tag as Int)
actionButton.backgroundTintList = ColorStateList.valueOf(color(selected)) actionButton.backgroundTintList = ColorStateList.valueOf(color(selected))
@ -368,18 +377,17 @@ class HandHistoryAdapter(
// Amount // Amount
itemView.findViewById<EditText>(R.id.amountEditText)?.let { amountEditText -> itemView.findViewById<EditText>(R.id.amountEditText)?.let { amountEditText ->
amountEditText.isEnabled = computedAction.amountCanBeEdited // amountEditText.isEnabled = computedAction.amountCanBeEdited
val tag = amountEditText.tag as Int val tag = amountEditText.tag as Int
val selected = adapter.dataSource.isSelected(position, row, tag) configureEditTexts(tag, position, row, adapter)
// val selected = adapter.dataSource.isSelected(position, row, tag)
// amountEditText.setBackgroundColor(color(selected)) // amountEditText.setBackgroundColor(color(selected))
// Useful to have the cursor disappear when the keyboard is closed // Useful to have the cursor disappear when the keyboard is closed
amountEditText.isFocusable = selected && computedAction.amountCanBeEdited // amountEditText.isFocusable = selected && computedAction.amountCanBeEdited
amountEditText.isFocusableInTouchMode = selected && computedAction.amountCanBeEdited // amountEditText.isFocusableInTouchMode = selected && computedAction.amountCanBeEdited
configureEditTexts(tag, position, row, adapter)
// amountEditText.setText(computedAction.action.formattedAmount) // amountEditText.setText(computedAction.action.formattedAmount)
// //
@ -388,7 +396,7 @@ class HandHistoryAdapter(
// } else { // } else {
// amountEditText.clearFocus() // amountEditText.clearFocus()
// } // }
Timber.d("Amount at $position is selected: $selected, focusable = ${amountEditText.isFocusable}, isFocusableInTouchMode = ${amountEditText.isFocusableInTouchMode}, hasFocus = ${amountEditText.hasFocus()}, enabled = ${amountEditText.isEnabled}") // Timber.d("Amount at $position is selected: $selected, focusable = ${amountEditText.isFocusable}, isFocusableInTouchMode = ${amountEditText.isFocusableInTouchMode}, hasFocus = ${amountEditText.hasFocus()}, enabled = ${amountEditText.isEnabled}")
} }
@ -430,77 +438,24 @@ class HandHistoryAdapter(
} }
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
super.onBind(position, row, adapter) super.onBind(position, row, adapter)
val streetCardView = row as StreetCardsRow
val street = streetCardView.street
configureEditTexts(Street.FLOP.ordinal..Street.RIVER.ordinal, position, row, adapter) configureEditTexts(Street.FLOP.ordinal..Street.RIVER.ordinal, position, row, adapter)
itemView.findViewById<EditText>(R.id.flopEditText)?.let { flopEditText ->
flopEditText.isFocusable = (street == Street.FLOP)
flopEditText.isVisible = true
// val flop = streetCardView.cardHolder?.cards?.take(3)
// val text = flop?.formatted(itemView.context)
// flopEditText.setText(text)
//
// val selected = adapter.dataSource.isSelected(position, row, Street.FLOP.ordinal)
// toggleFocus(flopEditText, selected)
}
itemView.findViewById<EditText>(R.id.turnEditText)?.let { turnEditText ->
// turnEditText.isVisible = streetCardView.street.ordinal >= Street.TURN.ordinal
turnEditText.isFocusable = (street == Street.TURN)
// if (streetCardView.cardCount > 3) {
// val text = streetCardView.cardAtIndex(3)?.formatted(itemView.context)
// turnEditText.setText(text)
// } else {
// turnEditText.text = null
// }
//
// val selected = adapter.dataSource.isSelected(position, row, Street.TURN.ordinal)
// toggleFocus(turnEditText, selected)
}
itemView.findViewById<EditText>(R.id.riverEditText)?.let { riverEditText ->
// riverEditText.isVisible = streetCardView.street.ordinal >= Street.RIVER.ordinal
riverEditText.isFocusable = (street == Street.RIVER)
// if (streetCardView.cardCount > 4) {
// val text = streetCardView.cardAtIndex(4)?.formatted(itemView.context)
// riverEditText.setText(text)
// } else {
// riverEditText.text = null
// }
//
// val selected = adapter.dataSource.isSelected(position, row, Street.RIVER.ordinal)
// toggleFocus(riverEditText, selected)
}
} }
} }
/** /**
* Display a hand action * Display a hand action
*/ */
inner class RowHandPlayerSummary(itemView: View) : RowHandHolder(itemView) { inner class RowHandPlayerSummary(itemView: View) : RowHandHolder(itemView) {
init { init {
itemView.cardsEditText.tag = PlayerCardsRow.Tag.CARDS.ordinal
// Cards // Cards
itemView.findViewById<EditText>(R.id.cardsEditText)?.let { cardsEditText -> itemView.findViewById<EditText>(R.id.cardsEditText)?.let { cardsEditText ->
cardsEditText.tag = PlayerCardsRow.Tag.CARDS.ordinal
cardsEditText.isFocusableInTouchMode = true cardsEditText.isFocusableInTouchMode = true
cardsEditText.setOnTouchListener { _, event -> cardsEditText.setOnTouchListener { _, event ->
if (event.action == MotionEvent.ACTION_UP) { if (event.action == MotionEvent.ACTION_UP) {
@ -529,23 +484,8 @@ class HandHistoryAdapter(
positionButton.text = playerCardView.position?.value ?: throw PAIllegalStateException("Should not happen") positionButton.text = playerCardView.position?.value ?: throw PAIllegalStateException("Should not happen")
} }
// Amount configureEditTexts(PlayerCardsRow.Tag.CARDS.ordinal, position, row, adapter)
itemView.findViewById<EditText>(R.id.cardsEditText)?.let { cardsEditText ->
val selected = adapter.dataSource.isSelected(position, row, PlayerCardsRow.Tag.CARDS.ordinal)
// Both are required, otherwise requestFocus() fails
cardsEditText.isFocusable = selected
cardsEditText.isFocusableInTouchMode = selected
configureEditTexts(PlayerCardsRow.Tag.CARDS.ordinal, position, row, adapter)
// Timber.d("cardsEditText at $position is selected: $selected, focusable = ${cardsEditText.isFocusable}, isFocusableInTouchMode = ${cardsEditText.isFocusableInTouchMode}, hasFocus = ${cardsEditText.hasFocus()}, enabled = ${cardsEditText.isEnabled}")
// cardsEditText.setBackgroundColor(color(selected))
//
// cardsEditText.setText(playerCardView.cardHolder?.cards?.formatted(itemView.context))
// toggleFocus(cardsEditText, selected)
}
} }
} }
@ -556,7 +496,7 @@ class HandHistoryAdapter(
init { init {
itemView.handEditText.tag = PlayerSetupRow.Tag.CARDS.ordinal itemView.handEditText.tag = PlayerSetupRow.Tag.HAND.ordinal
itemView.stackEditText.tag = PlayerSetupRow.Tag.STACK.ordinal itemView.stackEditText.tag = PlayerSetupRow.Tag.STACK.ordinal
// Position Recycler // Position Recycler
@ -612,44 +552,22 @@ class HandHistoryAdapter(
// Position Button // Position Button
itemView.posButton.text = adapter.dataSource.charSequenceForRow(row, itemView.context, PlayerSetupRow.Tag.POSITION.ordinal) itemView.posButton.text = adapter.dataSource.charSequenceForRow(row, itemView.context, PlayerSetupRow.Tag.POSITION.ordinal)
itemView.posButton.setOnClickListener { // itemView.posButton.setOnClickListener {
setupRow.showPosition() // setupRow.showPosition()
itemView.positionRecyclerView.visibility = View.VISIBLE // itemView.positionRecyclerView.visibility = View.VISIBLE
itemView.posButton.backgroundTintList = ColorStateList.valueOf(color(true)) // itemView.posButton.backgroundTintList = ColorStateList.valueOf(color(true))
} // }
val positionSelected = adapter.dataSource.isSelected(position, row, PlayerSetupRow.Tag.POSITION.ordinal) val positionSelected = adapter.dataSource.isSelected(position, row, PlayerSetupRow.Tag.POSITION.ordinal)
itemView.posButton.backgroundTintList = ColorStateList.valueOf(color(positionSelected)) itemView.posButton.backgroundTintList = ColorStateList.valueOf(color(positionSelected))
// Settings // Settings
itemView.settings_container.visibility = if (state == PlayerSetupRow.State.POSITIONS_ONLY) View.GONE else View.VISIBLE itemView.settings_container.visibility = if (state == PlayerSetupRow.State.POSITIONS_ONLY) View.GONE else View.VISIBLE
configureEditTexts(1..2, position, row, adapter) configureEditTexts(PlayerSetupRow.Tag.HAND.ordinal, position, row, adapter)
configureEditTexts(PlayerSetupRow.Tag.STACK.ordinal, position, row, adapter)
// Hand
// itemView.handEditText.setText(setup.playerSetup?.cards?.formatted(itemView.context))
// val handSelected = adapter.dataSource.isSelected(position, row, PlayerSetupRow.Tag.CARDS.ordinal)
// itemView.handEditText.setBackgroundColor(color(handSelected))
// toggleFocus(itemView.handEditText, handSelected)
//
// // Stack
// itemView.stackEditText.setText(setup.playerSetup?.stack?.formatted())
// val stackSelected = adapter.dataSource.isSelected(position, row, PlayerSetupRow.Tag.STACK.ordinal)
// itemView.stackEditText.setBackgroundColor(color(stackSelected))
// toggleFocus(itemView.stackEditText, stackSelected)
// itemView.handEditText.setText(adapter.dataSource.charSequenceForRow(row, itemView.context, 0))
// itemView.stackEditText.setText(adapter.dataSource.charSequenceForRow(row, itemView.context, 1))
} }
// override fun editTextForTag(tag: Int): EditText {
// return when (tag) {
// PlayerSetupRow.Tag.STACK.ordinal -> itemView.stackEditText
// else -> throw PAIllegalStateException("unmanaged tag $tag")
// }
// }
} }
} }

@ -177,8 +177,11 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
} }
private fun findNextActionToEdit(index: Int? = null) { private fun findNextActionToEdit(index: Int? = null) {
val startIndex = index ?: this.model.currentSelection.index val startIndex = index ?: this.model.currentSelection.index
this.model.findSelectionForEdition(startIndex)?.let { selection -> val minTag = if (index != null) null else this.model.currentSelection.tag
this.model.findSelectionForEdition(startIndex, minTag)?.let { selection ->
this.scrollToPosition(selection.index) this.scrollToPosition(selection.index)
@ -261,7 +264,9 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
val index = this.indexOfRowRepresentable(row) val index = this.indexOfRowRepresentable(row)
this.handHistoryAdapter.notifyItemChanged(index) this.handHistoryAdapter.notifyItemChanged(index)
if (row.tagForCompletion(this.model.handHistory) != null) { // Change the focus only for the row, don't look elsewhere
val anyEmpty = row.tagsForCompletion().any { row.isFieldEmpty(it, this.model.handHistory) }
if (anyEmpty) {
this.findNextActionToEdit(index) this.findNextActionToEdit(index)
} }
} }

@ -456,6 +456,11 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
} }
} }
fun isPlayerAllinWithAmount(position: Int): Boolean {
val computedAction = this.lastOrNull { it.action.position == position && it.action.type?.isAllin == true }
return computedAction?.action?.amount != null
}
/*** /***
* Returns the list of the player next street actions * Returns the list of the player next street actions
*/ */

@ -28,14 +28,25 @@ abstract class CardsRow : HandHistoryRow {
abstract val cardHolder: CardHolder? abstract val cardHolder: CardHolder?
override fun tagForCompletion(handHistory: HandHistory): Int? { // override fun tagsForCompletion(): List<Int> {
return when { //
this.cardCount < cardLimit() ?: MAXCARDS -> 0 // }
this.cardHolder?.cards?.lastOrNull()?.suit == null -> 0
else -> null override fun isFieldEmpty(tag: Int, handHistory: HandHistory): Boolean {
} return this.cardCount == 0
} }
// override fun tagForCompletion(
// handHistory: HandHistory,
// minTag: Int?
// ): Int? {
// return when {
// this.cardCount < cardLimit() ?: MAXCARDS -> 0
// this.cardHolder?.cards?.lastOrNull()?.suit == null -> 0
// else -> null
// }
// }
override fun keyboardForTag(tag: Int): HHKeyboard? { override fun keyboardForTag(tag: Int): HHKeyboard? {
return HHKeyboard.CARD return HHKeyboard.CARD
} }
@ -153,14 +164,28 @@ class StreetCardsRow(var street: Street, var handHistory: HandHistory) : CardsRo
throw PAIllegalStateException("This cannot happen") throw PAIllegalStateException("This cannot happen")
} }
override fun tagForCompletion(handHistory: HandHistory): Int? { override fun tagsForCompletion(): List<Int> {
return if (canAddMoreCards()) { return listOf(Street.FLOP.ordinal, Street.TURN.ordinal, Street.RIVER.ordinal)
this.street.ordinal
} else {
null
}
} }
override fun isFieldEmpty(
tag: Int,
handHistory: HandHistory
): Boolean {
return cardsForTag(tag)?.isEmpty() ?: true
}
// override fun tagForCompletion(
// handHistory: HandHistory,
// minTag: Int?
// ): Int? {
// return if (canAddMoreCards()) {
// this.street.ordinal
// } else {
// null
// }
// }
override fun cardLimit() : Int { override fun cardLimit() : Int {
return this.street.totalBoardCards return this.street.totalBoardCards
} }

@ -7,7 +7,6 @@ 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.view.RowRepresentable
import timber.log.Timber
import kotlin.math.min import kotlin.math.min
interface HandHistoryRow : RowRepresentable { interface HandHistoryRow : RowRepresentable {
@ -15,7 +14,11 @@ interface HandHistoryRow : RowRepresentable {
/*** /***
* Returns the appropriate keyboard to complete the row content * Returns the appropriate keyboard to complete the row content
*/ */
fun tagForCompletion(handHistory: HandHistory): Int? // fun tagForCompletion(handHistory: HandHistory, minTag: Int?): Int?
fun isFieldEmpty(tag: Int, handHistory: HandHistory): Boolean
fun tagsForCompletion(): List<Int>
fun keyboardForTag(tag: Int): HHKeyboard? fun keyboardForTag(tag: Int): HHKeyboard?
@ -172,19 +175,37 @@ class ComputedAction(var manager: ActionManager,
* All ComputedAction should have a type, so we return the action keyboard if the type is null * All ComputedAction should have a type, so we return the action keyboard if the type is null
* If the action has a type, we return the amount keyboard if the action requires one * If the action has a type, we return the amount keyboard if the action requires one
*/ */
override fun tagForCompletion(handHistory: HandHistory): Int? { // override fun tagForCompletion(
Timber.d("index = ${action.index} / type = ${this.action.type} / amount = ${this.action.amount}") // handHistory: HandHistory,
return if (this.action.type != null) { // minTag: Int?
if (this.requiresAmount) { // ): Int? {
Tag.AMOUNT.ordinal // Timber.d("index = ${action.index} / type = ${this.action.type} / amount = ${this.action.amount}")
} else { // return if (this.action.type != null) {
null // if (this.requiresAmount) {
} // Tag.AMOUNT.ordinal
} else { // } else {
Tag.ACTION.ordinal // null
// }
// } else {
// Tag.ACTION.ordinal
// }
// }
override fun isFieldEmpty(
tag: Int,
handHistory: HandHistory
): Boolean {
return when (tag) {
Tag.ACTION.ordinal -> this.action.type == null
Tag.AMOUNT.ordinal -> this.requiresAmount
else -> throw PAIllegalStateException("cannot happen")
} }
} }
override fun tagsForCompletion(): List<Int> {
return listOf(Tag.ACTION.ordinal, Tag.AMOUNT.ordinal)
}
override fun keyboardForTag(tag: Int): HHKeyboard? { override fun keyboardForTag(tag: Int): HHKeyboard? {
return when (tag) { return when (tag) {
Tag.ACTION.ordinal -> HHKeyboard.ACTION Tag.ACTION.ordinal -> HHKeyboard.ACTION

@ -129,7 +129,6 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
*/ */
private var straddlePositions: LinkedHashSet<Position> = linkedSetOf() private var straddlePositions: LinkedHashSet<Position> = linkedSetOf()
/*** /***
* Creates and configures a new HandHistory object using a [handSetup] * Creates and configures a new HandHistory object using a [handSetup]
*/ */
@ -239,12 +238,6 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
} }
// private fun refreshStreetPots() {
// this.rowRepresentables.filterIsInstance<StreetHeaderRow>().forEach {
// it.value = formattedPotSizeForStreet(it.street)
// }
// }
private fun formattedPotSizeForStreet(street: Street): String { private fun formattedPotSizeForStreet(street: Street): String {
val firstIndexOfStreet = this.sortedActions.firstOrNull { it.street == street }?.action?.index val firstIndexOfStreet = this.sortedActions.firstOrNull { it.street == street }?.action?.index
?: this.sortedActions.size ?: this.sortedActions.size
@ -296,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): HHSelection? { fun findSelectionForEdition(index: Int, minTag: Int?): HHSelection? {
val selection = this.getSelectionForFirstEditableRow(index) val selection = this.getSelectionForFirstIncompleteRow(index, minTag)
this.selectionLiveData.value = selection this.selectionLiveData.value = selection
return selection return selection
} }
@ -306,16 +299,35 @@ 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 getSelectionForFirstEditableRow(startIndex: Int): HHSelection? { private fun getSelectionForFirstIncompleteRow(startIndex: Int, minTag: Int?): HHSelection? {
this.rowRepresentables.forEachIndexed { index, rowRepresentable -> this.rowRepresentables.forEachIndexed { index, rowRepresentable ->
if (index >= startIndex && rowRepresentable is HandHistoryRow) { if (rowRepresentable is HandHistoryRow) {
val tag = rowRepresentable.tagForCompletion(this.handHistory)
if (tag != null) { val tags = rowRepresentable.tagsForCompletion()
return HHSelection(index, tag) when {
index == startIndex && minTag != null -> {
tags.firstOrNull {
it > minTag && rowRepresentable.isFieldEmpty(it, this.handHistory)
}?.let {
return HHSelection(index, it)
}
}
index >= startIndex -> {
tags.firstOrNull { rowRepresentable.isFieldEmpty(it, this.handHistory) }?.let { tag ->
return HHSelection(index, tag)
}
}
} }
} }
// if (index >= startIndex && rowRepresentable is HandHistoryRow) {
// val tag = rowRepresentable.tagForCompletion(this.handHistory, minTag)
// if (tag != null) {
// return HHSelection(index, tag)
// }
// }
} }
return null return null
} }
@ -362,7 +374,6 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
} }
is ComputedAction -> { is ComputedAction -> {
this.sortedActions.setAmount(this.actionIndexForSelection, amount) this.sortedActions.setAmount(this.actionIndexForSelection, amount)
// this.refreshStreetPots()
} }
is PlayerSetupRow -> { is PlayerSetupRow -> {
row.setStack(amount) row.setStack(amount)
@ -551,8 +562,52 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
// } // }
} }
fun cardSelectionEnded() { override fun isEnabled(row: RowRepresentable, tag: Int): Boolean {
this.cardSelectionEnded(this.currentSelection.index)
return when (row) {
is PlayerSetupRow -> {
when (tag) {
PlayerSetupRow.Tag.STACK.ordinal -> {
row.playerSetup?.position?.let {
!this.sortedActions.isPlayerAllinWithAmount(it)
} ?: run { true }
}
else -> true
}
}
is ComputedAction -> {
when (tag) {
ComputedAction.Tag.ACTION.ordinal -> row.actionTypeCanBeEdited
ComputedAction.Tag.AMOUNT.ordinal -> row.amountCanBeEdited
else -> true
}
}
else -> true
}
}
override fun isFocusable(position: Int, row: RowRepresentable, tag: Int): Boolean {
return when (row) {
is ComputedAction -> {
val isSelected = this.isSelected(position, row, tag)
when (tag) {
ComputedAction.Tag.AMOUNT.ordinal -> isSelected && row.amountCanBeEdited
else -> throw PAIllegalStateException("Unmanaged tag: $tag")
}
}
is StreetCardsRow -> {
when (tag) {
Street.FLOP.ordinal -> row.street == Street.FLOP
Street.TURN.ordinal -> row.street == Street.TURN
Street.RIVER.ordinal -> row.street == Street.RIVER
else -> throw PAIllegalStateException("Unmanaged tag: $tag")
}
}
is PlayerCardsRow -> this.isSelected(position, row, tag)
else -> true
}
} }
override fun charSequenceForRow(row: RowRepresentable, context: Context, tag: Int): CharSequence { override fun charSequenceForRow(row: RowRepresentable, context: Context, tag: Int): CharSequence {
@ -573,7 +628,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
is PlayerSetupRow -> { is PlayerSetupRow -> {
when (tag) { when (tag) {
PlayerSetupRow.Tag.POSITION.ordinal -> row.position?.value PlayerSetupRow.Tag.POSITION.ordinal -> row.position?.value
PlayerSetupRow.Tag.CARDS.ordinal -> row.cardHolder?.cards?.formatted(context) PlayerSetupRow.Tag.HAND.ordinal -> row.cardHolder?.cards?.formatted(context)
PlayerSetupRow.Tag.STACK.ordinal -> row.playerSetup?.stack?.formatted() PlayerSetupRow.Tag.STACK.ordinal -> row.playerSetup?.stack?.formatted()
else -> throw PAIllegalStateException("Unmanaged case with $row, tag = $tag") else -> throw PAIllegalStateException("Unmanaged case with $row, tag = $tag")
} }
@ -595,6 +650,10 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
return listOf() return listOf()
} }
fun cardSelectionEnded() {
this.cardSelectionEnded(this.currentSelection.index)
}
fun changeStraddleSelection(positions: LinkedHashSet<Position>) { fun changeStraddleSelection(positions: LinkedHashSet<Position>) {
if (positions.isEmpty()) { if (positions.isEmpty()) {

@ -47,4 +47,12 @@ open class PlayerCardsRow(private var playerSetupCreationListener: PlayerSetupCr
this.playerSetupCreationListener?.playerSetupCreated() this.playerSetupCreationListener?.playerSetupCreated()
} }
override fun tagsForCompletion(): List<Int> {
return listOf(Tag.CARDS.ordinal)
}
override fun isFieldEmpty(tag: Int, handHistory: HandHistory): Boolean {
return super.isFieldEmpty(tag, handHistory)
}
} }

@ -24,7 +24,7 @@ class PlayerSetupRow(var hero: Boolean = false,
enum class Tag { enum class Tag {
POSITION, POSITION,
CARDS, HAND,
STACK STACK
} }
@ -65,27 +65,42 @@ class PlayerSetupRow(var hero: Boolean = false,
override val viewType: Int = HandRowType.PLAYER_SETUP.ordinal override val viewType: Int = HandRowType.PLAYER_SETUP.ordinal
override fun tagForCompletion(handHistory: HandHistory): Int? { // override fun tagForCompletion(
// handHistory: HandHistory,
// if the PlayerSetup exists // minTag: Int?
this.playerSetup?.let { // ): Int? {
super.tagForCompletion(handHistory)?.let { tag -> //
return Tag.CARDS.ordinal // // if the PlayerSetup exists
} // this.playerSetup?.let {
// super.tagForCompletion(handHistory, minTag)?.let { tag ->
// stack // return Tag.HAND.ordinal
if (it.stack == null) { // }
return Tag.STACK.ordinal //
} // // stack
// if (it.stack == null) {
// return Tag.STACK.ordinal
// }
// }
//
// return null
// }
override fun isFieldEmpty(tag: Int, handHistory: HandHistory): Boolean {
return when(tag) {
Tag.HAND.ordinal -> super.isFieldEmpty(tag, handHistory)
Tag.STACK.ordinal -> this.playerSetup?.stack == null
else -> false
} }
}
return null override fun tagsForCompletion(): List<Int> {
return if (this.playerSetup != null) listOf(Tag.HAND.ordinal, Tag.STACK.ordinal) else listOf()
} }
override fun keyboardForTag(tag: Int): HHKeyboard? { override fun keyboardForTag(tag: Int): HHKeyboard? {
return when (tag) { return when (tag) {
Tag.POSITION.ordinal -> null Tag.POSITION.ordinal -> null
Tag.CARDS.ordinal -> HHKeyboard.CARD Tag.HAND.ordinal -> HHKeyboard.CARD
Tag.STACK.ordinal -> HHKeyboard.AMOUNT Tag.STACK.ordinal -> HHKeyboard.AMOUNT
else -> throw PAIllegalStateException("unmanaged tag: $tag") else -> throw PAIllegalStateException("unmanaged tag: $tag")
} }

Loading…
Cancel
Save