From 024ce910403a375b92967af28458248148293e58 Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 31 Jan 2020 11:48:15 +0100 Subject: [PATCH] Various fixes and improvements --- .../android/model/handhistory/HHBuilder.kt | 26 ++++++++++++++----- .../android/model/realm/handhistory/Action.kt | 7 ++--- .../android/model/realm/handhistory/Card.kt | 5 ++++ .../model/realm/handhistory/HandHistory.kt | 2 +- .../modules/handhistory/HandHistoryAdapter.kt | 18 ++++++------- .../handhistory/HandHistoryFragment.kt | 23 +++++++++++----- .../handhistory/HandHistoryViewModel.kt | 11 +++++--- .../handhistory/views/CardSuitAdapter.kt | 2 +- .../ui/modules/handhistory/views/CardsRow.kt | 12 ++++++++- .../handhistory/views/KeyboardActionView.kt | 11 ++++++++ .../handhistory/views/KeyboardAmountView.kt | 18 ++++++++----- .../handhistory/views/KeyboardContainer.kt | 7 ++++- .../android/ui/view/RowViewType.kt | 9 ++++--- .../android/ui/view/holder/RowViewHolder.kt | 26 ++++++++++++++++--- 14 files changed, 130 insertions(+), 47 deletions(-) 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 7473668d..a5adbe10 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 @@ -113,7 +113,7 @@ class HHBuilder { /*** * Returns the list of available user actions at [index] */ - private fun availableActions(index: Int) : Set { + fun availableActions(index: Int) : Set { val lastSignificantAction: ComputedAction? = getStreetLastSignificantAction(index) val lastUserAction: ComputedAction? = getLastUserAction(index) @@ -323,12 +323,18 @@ class HHBuilder { /*** * Returns the list of position still in play before the given [index] */ - private fun activePositions(index: Int): MutableList { + private fun activePositions(index: Int, showDown: Boolean = false): MutableList { val oustedPositions = this.sortedActions.take(index + 1) - .filter { it.action.type?.isPullOut ?: false } + .filter { + if (showDown) { + it.action.type == Action.Type.FOLD + } else { + it.action.type?.isPullOut ?: false + } + } .map { it.position } - val allPositions = this.positions + val allPositions = this.positions.clone() as LinkedHashSet allPositions.removeAll(oustedPositions) return allPositions.toMutableList() } @@ -360,7 +366,8 @@ class HHBuilder { addStreetHeader(this.rowRepresentables, street, totalPotSize) val lastActionIndex = lastComputedAction.action.index - activePositions(lastActionIndex).sortedBy { it.ordinal }.forEach { + val isShowDown = street == Street.SUMMARY + activePositions(lastActionIndex, isShowDown).sortedBy { it.ordinal }.forEach { when (street) { Street.SUMMARY -> { @@ -398,6 +405,7 @@ class HHBuilder { } val sizeBefore = this.sortedActions.size this.sortedActions = this.sortedActions.take(index + defaultRowsCount).toMutableList() + this.createRowRepresentation() val sizeAfter = this.sortedActions.size return sizeAfter != sizeBefore @@ -815,7 +823,13 @@ class HHBuilder { rowRepresentables.add(headerView) if (street.totalBoardCards > 0) { - val boardView = StreetCardsRow(street, this.handHistory.cardsForStreet(street)) + + // get board from last street + val lastBoardRow = this.rowRepresentables.lastOrNull { it is StreetCardsRow } as? StreetCardsRow + val cards = lastBoardRow?.cards ?: listOf() + + // create new StreetCardsRow + val boardView = StreetCardsRow(street, cards) 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 6bba2086..c252c2f7 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 @@ -73,8 +73,9 @@ open class Action : RealmObject() { companion object { - val defaultTypes: List - get() { return listOf(FOLD, CHECK, BET, CALL, RAISE, UNDEFINED_ALLIN) } + val defaultTypes: List by lazy { + listOf(FOLD, CHECK, BET, CALL, RAISE, UNDEFINED_ALLIN) + } } @@ -129,7 +130,7 @@ open class Action : RealmObject() { return this.type?.isSignificant ?: false } - val displayedFormattedAmount: String? + val formattedAmount: String? get() { val amount = when (type) { Type.CALL, Type.CALL_ALLIN -> this.effectiveAmount 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 7c825766..c718a458 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 @@ -82,6 +82,11 @@ open class Card : RealmObject() { CLOVER("♣︎"); companion object { + + val displaySuits: List by lazy { + listOf(SPADES, HEART, DIAMOND, CLOVER, UNDEFINED) + } + fun format(suit: Suit?) : String { return suit?.value ?: "" } diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt index a4d80765..f861b946 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt @@ -109,7 +109,7 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab val totalActions = this.actions.size - for (i in totalActions until this.numberOfPlayers + totalActions - 1) { + for (i in totalActions until this.numberOfPlayers + totalActions) { this.addAction(i, i % this.numberOfPlayers) } 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 3bbd16a6..69f81e23 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 @@ -1,6 +1,5 @@ package net.pokeranalytics.android.ui.modules.handhistory -import android.app.Activity import android.content.res.ColorStateList import android.text.InputType import android.view.LayoutInflater @@ -21,7 +20,6 @@ import net.pokeranalytics.android.ui.adapter.BindableHolder import net.pokeranalytics.android.ui.adapter.RecyclerAdapter import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate -import net.pokeranalytics.android.ui.extensions.hideKeyboard import net.pokeranalytics.android.ui.modules.handhistory.views.PlayerCardsRow import net.pokeranalytics.android.ui.modules.handhistory.views.StreetCardsRow import net.pokeranalytics.android.ui.view.RowRepresentable @@ -114,7 +112,7 @@ class HandHistoryAdapter( // Action itemView.findViewById