diff --git a/app/src/main/java/net/pokeranalytics/android/model/handhistory/BoardManager.kt b/app/src/main/java/net/pokeranalytics/android/model/handhistory/BoardManager.kt index 8a019097..1a4080b1 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/handhistory/BoardManager.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/handhistory/BoardManager.kt @@ -38,6 +38,12 @@ class BoardManager(cards: List, var listener: BoardChangedListener) { */ fun add(card: Card) { + this.sortedBoardCards.lastOrNull()?.let { + if (it.suit == null) { + it.suit = Card.Suit.UNDEFINED + } + } + if (this.sortedBoardCards.size == 5) { throw PAIllegalStateException("Can't add anymore cards") } diff --git a/app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt b/app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt index d3321bef..d930fc10 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/handhistory/HHBuilder.kt @@ -10,6 +10,7 @@ import net.pokeranalytics.android.ui.modules.handhistory.views.PlayerCardsRow import net.pokeranalytics.android.ui.modules.handhistory.views.StreetCardView import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable +import net.pokeranalytics.android.util.extensions.formatted import timber.log.Timber import kotlin.math.max @@ -546,16 +547,12 @@ class HHBuilder : BoardChangedListener { fun findIndexForEdition(startIndex: Int, keyboard: HHKeyboard? = null): HHSelection? { this.rowRepresentables.forEachIndexed { index, rowRepresentable -> + if (index >= startIndex && rowRepresentable is HandHistoryRow) { -// Timber.d("Check keyboard for index = $index") val foundKeyboard = rowRepresentable.keyboardForCompletion() - if (foundKeyboard != null && !(index == startIndex && keyboard == foundKeyboard)) { + if (foundKeyboard != null) { return HHSelection(index, foundKeyboard) } - -// rowRepresentable.keyboardForCompletion()?.let { keyboard -> -// return HHSelection(index, keyboard) -// } } } return null @@ -701,7 +698,6 @@ class HHBuilder : BoardChangedListener { } } - } this.rowRepresentables = rows @@ -743,8 +739,11 @@ class HHBuilder : BoardChangedListener { } - val allCheck = this.sortedActions.filter { it.action.street == currentStreet }.all { it.action.type == Action.Type.CHECK } - if (allCheck) { + val allPassive = this.sortedActions + .filter { it.action.street == currentStreet } + .all { it.action.type?.isPassive ?: false } + + if (allPassive) { return if (currentStreet != Street.RIVER) { currentStreet.next } else { @@ -759,11 +758,11 @@ class HHBuilder : BoardChangedListener { * Adds a [street] header to a [rowRepresentables] list with a given [potSize] */ private fun addStreetHeader(rowRepresentables: MutableList, street: Street, potSize: Double) { - val headerView = CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = street.resId) + val headerView = CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = street.resId, value = potSize.formatted()) rowRepresentables.add(headerView) if (street.totalBoardCards > 0) { - val boardView = StreetCardView(street, this.handHistory.cardsForStreet(street), potSize) + val boardView = StreetCardView(street, this.handHistory.cardsForStreet(street)) rowRepresentables.add(boardView) } diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt index 1ee89ab7..0e24aecc 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt @@ -45,6 +45,14 @@ open class Action : RealmObject() { } } + val isPassive: Boolean + get() { + return when (this) { + FOLD, CHECK -> true + else -> false + } + } + val requiresOpponentDecision: Boolean get() { return when(this) { diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Card.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Card.kt index 52d5d91b..7c825766 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Card.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Card.kt @@ -75,6 +75,7 @@ open class Card : RealmObject() { } enum class Suit(val value: String) : CardProperty, RowRepresentable { + UNDEFINED("x"), SPADES("♠︎"), HEART("♥︎"), DIAMOND("♦︎"), @@ -82,7 +83,7 @@ open class Card : RealmObject() { companion object { fun format(suit: Suit?) : String { - return suit?.value ?: "x" + return suit?.value ?: "" } fun color(suit: Suit?) : Int { return suit?.color ?: R.color.white @@ -92,6 +93,7 @@ open class Card : RealmObject() { val color: Int get() { return when (this) { + UNDEFINED -> R.color.white SPADES -> R.color.white_dark HEART -> R.color.red DIAMOND -> R.color.diamond 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 15fea871..1b9104b4 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 @@ -31,7 +31,7 @@ import timber.log.Timber enum class HandRowType(var layoutRes: Int) : ViewIdentifier { - HEADER(R.layout.row_header_title), + HEADER(R.layout.row_header_value), ACTION(R.layout.row_hand_action), PLAYER_SUMMARY(R.layout.row_hand_player_summary), STREET(R.layout.row_hand_cards); 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 90b70511..a7db02b2 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 @@ -157,14 +157,15 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL this.model.isEdited = false } - private fun findNextActionToEdit() { - val selection = this.model.selectionLiveData.value - val index = selection?.index ?: throw PAIllegalStateException("Request next with no selection") - this.findNextActionToEdit(index, selection.keyboard) - } - - private fun findNextActionToEdit(startIndex: Int, keyboard: HHKeyboard? = null) { - this.model.findIndexForEdition(startIndex, keyboard)?.let { +// private fun findNextActionToEdit() { +// val selection = this.model.selectionLiveData.value +// val index = selection?.index ?: throw PAIllegalStateException("Request next with no selection") +// this.findNextActionToEdit(index, selection.keyboard) +// } + + private fun findNextActionToEdit(index: Int? = null) { + val startIndex = index ?: this.model.currentSelection.index + this.model.findIndexForEdition(startIndex)?.let { this.keyboard.show(it) } ?: run { this.keyboard.hide() @@ -241,7 +242,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index) // TODO add test about number of cards before selecting next action? -// this.findNextActionToEdit() + this.findNextActionToEdit() } override fun cardSuitSelected(suit: Card.Suit) { @@ -249,7 +250,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index) // TODO add test about number of cards? -// this.findNextActionToEdit() + this.findNextActionToEdit() } override fun clearCards() { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryViewModel.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryViewModel.kt index 619cd970..43dbb394 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryViewModel.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryViewModel.kt @@ -82,9 +82,10 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource { this.builder.deleteLastCardProperty(this.currentSelection) } - fun findIndexForEdition(startIndex: Int, keyboard: HHKeyboard? = null): HHKeyboard? { - this.selectionLiveData.value = this.builder.findIndexForEdition(startIndex, keyboard) - return selectionLiveData.value?.keyboard + fun findIndexForEdition(index: Int): HHKeyboard? { + val selection = this.builder.findIndexForEdition(index, this.selectionLiveData.value?.keyboard) + this.selectionLiveData.value = selection + return selection?.keyboard } fun amountChanged(amount: String?) { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/StreetCardView.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/StreetCardView.kt index 734e51dd..ec089d9b 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/StreetCardView.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/StreetCardView.kt @@ -6,12 +6,14 @@ import net.pokeranalytics.android.model.handhistory.Street import net.pokeranalytics.android.model.realm.handhistory.Card import net.pokeranalytics.android.ui.modules.handhistory.HandRowType -class StreetCardView(var street: Street, var cards: List, var potSize: Double) : HandHistoryRow { +class StreetCardView(var street: Street, var cards: List) : HandHistoryRow { override val viewType: Int = HandRowType.STREET.ordinal override fun keyboardForCompletion(): HHKeyboard? { - return if (cards.size != street.totalBoardCards) { + return if (cards.size < street.totalBoardCards) { + HHKeyboard.CARD + } else if (cards.last().suit == null) { HHKeyboard.CARD } else { null diff --git a/app/src/main/res/layout/row_header_value.xml b/app/src/main/res/layout/row_header_value.xml new file mode 100644 index 00000000..35c91a1b --- /dev/null +++ b/app/src/main/res/layout/row_header_value.xml @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file