From 64d593df41148c09bb9d2d63dd1454cabcf35f3b Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 11 Feb 2020 16:53:02 +0100 Subject: [PATCH] Enables number of player selection --- .../pokeranalytics/android/model/TableSize.kt | 20 +++++++++----- .../model/realm/handhistory/HandHistory.kt | 20 +++++++------- .../bottomsheet/BottomSheetFragment.kt | 10 ++++--- .../BottomSheetTableSizeGridFragment.kt | 24 ++++++++--------- .../modules/handhistory/HandHistoryAdapter.kt | 6 +++++ .../handhistory/HandHistoryFragment.kt | 6 ++++- .../handhistory/model/HandHistoryViewModel.kt | 27 ++++++++++--------- ...ettings.kt => StraddleRowRepresentable.kt} | 0 .../android/ui/view/holder/RowViewHolder.kt | 2 +- .../ui/viewmodel/BottomSheetViewModel.kt | 1 + 10 files changed, 70 insertions(+), 46 deletions(-) rename app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/{HandHistorySettings.kt => StraddleRowRepresentable.kt} (100%) diff --git a/app/src/main/java/net/pokeranalytics/android/model/TableSize.kt b/app/src/main/java/net/pokeranalytics/android/model/TableSize.kt index 144396f3..0a08d9a2 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/TableSize.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/TableSize.kt @@ -6,15 +6,15 @@ import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.util.Parser -class TableSize(var numberOfPlayer: Int, var rowViewType: Int = RowViewType.TITLE_GRID.ordinal) : RowRepresentable { +class TableSize(var numberOfPlayer: Int, var rowViewType: Int = RowViewType.TITLE_GRID.ordinal, var alternativeLabels: Boolean = true) : RowRepresentable { companion object { - val all: List - get() { - return Array(9, init = - { index -> TableSize(index + 2) }).toList() - } + fun all(alternativeLabels: Boolean): List { + return Array(9, init = { index -> + TableSize(index + 2, alternativeLabels = alternativeLabels) + }).toList() + } fun valueForLabel(label: String) : Int? { @@ -32,6 +32,10 @@ class TableSize(var numberOfPlayer: Int, var rowViewType: Int = RowViewType.TITL } override fun getDisplayName(context: Context): String { + if (this.alternativeLabels) { + return this.numberOfPlayer.toString() + } + return if (this.numberOfPlayer == 2) { return "HU" } else { @@ -49,6 +53,10 @@ class TableSize(var numberOfPlayer: Int, var rowViewType: Int = RowViewType.TITL } override fun localizedTitle(context: Context): String { + if (this.alternativeLabels) { + return this.numberOfPlayer.toString() + } + this.resId?.let { return if (this.numberOfPlayer == 2) { context.getString(it) 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 d833dd8c..0c2b123b 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 @@ -60,7 +60,7 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab /*** * Number of players in the hand */ - var numberOfPlayers: Int = 10 + var numberOfPlayers: Int = 4 /*** * Number of players in the hand @@ -95,26 +95,24 @@ open class HandHistory : RealmObject(), RowRepresentable, Identifiable, Filterab fun configure(handSetup: HandSetup) { -// this.board.addAll(listOf(Card.valueOf(2, Card.Suit.SPADES), -// Card.valueOf(14, Card.Suit.HEART), -// Card.valueOf(5, Card.Suit.CLOVER), -// Card.valueOf(10, Card.Suit.DIAMOND), -// Card.valueOf(12, Card.Suit.SPADES))) - - this.actions.clear() - handSetup.tableSize?.let { this.numberOfPlayers = it } handSetup.smallBlind?.let { this.smallBlind = it } handSetup.bigBlind?.let { this.bigBlind = it } + this.createActions(handSetup.straddlePositions) + } + + private fun createActions(straddlePositions: List) { + + this.actions.clear() + this.addAction(0, Action.Type.POST_SB, this.smallBlind) this.addAction(1, Action.Type.POST_BB, this.bigBlind) val positions = Position.positionsPerPlayers(this.numberOfPlayers) - var lastStraddler: Int? = null - handSetup.straddlePositions.forEach { position -> // position are sorted here + straddlePositions.forEach { position -> // position are sorted here val positionIndex = positions.indexOf(position) this.addAction(positionIndex, Action.Type.STRADDLE) lastStraddler = positionIndex diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetFragment.kt index 075e1a60..82b1fe0a 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetFragment.kt @@ -33,7 +33,9 @@ class BottomSheetConfig(var row: RowRepresentable, var isClearable: Boolean? = true, var currentCurrency: Currency? = null, var isDeletable: Boolean? = false, - var valueHasPlaceholder: Boolean? = null) { + var valueHasPlaceholder: Boolean? = null, + var alternativeLabels: Boolean = false +) { } @@ -60,11 +62,12 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { isClearable: Boolean? = true, currentCurrency: Currency? = null, isDeletable: Boolean? = false, - valueHasPlaceholder: Boolean? = null + valueHasPlaceholder: Boolean? = null, + alternativeLabels: Boolean = false ): BottomSheetFragment { val bottomSheetFragment = newInstance(row.bottomSheetType) bottomSheetFragment.show(fragmentManager, "bottomSheet") - this.config = BottomSheetConfig(row, delegate, rowRepresentableEditDescriptors, isClearable, currentCurrency, isDeletable, valueHasPlaceholder) + this.config = BottomSheetConfig(row, delegate, rowRepresentableEditDescriptors, isClearable, currentCurrency, isDeletable, valueHasPlaceholder, alternativeLabels) return bottomSheetFragment } @@ -114,6 +117,7 @@ open class BottomSheetFragment : BottomSheetDialogFragment() { this.viewModel.currentCurrency = configuration.currentCurrency this.viewModel.isDeletable = configuration.isDeletable ?: false this.viewModel.valueAsPlaceholder = configuration.valueHasPlaceholder ?: false + this.viewModel.alternativeLabels = configuration.alternativeLabels } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetTableSizeGridFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetTableSizeGridFragment.kt index 8f67cf2f..98881ef1 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetTableSizeGridFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/components/bottomsheet/BottomSheetTableSizeGridFragment.kt @@ -1,6 +1,5 @@ package net.pokeranalytics.android.ui.fragment.components.bottomsheet -import android.content.Context import android.os.Bundle import android.view.LayoutInflater import android.view.View @@ -55,7 +54,7 @@ class BottomSheetTableSizeGridFragment : BottomSheetFragment(), StaticRowReprese } override fun adapterRows(): List? { - return TableSize.all + return TableSize.all(this.viewModel.alternativeLabels) } override fun onRowSelected(position: Int, row: RowRepresentable, tag: Int) { @@ -64,15 +63,16 @@ class BottomSheetTableSizeGridFragment : BottomSheetFragment(), StaticRowReprese dismiss() } - override fun stringForRow( - row: RowRepresentable, - context: Context, - tag: Int - ): String { - this.context?.let { - return row.localizedTitle(it) - } - return "UNKNOWN CONTEXT FOR ROW $row" - } +// override fun stringForRow(row: RowRepresentable, context: Context, tag: Int): String { +// +// if (this.viewModel.alternativeLabels) { +// return (row as TableSize).numberOfPlayer.toString() +// } +// +// this.context?.let { +// return row.localizedTitle(it) +// } +// return "UNKNOWN CONTEXT FOR ROW $row" +// } } \ No newline at end of file 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 29a22d3d..79791da7 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 @@ -38,6 +38,7 @@ import timber.log.Timber enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, HandHistoryRow { + DEFAULT(R.layout.row_title_value), HEADER(R.layout.row_header_value), ACTION(R.layout.row_hand_action), PLAYER_SUMMARY(R.layout.row_hand_player_summary), @@ -45,6 +46,7 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, H BLINDS(R.layout.row_hhsettings_blinds), STRADDLE(R.layout.row_hhsettings_straddle), COMMENT(R.layout.row_hhsettings_comments), + PLAYER_NUMBER(R.layout.row_title_value), PLAYER_SETUP(R.layout.row_hhsettings_player_setup) ; @@ -89,6 +91,7 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, H override val bottomSheetType: BottomSheetType get() { return when(this) { + PLAYER_NUMBER -> BottomSheetType.GRID COMMENT -> BottomSheetType.EDIT_TEXT_MULTI_LINES else -> BottomSheetType.NONE } @@ -97,6 +100,7 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, H override val resId: Int? get() { return when(this) { + PLAYER_NUMBER -> R.string.number_of_players COMMENT -> R.string.comment else -> null } @@ -129,6 +133,7 @@ class HandHistoryAdapter( val rowType: HandRowType = HandRowType.values()[viewType] val layout = LayoutInflater.from(parent.context).inflate(rowType.layoutRes, parent, false) return when (rowType) { + HandRowType.DEFAULT -> RowViewHolder(layout) HandRowType.HEADER -> RowViewHolder(layout) HandRowType.ACTION -> RowHandAction(layout) HandRowType.STREET -> RowHandStreet(layout) @@ -137,6 +142,7 @@ class HandHistoryAdapter( HandRowType.STRADDLE -> RowHandStraddle(layout) HandRowType.PLAYER_SETUP -> RowHandPlayerSetup(layout) HandRowType.COMMENT -> RowViewHolder(layout) + HandRowType.PLAYER_NUMBER -> RowViewHolder(layout) } } 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 0bbdfe1f..376a4401 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 @@ -224,7 +224,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL BottomSheetType.NONE -> {} else -> { val editDescriptors = listOf(RowRepresentableEditDescriptor(this.model.handHistory.comment, R.string.comment)) - BottomSheetFragment.create(this.fragmentManager, row, this, editDescriptors) + BottomSheetFragment.create(this.fragmentManager, row, this, editDescriptors, alternativeLabels = true) return } } @@ -250,6 +250,10 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL this.model.handHistory.comment = value as? String refreshCells(this.model.indexOfRowRepresentable(row)) } + HandRowType.PLAYER_NUMBER -> { + this.model.setNumberOfPlayers(value as Int) + this.handHistoryAdapter.notifyDataSetChanged() + } is ComputedAction -> { this.model.currentAmount = value as String } 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 bb83149a..670d5ec1 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 @@ -39,7 +39,12 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra private set /*** - * + * The hand setup + */ + private var handSetup: HandSetup = HandSetup() + + /*** + * Indicats whether the HH is new or not */ private var isNew: Boolean = true @@ -102,11 +107,6 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra */ private var firstStraddlePosition: Position? = null - /*** - * The hand setup - */ - private var handSetup: HandSetup = HandSetup() - /*** * The board cards sorted by position */ @@ -161,7 +161,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra * Pre-computes the potsizes for the video export */ private fun load() { - this.setNumberOfPlayers(handHistory.numberOfPlayers) + this.sortedActions.positions = Position.positionsPerPlayers(this.handHistory.numberOfPlayers) this.sortedActions.load(this.handHistory) this.createRowRepresentation() } @@ -174,9 +174,9 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra rows.add(HandRowType.COMMENT) - rows.add(CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = R.string.settings, value = "")) + rows.add(HandRowType.PLAYER_NUMBER) rows.add(HandRowType.BLINDS) if (this.isNew) { // don't allow any straddle changes if not new @@ -243,9 +243,12 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra * Sets the number of players playing the hand * Defines the appropriate positions for this player count */ - private fun setNumberOfPlayers(playerCount: Int) { - this.handHistory.numberOfPlayers = playerCount - this.sortedActions.positions = Position.positionsPerPlayers(playerCount) + fun setNumberOfPlayers(playerCount: Int) { + if (playerCount != this.handHistory.numberOfPlayers) { + this.handHistory.numberOfPlayers = playerCount + this.handHistory.configure(this.handSetup) + load() + } } /*** @@ -437,7 +440,6 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra } - // Card Centralizer /*** @@ -536,6 +538,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra override fun stringForRow(row: RowRepresentable, context: Context, tag: Int): String { return when (row) { + HandRowType.PLAYER_NUMBER -> this.handHistory.numberOfPlayers.toString() HandRowType.COMMENT -> this.handHistory.comment ?: context.getString(R.string.comment) HandRowType.BLINDS -> { when (tag) { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistorySettings.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StraddleRowRepresentable.kt similarity index 100% rename from app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistorySettings.kt rename to app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StraddleRowRepresentable.kt diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/holder/RowViewHolder.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/holder/RowViewHolder.kt index 43957e2d..124e0dff 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/holder/RowViewHolder.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/holder/RowViewHolder.kt @@ -105,7 +105,7 @@ class RowViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), Bindabl // Title itemView.findViewById(R.id.title)?.let { val title = row.resId?.let { resId -> - itemView.context.getString(resId) + row.localizedTitle(itemView.context) } ?: run { row.getDisplayName(itemView.context) } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/viewmodel/BottomSheetViewModel.kt b/app/src/main/java/net/pokeranalytics/android/ui/viewmodel/BottomSheetViewModel.kt index b56256c9..eae5a684 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/viewmodel/BottomSheetViewModel.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/viewmodel/BottomSheetViewModel.kt @@ -58,6 +58,7 @@ class BottomSheetViewModel : ViewModel() { * Table Size */ var defaultSize: Int? = null + var alternativeLabels: Boolean = false /** * Multiselection