From 3acb0f02ef54eb6694514e211e9a08dd995a4a83 Mon Sep 17 00:00:00 2001 From: Laurent Date: Fri, 6 Mar 2020 11:55:42 +0100 Subject: [PATCH] Refactor the way PlayerSetups are added --- .../modules/handhistory/HandHistoryAdapter.kt | 118 ++++++++--------- .../handhistory/HandHistoryFragment.kt | 36 ++--- .../modules/handhistory/model/ActionList.kt | 16 +-- .../handhistory/model/ActionReadRow.kt | 8 +- .../handhistory/model/ComputedAction.kt | 27 +--- .../handhistory/model/HandHistoryRow.kt | 7 +- .../handhistory/model/HandHistoryViewModel.kt | 123 ++++++------------ .../handhistory/model/PlayerCardsRow.kt | 25 ++-- .../handhistory/model/PlayerSetupRow.kt | 12 +- app/src/main/res/layout/row_hand_action.xml | 12 +- .../main/res/layout/row_hand_action_read.xml | 12 +- .../layout/row_hhsettings_player_setup.xml | 6 - ...sition.xml => row_hhsettings_position.xml} | 1 - 13 files changed, 168 insertions(+), 235 deletions(-) rename app/src/main/res/layout/{row_hhsettings_hero_position.xml => row_hhsettings_position.xml} (93%) 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 e03e84b3..18f4279c 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 @@ -21,11 +21,14 @@ import kotlinx.android.synthetic.main.row_hhsettings_player_setup.view.* import kotlinx.android.synthetic.main.row_hhsettings_player_setup.view.position_button import kotlinx.android.synthetic.main.row_hhsettings_player_setup.view.ps_hand_layout import kotlinx.android.synthetic.main.row_hhsettings_player_setup.view.settings_container +import kotlinx.android.synthetic.main.row_hhsettings_player_setup.view.title import kotlinx.android.synthetic.main.row_hhsettings_player_setup_read.view.* +import kotlinx.android.synthetic.main.row_hhsettings_position.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.Player import net.pokeranalytics.android.model.realm.handhistory.Card import net.pokeranalytics.android.ui.adapter.BindableHolder import net.pokeranalytics.android.ui.adapter.RecyclerAdapter @@ -56,7 +59,8 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable { ANTE(R.layout.row_title_value), BIG_BLIND_ANTE(R.layout.row_title_switch), ACTION_READ(R.layout.row_hand_action_read), - HERO_POSITION(R.layout.row_hhsettings_hero_position) + HERO_POSITION(R.layout.row_hhsettings_position), + PLAYER_POSITION(R.layout.row_hhsettings_position) ; override val viewType: Int = this.ordinal @@ -122,7 +126,7 @@ class HandHistoryAdapter( HandRowType.PLAYER_SETUP_READ -> RowReadOnlyPlayerSetupHolder(layout) HandRowType.COMMENT -> RowViewHolder(layout) HandRowType.ACTION_READ -> RowActionReadHolder(layout) - HandRowType.HERO_POSITION -> RowPositionHolder(layout) + HandRowType.HERO_POSITION, HandRowType.PLAYER_POSITION -> RowPositionHolder(layout) HandRowType.PLAYER_NUMBER, HandRowType.ANTE, HandRowType.BIG_BLIND_ANTE -> RowViewHolder(layout) } } @@ -264,6 +268,25 @@ class HandHistoryAdapter( return itemView.findViewWithTag(tag) } + protected fun configurePlayerImage(playerImageView: PlayerImageView, position: Int, row: RowRepresentable) { + + // Player + val listener = View.OnClickListener { + delegate?.onItemClick(position, row, playerImageView.tag as Int) + } + playerImageView.setOnImageClickListener(listener) + + val size = PlayerImageView.Size.SMALL + + val players = dataSource.contentForRow(row, itemView.context, Player::class) + if (players.isNotEmpty()) { + playerImageView.setPlayer(players.first(), size) + } else { + playerImageView.clear(size) + } + + } + protected fun configureCardsLayout(layout: LinearLayout) { layout.removeAllViews() @@ -324,29 +347,37 @@ class HandHistoryAdapter( } } + inner class RowActionReadHolder(itemView: View) : RowHandHolder(itemView) { + + init { + itemView.player_image_rhar.tag = ActionReadRow.Tag.PLAYER.ordinal + } + + override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { + + configurePlayerImage(itemView.player_image_rhar, position, row) + + val actionReadRow = row as ActionReadRow + itemView.playersText.text = actionReadRow.positions.joinToString(", ") { it.value } + itemView.actionText.text = actionReadRow.action?.localizedTitle(itemView.context) + itemView.amountText.text = actionReadRow.amount?.formatted() + + } + + } + /** * Display a hand action */ inner class RowActionHolder(itemView: View) : RowHandHolder(itemView) { init { + itemView.player_image_rha.tag = ComputedAction.Tag.PLAYER.ordinal itemView.actionButton.tag = ComputedAction.Tag.ACTION.ordinal itemView.amountEditText.tag = ComputedAction.Tag.AMOUNT.ordinal // Action setOnClickListener(itemView.actionButton) -// itemView.findViewById