From 4b2638a1dc98faa20db785eb58a9685053f8514a Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 14 Feb 2020 10:35:39 +0100 Subject: [PATCH] Fixes autoselection issue --- .../modules/handhistory/HandHistoryAdapter.kt | 2 +- .../handhistory/HandHistoryFragment.kt | 10 +++++----- .../ui/modules/handhistory/model/CardsRow.kt | 6 +++--- .../handhistory/model/ComputedAction.kt | 19 +------------------ .../handhistory/model/HandHistoryRow.kt | 17 +++++++++++++++++ .../handhistory/model/HandHistoryViewModel.kt | 12 ++++++------ .../handhistory/model/PlayerCardsRow.kt | 4 ---- .../handhistory/model/PlayerSetupRow.kt | 4 ++-- 8 files changed, 35 insertions(+), 39 deletions(-) create mode 100644 app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryRow.kt diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt index 2d4c1a32..81d248a6 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.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) { BLINDS -> { when (tag) { 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 e94477f7..447f2072 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 @@ -176,12 +176,12 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL 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 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) @@ -265,7 +265,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL this.handHistoryAdapter.notifyItemChanged(index) // 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) { this.findNextActionToEdit(index) } @@ -300,7 +300,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL this.model.amountValidated() } // this.handHistoryAdapter.notifyDataSetChanged() - this.findNextActionToEdit() + this.findNextActionToEdit(userInitiated = true) } override fun amountChanged(amount: String?) { @@ -338,7 +338,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL override fun cardSelectionEnded() { this.model.cardSelectionEnded() - this.findNextActionToEdit() + this.findNextActionToEdit(userInitiated = true) } override fun cardBackSpaceSelected() { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/CardsRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/CardsRow.kt index a8ec768b..3fb39c62 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/CardsRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/CardsRow.kt @@ -32,8 +32,8 @@ abstract class CardsRow : HandHistoryRow { // // } - override fun isFieldEmpty(tag: Int, handHistory: HandHistory): Boolean { - return this.cardCount == 0 + override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean { + return this.canAddMoreCards() } // 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) } - override fun isFieldEmpty( + override fun isFieldNeedsInput( tag: Int, handHistory: HandHistory ): Boolean { 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 14555af2..67d94554 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 @@ -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.HandHistory import net.pokeranalytics.android.ui.modules.handhistory.HandRowType -import net.pokeranalytics.android.ui.view.RowRepresentable 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 - - 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 @@ -191,7 +174,7 @@ class ComputedAction(var manager: ActionManager, // } // } - override fun isFieldEmpty( + override fun isFieldNeedsInput( tag: Int, handHistory: HandHistory ): Boolean { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryRow.kt new file mode 100644 index 00000000..fafb5b07 --- /dev/null +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryRow.kt @@ -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 + + fun keyboardForTag(tag: Int): HHKeyboard? + + fun amountForTag(handHistory: HandHistory, tag: Int): Double? { return null } + +} \ No newline at end of file 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 fd302789..bc939164 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 @@ -289,8 +289,8 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra /*** * Looks for a row and a keyboard, i.e. a HHSelection, suitable for edition */ - fun findSelectionForEdition(index: Int, minTag: Int?): HHSelection? { - val selection = this.getSelectionForFirstIncompleteRow(index, minTag) + fun findSelectionForEdition(index: Int, minTag: Int?, userInitiated: Boolean): HHSelection? { + val selection = this.getSelectionForFirstIncompleteRow(index, minTag, userInitiated) this.selectionLiveData.value = selection return selection } @@ -299,7 +299,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra * Finds the index of the first incomplete action, if existing * 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 -> @@ -307,15 +307,15 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra val tags = rowRepresentable.tagsForCompletion() when { - index == startIndex && minTag != null -> { + userInitiated && minTag != null && index == startIndex -> { tags.firstOrNull { - it > minTag && rowRepresentable.isFieldEmpty(it, this.handHistory) + it > minTag && rowRepresentable.isFieldNeedsInput(it, this.handHistory) }?.let { return HHSelection(index, it) } } index >= startIndex -> { - tags.firstOrNull { rowRepresentable.isFieldEmpty(it, this.handHistory) }?.let { tag -> + tags.firstOrNull { rowRepresentable.isFieldNeedsInput(it, this.handHistory) }?.let { tag -> return HHSelection(index, tag) } } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerCardsRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerCardsRow.kt index 3e8a0033..804b308d 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerCardsRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerCardsRow.kt @@ -51,8 +51,4 @@ open class PlayerCardsRow(private var playerSetupCreationListener: PlayerSetupCr return listOf(Tag.CARDS.ordinal) } - override fun isFieldEmpty(tag: Int, handHistory: HandHistory): Boolean { - return super.isFieldEmpty(tag, handHistory) - } - } \ No newline at end of file diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRow.kt index ae7e12a9..ba5f5048 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRow.kt @@ -85,9 +85,9 @@ class PlayerSetupRow(var hero: Boolean = false, // return null // } - override fun isFieldEmpty(tag: Int, handHistory: HandHistory): Boolean { + override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean { return when(tag) { - Tag.HAND.ordinal -> super.isFieldEmpty(tag, handHistory) + Tag.HAND.ordinal -> super.isFieldNeedsInput(tag, handHistory) Tag.STACK.ordinal -> this.playerSetup?.stack == null else -> false }