From e7b820dc3371a85e430fd02926bfb1a95445fcb0 Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 11 Feb 2020 18:54:42 +0100 Subject: [PATCH] Prepare Player Setup rows --- .../model/realm/handhistory/PlayerSetup.kt | 2 +- .../modules/handhistory/HandHistoryAdapter.kt | 49 ++++++++++++++++--- .../handhistory/model/HandHistoryViewModel.kt | 26 ++++++++++ .../model/PlayerSetupRowRepresentable.kt | 46 +++++++++++++++++ .../handhistory/views/KeyboardContainer.kt | 5 +- .../handhistory/views/PositionAdapter.kt | 4 +- .../layout/row_hhsettings_player_setup.xml | 31 ++++++++++-- app/src/main/res/values/strings.xml | 1 + 8 files changed, 147 insertions(+), 17 deletions(-) create mode 100644 app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRowRepresentable.kt diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/PlayerSetup.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/PlayerSetup.kt index 54ecf6c3..bbb7d038 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/PlayerSetup.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/PlayerSetup.kt @@ -13,7 +13,7 @@ open class PlayerSetup : RealmObject(), CardHolder { var player: Player? = null /*** - * The position at the table: SB..BUTTON + * The position at the table */ var position: Int = 0 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 79791da7..597c94de 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 @@ -14,8 +14,10 @@ import com.google.android.material.chip.Chip import kotlinx.android.synthetic.main.row_hand_action.view.* import kotlinx.android.synthetic.main.row_hhsettings_blinds.view.* import kotlinx.android.synthetic.main.row_hhsettings_player_setup.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.handhistory.Street import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.model.realm.handhistory.formatted @@ -25,15 +27,15 @@ import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource import net.pokeranalytics.android.ui.adapter.RowRepresentableDelegate import net.pokeranalytics.android.ui.extensions.px import net.pokeranalytics.android.ui.fragment.components.bottomsheet.BottomSheetType -import net.pokeranalytics.android.ui.modules.handhistory.model.ComputedAction -import net.pokeranalytics.android.ui.modules.handhistory.model.HHKeyboard -import net.pokeranalytics.android.ui.modules.handhistory.model.HandHistoryRow -import net.pokeranalytics.android.ui.modules.handhistory.model.StraddleRowRepresentable +import net.pokeranalytics.android.ui.modules.handhistory.model.* import net.pokeranalytics.android.ui.modules.handhistory.views.PlayerCardsRow +import net.pokeranalytics.android.ui.modules.handhistory.views.PositionAdapter +import net.pokeranalytics.android.ui.modules.handhistory.views.PositionSelectionListener import net.pokeranalytics.android.ui.modules.handhistory.views.StreetCardsRow import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.holder.RowViewHolder import net.pokeranalytics.android.ui.view.rowrepresentable.ViewIdentifier +import net.pokeranalytics.android.util.extensions.formatted import timber.log.Timber @@ -518,15 +520,46 @@ class HandHistoryAdapter( } } - inner class RowHandPlayerSetup(itemView: View) : RowHandHolder(itemView) { + inner class RowHandPlayerSetup(itemView: View) : RowHandHolder(itemView), PositionSelectionListener { + + private var positionAdapter: PositionAdapter = PositionAdapter(this) + + init { + + // TODO configure recycler view + +// itemView.positionRecyclerView + + } override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { super.onBind(position, row, adapter) -// itemView.positionsChipGroup + val setup = row as PlayerSetupRowRepresentable + val state = setup.state + + itemView.title.text = setup.title(itemView.context) + + val visibility = if (state == PlayerSetupRowRepresentable.State.SHOW_POSITION) View.VISIBLE else View.GONE + itemView.positionRecyclerView.visibility = visibility + + itemView.posButton.text = setup.position?.value + + itemView.settings_container.visibility = if (state == PlayerSetupRowRepresentable.State.POSITION_ONLY) View.GONE else View.VISIBLE + + itemView.handEditText.setText(setup.playerSetup?.cards?.formatted(itemView.context)) + itemView.stackEditText.setText(setup.playerSetup?.stack?.formatted()) + + this.positionAdapter.positions = listOf() // TODO + +// itemView.handEditText.setText(adapter.dataSource.stringForRow(row, itemView.context, 0)) +// itemView.stackEditText.setText(adapter.dataSource.stringForRow(row, itemView.context, 1)) + + } + + override fun positionSelected(position: Position) { - itemView.handEditText.setText(adapter.dataSource.stringForRow(row, itemView.context, 0)) - itemView.stackEditText.setText(adapter.dataSource.stringForRow(row, itemView.context, 1)) + // TODO sets position for PlayerSetup } 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 670d5ec1..4e46d2fc 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 @@ -187,6 +187,10 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra rows.add(StraddleRowRepresentable(positions, this.straddlePositions)) } + this.playerSetups().forEach { + rows.add(it) + } + Street.values().forEach { street -> val actions = this.sortedActions.filter { it.street == street } @@ -572,4 +576,26 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra } + private fun playerSetups(): List { + + val hh = this.handHistory + + val arrangedSetups = hh.playerSetups.sortedBy { it.position }.map { PlayerSetupRowRepresentable(playerSetup = it) }.toMutableList() + val heroSetup = arrangedSetups.firstOrNull { it.playerSetup?.position == hh.heroIndex } + heroSetup?.let { + it.hero = true + arrangedSetups.remove(it) + arrangedSetups.add(0, it) + } ?: run { + arrangedSetups.add(PlayerSetupRowRepresentable(true, null)) + } + + if (arrangedSetups.size < hh.numberOfPlayers) { + arrangedSetups.add(PlayerSetupRowRepresentable(false, null)) + } + + return arrangedSetups + + } + } \ No newline at end of file diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRowRepresentable.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRowRepresentable.kt new file mode 100644 index 00000000..bb5108ba --- /dev/null +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRowRepresentable.kt @@ -0,0 +1,46 @@ +package net.pokeranalytics.android.ui.modules.handhistory.model + +import android.content.Context +import net.pokeranalytics.android.R +import net.pokeranalytics.android.model.handhistory.Position +import net.pokeranalytics.android.model.realm.handhistory.PlayerSetup +import net.pokeranalytics.android.ui.modules.handhistory.HandRowType +import net.pokeranalytics.android.ui.view.RowRepresentable + +class PlayerSetupRowRepresentable(var hero: Boolean = false, var playerSetup: PlayerSetup? = null) : + RowRepresentable { + + var positionEdited: Boolean = false + var position: Position? = null + + enum class State { + POSITION_ONLY, + SHOW_POSITION, + DEFAULT, + } + + val state: State + get() { + return when { + this.positionEdited -> State.SHOW_POSITION + (this.playerSetup == null) -> State.POSITION_ONLY + else -> State.DEFAULT + } + } + + fun title(context: Context): String { + return if (this.hero) { + context.getString(R.string.hero) + } else { + this.playerSetup?.player?.name?.let { + it + } ?: run { + context.getString(R.string.vilain) + } + } + } + + override val viewType: Int = HandRowType.PLAYER_SETUP.ordinal + + +} \ No newline at end of file diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardContainer.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardContainer.kt index 7a935bd3..7e55fd01 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardContainer.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/KeyboardContainer.kt @@ -14,7 +14,7 @@ import net.pokeranalytics.android.model.realm.handhistory.Card import net.pokeranalytics.android.ui.modules.handhistory.model.HHKeyboard -interface KeyboardListener { +interface KeyboardListener : PositionSelectionListener { fun actionSelected(action: Action.Type) fun amountChanged(amount: String?) fun amountValidated() @@ -25,6 +25,9 @@ interface KeyboardListener { fun cardBackSpaceSelected() fun cardSelectionEnded() fun closeKeyboard() +} + +interface PositionSelectionListener { fun positionSelected(position: Position) } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/PositionAdapter.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/PositionAdapter.kt index 30a12bff..44560fc3 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/PositionAdapter.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/views/PositionAdapter.kt @@ -14,7 +14,7 @@ import net.pokeranalytics.android.ui.view.RowViewType import net.pokeranalytics.android.ui.view.holder.RowViewHolder import timber.log.Timber -class PositionAdapter(var keyboardListener: KeyboardListener) : +class PositionAdapter(var listener: PositionSelectionListener) : RecyclerView.Adapter(), RowRepresentableDataSource, RowRepresentableDelegate, RecyclerAdapter { @@ -61,7 +61,7 @@ class PositionAdapter(var keyboardListener: KeyboardListener) : override fun onRowSelected(position: Int, row: RowRepresentable, tag: Int) { Timber.d("/////onRowSelected") - keyboardListener.positionSelected(this.positions[position]) + this.listener.positionSelected(this.positions[position]) } } \ 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 bef4aa99..9d74711c 100644 --- a/app/src/main/res/layout/row_hhsettings_player_setup.xml +++ b/app/src/main/res/layout/row_hhsettings_player_setup.xml @@ -1,20 +1,41 @@ - + android:layout_height="wrap_content" + android:layout_marginStart="8dp" /> + + + + + + r_allin mississipi + vilain