From dbe325e6e70f65d363c363bfb67ddf71ad7d9cc9 Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 28 Feb 2020 12:15:12 +0100 Subject: [PATCH] read mode for player setups --- .../modules/handhistory/HandHistoryAdapter.kt | 197 +++++------------- .../handhistory/HandHistoryFragment.kt | 6 +- .../modules/handhistory/model/ActionList.kt | 2 + .../handhistory/model/ActionReadRow.kt | 2 +- .../handhistory/model/HandHistoryViewModel.kt | 29 ++- .../handhistory/model/PlayerSetupRow.kt | 34 +-- .../main/res/layout/row_hand_action_read.xml | 23 +- .../layout/row_hhsettings_player_setup.xml | 11 - .../row_hhsettings_player_setup_read.xml | 45 ++++ 9 files changed, 154 insertions(+), 195 deletions(-) create mode 100644 app/src/main/res/layout/row_hhsettings_player_setup_read.xml 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 c539cb4a..c2db9382 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 @@ -9,6 +9,7 @@ import android.view.ViewGroup import android.widget.Button import android.widget.EditText import android.widget.LinearLayout +import android.widget.TextView import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.google.android.material.chip.Chip @@ -17,12 +18,15 @@ import kotlinx.android.synthetic.main.row_hand_action_read.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_player_setup.view.* +import kotlinx.android.synthetic.main.row_hhsettings_player_setup.view.posButton +import kotlinx.android.synthetic.main.row_hhsettings_player_setup.view.psHandLayout +import kotlinx.android.synthetic.main.row_hhsettings_player_setup.view.settings_container +import kotlinx.android.synthetic.main.row_hhsettings_player_setup_read.view.* import kotlinx.android.synthetic.main.row_hhsettings_straddle.view.* import net.pokeranalytics.android.R import net.pokeranalytics.android.exceptions.PAIllegalStateException import net.pokeranalytics.android.model.handhistory.Position import net.pokeranalytics.android.model.realm.handhistory.Card -import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.ui.adapter.BindableHolder import net.pokeranalytics.android.ui.adapter.RecyclerAdapter import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource @@ -37,7 +41,7 @@ import net.pokeranalytics.android.ui.view.rowrepresentable.ViewIdentifier import net.pokeranalytics.android.util.extensions.formatted -enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, HandHistoryRow { +enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable { DEFAULT(R.layout.row_title), HEADER(R.layout.row_header_value), ACTION(R.layout.row_hand_action), @@ -47,6 +51,7 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, H COMMENT(R.layout.row_hhsettings_comments), PLAYER_NUMBER(R.layout.row_title_value), PLAYER_SETUP(R.layout.row_hhsettings_player_setup), + PLAYER_SETUP_READ(R.layout.row_hhsettings_player_setup_read), ANTE(R.layout.row_title_value), BIG_BLIND_ANTE(R.layout.row_title_switch), ACTION_READ(R.layout.row_hand_action_read) @@ -57,50 +62,6 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable, H override val identifier: Int get() { return this.ordinal } - override fun tagsForCompletion(): List { -// return when (this) { -// BLINDS -> listOf(0, 1) -// else -> listOf() -// } - return listOf() - } - - override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean { -// return when (this) { -// BLINDS -> { -// when (tag) { -// 0 -> (handHistory.smallBlind == null) -// 1 -> (handHistory.bigBlind == null) -// else -> false -// } -// } -// else -> false -// } - return false - } - - override fun keyboardForTag(tag: Int): HHKeyboard? { -// return when (this) { -// BLINDS -> HHKeyboard.AMOUNT -// else -> throw PAIllegalStateException("unmanaged tag $tag") -// } - throw PAIllegalStateException("unmanaged tag $tag") - } - - override fun amountForTag(handHistory: HandHistory, tag: Int): Double? { -// return when (this) { -// BLINDS -> { -// when (tag) { -// 0 -> handHistory.smallBlind -// 1 -> handHistory.bigBlind -// else -> null -// } -// } -// else -> null -// } - return null - } - override val bottomSheetType: BottomSheetType get() { return when(this) { @@ -154,9 +115,9 @@ class HandHistoryAdapter( HandRowType.ACTION -> RowHandAction(layout) HandRowType.STREET -> RowHandStreet(layout) HandRowType.PLAYER_SUMMARY -> RowHandPlayerSummary(layout) -// HandRowType.BLINDS -> RowHandBlinds(layout) HandRowType.STRADDLE -> RowHandStraddle(layout) HandRowType.PLAYER_SETUP -> RowHandPlayerSetup(layout) + HandRowType.PLAYER_SETUP_READ -> RowHandReadOnlyPlayerSetup(layout) HandRowType.COMMENT -> RowViewHolder(layout) HandRowType.ACTION_READ -> RowActionRead(layout) HandRowType.PLAYER_NUMBER, HandRowType.ANTE, HandRowType.BIG_BLIND_ANTE -> RowViewHolder(layout) @@ -211,7 +172,7 @@ class HandHistoryAdapter( this.configureEditTexts(index..index, position, row, adapter) } - protected fun configureEditTexts(tagRange: IntRange, position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { + private fun configureEditTexts(tagRange: IntRange, position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { tagRange.forEach { tag -> @@ -245,6 +206,11 @@ class HandHistoryAdapter( } + protected fun configureTextView(tag: Int, position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { + val textView = itemView.findViewWithTag(tag) ?: throw PAIllegalStateException("TextView not found for tag: $tag, class: $this") + textView.text = adapter.dataSource.charSequenceForRow(row, itemView.context, tag) + } + protected fun setClickListener(editText: EditText) { editText.isFocusableInTouchMode = true @@ -302,29 +268,6 @@ class HandHistoryAdapter( } -// inner class RowHandBlinds(itemView: View) : RowHandHolder(itemView) { -// -// init { -//// itemView.smallBlindEditText.tag = 0 -//// itemView.bigBlindEditText.tag = 1 -// itemView.anteEditText.tag = 0 -// -//// setClickListener(itemView.smallBlindEditText) -//// setClickListener(itemView.bigBlindEditText) -// setClickListener(itemView.anteEditText) -// -// } -// -// // sb, bb, ante, bb ante -// -// override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { -// super.onBind(position, row, adapter) -// -// configureEditTexts(0, position, row, adapter) -// } -// -// } - inner class RowHandStraddle(itemView: View) : RowHandHolder(itemView) { override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { @@ -453,10 +396,6 @@ class HandHistoryAdapter( */ inner class RowHandStreet(itemView: View) : RowHandHolder(itemView) { - init { -// itemView.cardsLayout.tag = 0 - } - override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { super.onBind(position, row, adapter) @@ -464,19 +403,6 @@ class HandHistoryAdapter( itemView.cardsLayout.tag = streetCardsRow.street.ordinal configureCardsLayout(itemView.cardsLayout) - -// itemView.cardsLayout.removeAllViews() -// -// val inflater = LayoutInflater.from(itemView.context) -// adapter.dataSource.contentForRow(row, itemView.context, Card::class).forEach { card -> -// val cardView = card.view(itemView.context, inflater, itemView.cardsLayout) -// itemView.cardsLayout.addView(cardView) -// } -// -// itemView.cardsLayout.setOnClickListener { -// adapter.delegate?.onRowSelected(position, row) -// } - } } @@ -487,30 +413,7 @@ class HandHistoryAdapter( inner class RowHandPlayerSummary(itemView: View) : RowHandHolder(itemView) { init { - itemView.handLayout.tag = PlayerCardsRow.Tag.CARDS.ordinal - -// itemView.cardsEditText.tag = PlayerCardsRow.Tag.CARDS.ordinal - - // Cards -// itemView.findViewById(R.id.cardsEditText)?.let { cardsEditText -> -// -// cardsEditText.isFocusableInTouchMode = true -// cardsEditText.setOnTouchListener { _, event -> -// -// if (event.action == MotionEvent.ACTION_UP) { -// // Both are required, otherwise requestFocus() fails -// cardsEditText.isFocusable = true -// cardsEditText.isFocusableInTouchMode = true -// -// cardsEditText.requestFocus() -// -// editTextSelected(cardsEditText, true, PlayerCardsRow.Tag.CARDS.ordinal) -// } -// return@setOnTouchListener true -// } -// -// } } override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { @@ -525,52 +428,41 @@ class HandHistoryAdapter( } configureCardsLayout(itemView.handLayout) + } + } -// configureEditTexts(PlayerCardsRow.Tag.CARDS.ordinal, position, row, adapter) + inner class RowHandReadOnlyPlayerSetup(itemView: View) : AbstractRowHandPlayerSetup(itemView) { + init { + itemView.stackTextView.tag = PlayerSetupRow.Tag.STACK.ordinal } + + override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { + super.onBind(position, row, adapter) + + configureTextView(PlayerSetupRow.Tag.STACK.ordinal, position, row, adapter) + } + } - inner class RowHandPlayerSetup(itemView: View) : RowHandHolder(itemView) { + inner class RowHandPlayerSetup(itemView: View) : AbstractRowHandPlayerSetup(itemView) { private var positionAdapter: PositionAdapter = PositionAdapter() - private var delegate: RowRepresentableDelegate? = null + private var positionViewManager: LinearLayoutManager init { - itemView.psHandLayout.tag = PlayerSetupRow.Tag.HAND.ordinal itemView.stackEditText.tag = PlayerSetupRow.Tag.STACK.ordinal + itemView.stackEditText.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL setClickListener(itemView.stackEditText) - // Position Recycler - val positionViewManager = LinearLayoutManager(itemView.context, RecyclerView.HORIZONTAL, false) + this.positionViewManager = LinearLayoutManager(itemView.context, RecyclerView.HORIZONTAL, false) itemView.positionRecyclerView.apply { setHasFixedSize(true) layoutManager = positionViewManager adapter = positionAdapter } - - itemView.findViewById(R.id.stackEditText)?.let { stackEditText -> - - stackEditText.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL - stackEditText.isFocusableInTouchMode = true - - stackEditText.setOnTouchListener { _, event -> - - if (event.action == MotionEvent.ACTION_UP) { - // Both are required, otherwise requestFocus() fails - stackEditText.isFocusable = true - stackEditText.isFocusableInTouchMode = true - - stackEditText.requestFocus() - - editTextSelected(stackEditText, true, stackEditText.tag as Int) - } - return@setOnTouchListener true - } - } - } override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { @@ -578,7 +470,6 @@ class HandHistoryAdapter( val setupRow = row as PlayerSetupRow val state = setupRow.state - this.delegate = adapter.delegate // Title itemView.title.text = setupRow.title(itemView.context) @@ -595,13 +486,29 @@ class HandHistoryAdapter( this.delegate?.onRowValueChanged(pos, row) } + configureEditTexts(PlayerSetupRow.Tag.STACK.ordinal, position, row, adapter) + + } + + } + + abstract inner class AbstractRowHandPlayerSetup(itemView: View) : RowHandHolder(itemView) { + + protected var delegate: RowRepresentableDelegate? = null + + init { + itemView.psHandLayout.tag = PlayerSetupRow.Tag.HAND.ordinal + } + + override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { + super.onBind(position, row, adapter) + + val setupRow = row as PlayerSetupRow + val state = setupRow.state + this.delegate = adapter.delegate + // Position Button itemView.posButton.text = adapter.dataSource.charSequenceForRow(row, itemView.context, PlayerSetupRow.Tag.POSITION.ordinal) -// itemView.posButton.setOnClickListener { -// setupRow.showPosition() -// itemView.positionRecyclerView.visibility = View.VISIBLE -// itemView.posButton.backgroundTintList = ColorStateList.valueOf(color(true)) -// } val positionSelected = adapter.dataSource.isSelected(position, row, PlayerSetupRow.Tag.POSITION.ordinal) itemView.posButton.backgroundTintList = ColorStateList.valueOf(color(positionSelected)) @@ -609,8 +516,6 @@ class HandHistoryAdapter( itemView.settings_container.visibility = if (state == PlayerSetupRow.State.POSITIONS_ONLY) View.GONE else View.VISIBLE configureCardsLayout(itemView.psHandLayout) -// configureEditTexts(PlayerSetupRow.Tag.HAND.ordinal, position, row, adapter) - configureEditTexts(PlayerSetupRow.Tag.STACK.ordinal, position, row, adapter) } 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 e3976ed7..963fd7e6 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 @@ -169,6 +169,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL override fun onCreateOptionsMenu(menu: Menu?, inflater: MenuInflater?) { menu?.clear() + this.menu = menu inflater?.inflate(R.menu.toolbar_hand_history, menu) updateMenuUI() super.onCreateOptionsMenu(menu, inflater) @@ -196,7 +197,9 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL private fun retrieveEditTextInputConnection(selection: HHSelection) { - val handRow = this.model.rowRepresentableForPosition(selection.index) as? HandRowType +// throw PAIllegalStateException("I believe this should not happen any more") + + val handRow = this.model.rowRepresentableForPosition(selection.index) as? HandHistoryRow val holder = recyclerView.findViewHolderForAdapterPosition(selection.index) as? HandHistoryAdapter.RowHandHolder holder?.let { @@ -210,6 +213,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL private fun saveOrEdit() { this.model.isEdited = !this.model.isEdited + updateMenuUI() if (this.model.isEdited) { this.findNextActionToEdit(0) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt index 3adebbb1..b650afb4 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt @@ -133,6 +133,8 @@ class ActionList(var listener: ActionListListener) : ArrayList() */ override fun minimumBetAmount(index: Int): Double { + if (this[index].action.type?.isBlind == true) return 0.0 // no min for blinds + val street = this[index].street // Verify that the amount is correct, at least the amount of the previous raise difference diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionReadRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionReadRow.kt index 5a345838..223efc38 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionReadRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionReadRow.kt @@ -7,6 +7,6 @@ import net.pokeranalytics.android.ui.view.RowRepresentable class ActionReadRow(var positions: MutableList, var action: Action.Type?, var amount: Double?) : RowRepresentable { - override val viewType: Int = HandRowType.STREET.ordinal + override val viewType: Int = HandRowType.ACTION_READ.ordinal } \ 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 58299703..c7e83f6b 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 @@ -215,8 +215,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra rows.add(HandRowType.BIG_BLIND_ANTE) } - - this.playerSetups().forEach { + this.readPlayerSetups().forEach { rows.add(it) } @@ -797,6 +796,15 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra } + private fun readPlayerSetups(): List { + + val hh = this.handHistory + return hh.playerSetups.sortedBy { it.position }.map { + val position = this.positionForIndex(it.position) + createPlayerSetupRow(it, position, hero = false, readMode = true) + } + } + /*** * Returns the list of PlayerSetupRowRepresentable for the hand * Will show rows for existing PlayerSetup, as well as a row for the hero if not set, @@ -808,7 +816,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra val arrangedSetups = hh.playerSetups.sortedBy { it.position }.map { val position = this.positionForIndex(it.position) - createPlayerSetupRow(false, position, it) + createPlayerSetupRow(it, position, false) }.toMutableList() val heroSetup = arrangedSetups.firstOrNull { it.playerSetup?.position == hh.heroIndex } @@ -817,11 +825,11 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra arrangedSetups.remove(it) arrangedSetups.add(0, it) } ?: run { - arrangedSetups.add(0, createPlayerSetupRow(true)) + arrangedSetups.add(0, createPlayerSetupRow(hero = true)) } if (arrangedSetups.size < hh.numberOfPlayers) { - arrangedSetups.add(createPlayerSetupRow(false)) + arrangedSetups.add(createPlayerSetupRow(hero = false)) } return arrangedSetups @@ -830,8 +838,13 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra /*** * Convenience method to create a PlayerSetupRow */ - private fun createPlayerSetupRow(hero: Boolean, position: Position? = null, playerSetup: PlayerSetup? = null): PlayerSetupRow { - return PlayerSetupRow(hero, position, playerSetup?.position, this.handHistory, playerSetup, this.playerHandMaxCards) + private fun createPlayerSetupRow( + playerSetup: PlayerSetup? = null, + position: Position? = null, + hero: Boolean, + readMode: Boolean = false + ): PlayerSetupRow { + return PlayerSetupRow(hero, readMode, position, playerSetup?.position, this.handHistory, playerSetup, this.playerHandMaxCards) } /*** @@ -853,7 +866,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra if (!playerSetupRow.hero && setupCreated) { if (this.handHistory.undefinedPositions().isNotEmpty()) { - val newPlayerRow = createPlayerSetupRow(false) + val newPlayerRow = createPlayerSetupRow(hero = false) val index = this.indexOfRowRepresentable(playerSetupRow) this.rowsLiveData.value?.add(index + 1, newPlayerRow) } 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 003d6787..a6a0c61e 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 @@ -9,6 +9,7 @@ import net.pokeranalytics.android.model.realm.handhistory.PlayerSetup import net.pokeranalytics.android.ui.modules.handhistory.HandRowType class PlayerSetupRow(var hero: Boolean = false, + var readMode: Boolean = false, position: Position?, positionIndex: Int?, handHistory: HandHistory, @@ -38,10 +39,6 @@ class PlayerSetupRow(var hero: Boolean = false, return if (this.playerSetup != null) State.SETUP_ONLY else State.POSITIONS_ONLY } - fun showPosition() { - this._state = State.BOTH - } - fun closePosition() { this._state = null } @@ -63,27 +60,14 @@ class PlayerSetupRow(var hero: Boolean = false, } - override val viewType: Int = HandRowType.PLAYER_SETUP.ordinal - -// override fun tagForCompletion( -// handHistory: HandHistory, -// minTag: Int? -// ): Int? { -// -// // if the PlayerSetup exists -// this.playerSetup?.let { -// super.tagForCompletion(handHistory, minTag)?.let { tag -> -// return Tag.HAND.ordinal -// } -// -// // stack -// if (it.stack == null) { -// return Tag.STACK.ordinal -// } -// } -// -// return null -// } + override val viewType: Int + get() { + return if (this.readMode) { + HandRowType.PLAYER_SETUP_READ.ordinal + } else { + HandRowType.PLAYER_SETUP.ordinal + } + } override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean { return when(tag) { diff --git a/app/src/main/res/layout/row_hand_action_read.xml b/app/src/main/res/layout/row_hand_action_read.xml index 2c52f4c7..e202a5de 100644 --- a/app/src/main/res/layout/row_hand_action_read.xml +++ b/app/src/main/res/layout/row_hand_action_read.xml @@ -1,28 +1,45 @@ + + + android:layout_marginStart="8dp" + tools:text="BB" + /> + android:layout_marginStart="8dp" + tools:text="raises"/> + android:layout_marginStart="8dp" + android:layout_marginEnd="8dp" + android:gravity="end" + tools:text="120" /> \ No newline at end of file diff --git a/app/src/main/res/layout/row_hhsettings_player_setup.xml b/app/src/main/res/layout/row_hhsettings_player_setup.xml index 0fc9c462..113dcad6 100644 --- a/app/src/main/res/layout/row_hhsettings_player_setup.xml +++ b/app/src/main/res/layout/row_hhsettings_player_setup.xml @@ -49,17 +49,6 @@ android:paddingEnd="0dp" android:gravity="center"/> - - - - - - - - - - - + + + + + + + + + + + \ No newline at end of file