Refactor the way PlayerSetups are added

hh
Laurent 6 years ago
parent eb049a8ed2
commit 3acb0f02ef
  1. 118
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  2. 36
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  3. 16
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt
  4. 8
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionReadRow.kt
  5. 27
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt
  6. 5
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryRow.kt
  7. 123
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  8. 25
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerCardsRow.kt
  9. 12
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerSetupRow.kt
  10. 12
      app/src/main/res/layout/row_hand_action.xml
  11. 12
      app/src/main/res/layout/row_hand_action_read.xml
  12. 6
      app/src/main/res/layout/row_hhsettings_player_setup.xml
  13. 1
      app/src/main/res/layout/row_hhsettings_position.xml

@ -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.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.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.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_player_setup_read.view.*
import kotlinx.android.synthetic.main.row_hhsettings_position.view.*
import kotlinx.android.synthetic.main.row_hhsettings_straddle.view.* import kotlinx.android.synthetic.main.row_hhsettings_straddle.view.*
import net.pokeranalytics.android.R import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PAIllegalStateException import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.handhistory.Position 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.model.realm.handhistory.Card
import net.pokeranalytics.android.ui.adapter.BindableHolder import net.pokeranalytics.android.ui.adapter.BindableHolder
import net.pokeranalytics.android.ui.adapter.RecyclerAdapter 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), ANTE(R.layout.row_title_value),
BIG_BLIND_ANTE(R.layout.row_title_switch), BIG_BLIND_ANTE(R.layout.row_title_switch),
ACTION_READ(R.layout.row_hand_action_read), 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 override val viewType: Int = this.ordinal
@ -122,7 +126,7 @@ class HandHistoryAdapter(
HandRowType.PLAYER_SETUP_READ -> RowReadOnlyPlayerSetupHolder(layout) HandRowType.PLAYER_SETUP_READ -> RowReadOnlyPlayerSetupHolder(layout)
HandRowType.COMMENT -> RowViewHolder(layout) HandRowType.COMMENT -> RowViewHolder(layout)
HandRowType.ACTION_READ -> RowActionReadHolder(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) HandRowType.PLAYER_NUMBER, HandRowType.ANTE, HandRowType.BIG_BLIND_ANTE -> RowViewHolder(layout)
} }
} }
@ -264,6 +268,25 @@ class HandHistoryAdapter(
return itemView.findViewWithTag(tag) 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) { protected fun configureCardsLayout(layout: LinearLayout) {
layout.removeAllViews() 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 * Display a hand action
*/ */
inner class RowActionHolder(itemView: View) : RowHandHolder(itemView) { inner class RowActionHolder(itemView: View) : RowHandHolder(itemView) {
init { init {
itemView.player_image_rha.tag = ComputedAction.Tag.PLAYER.ordinal
itemView.actionButton.tag = ComputedAction.Tag.ACTION.ordinal itemView.actionButton.tag = ComputedAction.Tag.ACTION.ordinal
itemView.amountEditText.tag = ComputedAction.Tag.AMOUNT.ordinal itemView.amountEditText.tag = ComputedAction.Tag.AMOUNT.ordinal
// Action // Action
setOnClickListener(itemView.actionButton) setOnClickListener(itemView.actionButton)
// itemView.findViewById<Button>(R.id.actionButton)?.let { actionButton ->
//
// setOnClickListener(actionButton)
// actionButton.setOnClickListener {
// actionButton.backgroundTintList = ColorStateList.valueOf(color(true))
//
// val row = dataSource.rowRepresentableForPosition(currentPosition)
// ?: throw PAIllegalStateException("Row Representable not found at index: $currentPosition")
// delegate?.onRowSelected(currentPosition, row, HHKeyboard.ACTION.ordinal)
// }
// }
// Amount // Amount
itemView.findViewById<EditText>(R.id.amountEditText)?.let { amountEditText -> itemView.findViewById<EditText>(R.id.amountEditText)?.let { amountEditText ->
@ -376,6 +407,8 @@ class HandHistoryAdapter(
val computedAction = row as ComputedAction val computedAction = row as ComputedAction
configurePlayerImage(itemView.player_image_rha, position, row)
// Position // Position
itemView.findViewById<Button>(R.id.positionButton)?.let { button -> itemView.findViewById<Button>(R.id.positionButton)?.let { button ->
button.text = computedAction.position.value button.text = computedAction.position.value
@ -406,19 +439,6 @@ class HandHistoryAdapter(
} }
inner class RowActionReadHolder(itemView: View) : RowHandHolder(itemView) {
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
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 street * Display a hand street
*/ */
@ -486,22 +506,6 @@ class HandHistoryAdapter(
} }
protected fun configurePlayerImage(playerImageView: PlayerImageView, position: Int, row: PlayerSetupRow) {
// Player
val listener = View.OnClickListener {
delegate?.onItemClick(position, row, playerImageView.tag as Int)
}
playerImageView.setOnImageClickListener(listener)
val size = PlayerImageView.Size.SMALL
row.playerSetup?.player?.let { player ->
playerImageView.setPlayer(player, size)
} ?: run {
playerImageView.clear(size)
}
}
} }
inner class RowReadOnlyPlayerSetupHolder(itemView: View) : AbstractRowHandPlayerSetup(itemView) { inner class RowReadOnlyPlayerSetupHolder(itemView: View) : AbstractRowHandPlayerSetup(itemView) {
@ -545,17 +549,18 @@ class HandHistoryAdapter(
this.positionAdapter.notifyDataSetChanged() this.positionAdapter.notifyDataSetChanged()
} }
val heroIndex = adapter.dataSource.intForRow(row) itemView.title.text = adapter.dataSource.charSequenceForRow(row, itemView.context)
positionAdapter.setSelectedPosition(heroIndex)
if (row == HandRowType.HERO_POSITION) {
val heroIndex = adapter.dataSource.intForRow(row)
positionAdapter.setSelectedPosition(heroIndex)
}
} }
} }
inner class RowPlayerSetupHolder(itemView: View) : AbstractRowHandPlayerSetup(itemView) { inner class RowPlayerSetupHolder(itemView: View) : AbstractRowHandPlayerSetup(itemView) {
private var positionAdapter: PositionAdapter = PositionAdapter()
private var positionViewManager: LinearLayoutManager
init { init {
itemView.player_image.tag = PlayerSetupRow.Tag.PLAYER.ordinal itemView.player_image.tag = PlayerSetupRow.Tag.PLAYER.ordinal
@ -565,13 +570,6 @@ class HandHistoryAdapter(
itemView.stack_edit_text.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL itemView.stack_edit_text.inputType = InputType.TYPE_NUMBER_FLAG_DECIMAL
setClickListener(itemView.stack_edit_text) setClickListener(itemView.stack_edit_text)
this.positionViewManager = LinearLayoutManager(itemView.context, RecyclerView.HORIZONTAL, false)
itemView.position_recycler.apply {
setHasFixedSize(true)
layoutManager = positionViewManager
adapter = positionAdapter
}
} }
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
@ -588,16 +586,6 @@ class HandHistoryAdapter(
val visibility = if (state == PlayerSetupRow.State.SETUP_ONLY && !setupRow.hero) View.GONE else View.VISIBLE val visibility = if (state == PlayerSetupRow.State.SETUP_ONLY && !setupRow.hero) View.GONE else View.VISIBLE
itemView.title.visibility = visibility itemView.title.visibility = visibility
// Position recycler
val posVisibility = if (state == PlayerSetupRow.State.SETUP_ONLY) View.GONE else View.VISIBLE
itemView.position_recycler.visibility = posVisibility
this.positionAdapter.positions = adapter.dataSource.contentForRow(row, itemView.context, Position::class)
this.positionAdapter.setOnClickListener { pos ->
setupRow.closePosition()
this.delegate?.onRowValueChanged(pos, row)
}
configureEditTexts(PlayerSetupRow.Tag.STACK.ordinal, position, row, adapter) configureEditTexts(PlayerSetupRow.Tag.STACK.ordinal, position, row, adapter)
} }

@ -362,27 +362,31 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.model.setHeroPosition(value as Position) this.model.setHeroPosition(value as Position)
this.handHistoryAdapter.notifyItemChanged(this.indexOfRowRepresentable(row)) this.handHistoryAdapter.notifyItemChanged(this.indexOfRowRepresentable(row))
} }
HandRowType.PLAYER_POSITION -> {
this.model.createPlayerSetupForPosition(value as Position)
this.handHistoryAdapter.notifyDataSetChanged()
}
is ComputedAction -> { is ComputedAction -> {
this.model.currentAmount = value as String this.model.currentAmount = value as String
} }
is StraddleRowRepresentable -> { is StraddleRowRepresentable -> {
this.model.changeStraddleSelection(value as LinkedHashSet<Position>) this.model.changeStraddleSelection(value as LinkedHashSet<Position>)
} }
is PlayerSetupRow -> { // is PlayerSetupRow -> {
when (value) { // when (value) {
is Position -> { // is Position -> {
this.model.setPlayerSetupPosition(row, value) // this.model.setPlayerSetupPosition(row, value)
val index = this.indexOfRowRepresentable(row) // val index = this.indexOfRowRepresentable(row)
this.handHistoryAdapter.notifyItemChanged(index) // this.handHistoryAdapter.notifyItemChanged(index)
//
// Change the focus only for the row, don't look elsewhere // // Change the focus only for the row, don't look elsewhere
// val anyEmpty = row.tagsForCompletion().any { row.isFieldNeedsInput(it, this.model.handHistory) } //// val anyEmpty = row.tagsForCompletion().any { row.isFieldNeedsInput(it, this.model.handHistory) }
// if (anyEmpty) { //// if (anyEmpty) {
// this.findNextActionToEdit(index) //// this.findNextActionToEdit(index)
// } //// }
} // }
} // }
} // }
} }
} }
@ -394,7 +398,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
is PlayerSetupRow -> { is PlayerSetupRow -> {
when (tag) { when (tag) {
PlayerSetupRow.Tag.PLAYER.ordinal -> { PlayerSetupRow.Tag.PLAYER.ordinal -> {
this.model.clickPosition = position this.model.clickPlayerPosition = position
DataListActivity.newDialogInstance(this, LiveData.PLAYER, true) DataListActivity.newDialogInstance(this, LiveData.PLAYER, true)
} }
else -> { else -> {

@ -271,7 +271,7 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
private fun getLastPlayerAction(index: Int): ComputedAction? { private fun getLastPlayerAction(index: Int): ComputedAction? {
val action = this[index].action val action = this[index].action
val previousActions = this.take(index) val previousActions = this.take(index)
return previousActions.lastOrNull { it.action.position == action.position } return previousActions.lastOrNull { it.positionIndex == action.position }
} }
/*** /***
@ -473,7 +473,7 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
created = true created = true
} }
playerSetup.stack = this.filter { it.action.position == positionIndex }.sumByDouble { it.action.effectiveAmount } playerSetup.stack = this.filter { it.positionIndex == positionIndex }.sumByDouble { it.action.effectiveAmount }
if (created) { if (created) {
this.listener.playerSetupCreated() this.listener.playerSetupCreated()
@ -500,7 +500,7 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
* Returns whether the player at [position] is all-in and its amount is set * Returns whether the player at [position] is all-in and its amount is set
*/ */
fun isPlayerAllinWithAmount(position: Int): Boolean { fun isPlayerAllinWithAmount(position: Int): Boolean {
val computedAction = this.lastOrNull { it.action.position == position && it.action.type?.isAllin == true } val computedAction = this.lastOrNull { it.positionIndex == position && it.action.type?.isAllin == true }
return computedAction?.action?.amount != null return computedAction?.action?.amount != null
} }
@ -607,17 +607,17 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
} }
/*** /***
* Recomputes all remaining stacks for the given [positions] * Recomputes all remaining stacks for the given [positionIndexes]
*/ */
fun updateRemainingStacksForPositions(positions: List<Int>) { fun updateRemainingStacksForPositions(positionIndexes: List<Int>) {
val ante = if (this.handHistory.bigBlindAnte) this.handHistory.bigBlind ?: 0.0 else this.handHistory.ante val ante = if (this.handHistory.bigBlindAnte) this.handHistory.bigBlind ?: 0.0 else this.handHistory.ante
positions.forEach { position -> positionIndexes.forEach { posIndex ->
this.handHistory.playerSetupForPosition(position)?.stack?.let { initialStack -> this.handHistory.playerSetupForPosition(posIndex)?.stack?.let { initialStack ->
var remainingStack = initialStack - ante var remainingStack = initialStack - ante
val playerActions = this.filter { it.action.position == position } val playerActions = this.filter { it.positionIndex == posIndex }
playerActions.forEach { playerActions.forEach {
remainingStack -= it.action.effectiveAmount remainingStack -= it.action.effectiveAmount
it.playerRemainingStack = remainingStack it.playerRemainingStack = remainingStack

@ -5,7 +5,13 @@ import net.pokeranalytics.android.model.realm.handhistory.Action
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
class ActionReadRow(var positions: MutableList<Position>, var action: Action.Type?, var amount: Double?) : RowRepresentable { class ActionReadRow(var positions: MutableList<Position>,
var action: Action.Type?,
var amount: Double?) : RowRepresentable {
enum class Tag {
PLAYER
}
override val viewType: Int = HandRowType.ACTION_READ.ordinal override val viewType: Int = HandRowType.ACTION_READ.ordinal

@ -34,9 +34,10 @@ class ComputedAction(var manager: ActionManager,
var totalPotSize: Double = 0.0, var totalPotSize: Double = 0.0,
var playerRemainingStack: Double? = null, var playerRemainingStack: Double? = null,
var position: Position var position: Position
) : HandHistoryRow { ) : HandHistoryRow, PositionalRow {
enum class Tag { enum class Tag {
PLAYER,
ACTION, ACTION,
AMOUNT AMOUNT
} }
@ -177,27 +178,6 @@ class ComputedAction(var manager: ActionManager,
} }
} }
/***
* Returns a keyboard to complete the action, or null if the action is filled
* All ComputedAction should have a type, so we return the action keyboard if the type is null
* If the action has a type, we return the amount keyboard if the action requires one
*/
// override fun tagForCompletion(
// handHistory: HandHistory,
// minTag: Int?
// ): Int? {
// Timber.d("index = ${action.index} / type = ${this.action.type} / amount = ${this.action.amount}")
// return if (this.action.type != null) {
// if (this.requiresAmount) {
// Tag.AMOUNT.ordinal
// } else {
// null
// }
// } else {
// Tag.ACTION.ordinal
// }
// }
override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean { override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean {
return when (tag) { return when (tag) {
Tag.ACTION.ordinal -> this.action.type == null Tag.ACTION.ordinal -> this.action.type == null
@ -300,4 +280,7 @@ class ComputedAction(var manager: ActionManager,
return ActionReadRow(mutableListOf(this.position), this.action.type, this.action.amount) return ActionReadRow(mutableListOf(this.position), this.action.type, this.action.amount)
} }
override val positionIndex: Int
get() { return this.action.position }
} }

@ -3,7 +3,6 @@ package net.pokeranalytics.android.ui.modules.handhistory.model
import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
interface HandHistoryRow : RowRepresentable { interface HandHistoryRow : RowRepresentable {
fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean
@ -16,3 +15,7 @@ interface HandHistoryRow : RowRepresentable {
fun onSelect(tag: Int) {} fun onSelect(tag: Int) {}
} }
interface PositionalRow {
val positionIndex: Int
}

@ -12,7 +12,10 @@ import net.pokeranalytics.android.model.handhistory.Position
import net.pokeranalytics.android.model.handhistory.Street import net.pokeranalytics.android.model.handhistory.Street
import net.pokeranalytics.android.model.realm.Player import net.pokeranalytics.android.model.realm.Player
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.model.realm.handhistory.* import net.pokeranalytics.android.model.realm.handhistory.Action
import net.pokeranalytics.android.model.realm.handhistory.Card
import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.model.realm.handhistory.formatted
import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource import net.pokeranalytics.android.ui.adapter.RowRepresentableDataSource
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
import net.pokeranalytics.android.ui.modules.handhistory.views.CardCentralizer import net.pokeranalytics.android.ui.modules.handhistory.views.CardCentralizer
@ -125,7 +128,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
/*** /***
* The position of a click * The position of a click
*/ */
var clickPosition: Int? = null var clickPlayerPosition: Int? = null
/*** /***
* The board cards sorted by position * The board cards sorted by position
@ -244,7 +247,6 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
position, position,
positionIndex, positionIndex,
this.handHistory, this.handHistory,
this.handHistory.playerSetupForPosition(positionIndex),
this.playerHandMaxCards) this.playerHandMaxCards)
rows.add(playerCardsRow) rows.add(playerCardsRow)
} }
@ -288,8 +290,14 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
rows.add(StraddleRowRepresentable(positions, this.straddlePositions)) rows.add(StraddleRowRepresentable(positions, this.straddlePositions))
} }
// Used to set the hero position
rows.add(HandRowType.HERO_POSITION) rows.add(HandRowType.HERO_POSITION)
// Used to select an available position to set details for that position
if (this.handHistory.playerSetups.size < this.handHistory.numberOfPlayers) {
rows.add(HandRowType.PLAYER_POSITION)
}
this.playerSetups().forEach { this.playerSetups().forEach {
rows.add(it) rows.add(it)
} }
@ -312,7 +320,6 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
position, position,
positionIndex, positionIndex,
this.handHistory, this.handHistory,
this.handHistory.playerSetupForPosition(positionIndex),
this.playerHandMaxCards) this.playerHandMaxCards)
rows.add(playerCardsRow) rows.add(playerCardsRow)
} }
@ -428,12 +435,6 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
} }
} }
// if (index >= startIndex && rowRepresentable is HandHistoryRow) {
// val tag = rowRepresentable.tagForCompletion(this.handHistory, minTag)
// if (tag != null) {
// return HHSelection(index, tag)
// }
// }
} }
return null return null
} }
@ -470,19 +471,6 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
val row = this.rowRepresentables[this.currentSelection.index] val row = this.rowRepresentables[this.currentSelection.index]
when (row) { when (row) {
// HandRowType.BLINDS -> {
// when (this.currentSelection.tag) {
// 0 -> {
// this.handHistory.smallBlind = amount
// this.sortedActions.updateBlinds()
// }
// 1 -> {
// this.handHistory.bigBlind = amount
// this.sortedActions.updateBlinds()
// }
// 2 -> this.handHistory.ante = amount ?: 0.0
// }
// }
is ComputedAction -> { is ComputedAction -> {
amount?.let { amount?.let {
this.sortedActions.setAmount(this.actionIndexForSelection, amount) this.sortedActions.setAmount(this.actionIndexForSelection, amount)
@ -685,9 +673,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
is PlayerSetupRow -> { is PlayerSetupRow -> {
when (tag) { when (tag) {
PlayerSetupRow.Tag.STACK.ordinal -> { PlayerSetupRow.Tag.STACK.ordinal -> {
row.playerSetup?.position?.let { !this.sortedActions.isPlayerAllinWithAmount(row.positionIndex)
!this.sortedActions.isPlayerAllinWithAmount(it)
} ?: run { true }
} }
else -> true else -> true
} }
@ -707,7 +693,6 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
override fun isFocusable(position: Int, row: RowRepresentable, tag: Int): Boolean { override fun isFocusable(position: Int, row: RowRepresentable, tag: Int): Boolean {
return when (row) { return when (row) {
// HandRowType.BLINDS -> this.isSelected(position, row, tag)
is ComputedAction -> { is ComputedAction -> {
val isSelected = this.isSelected(position, row, tag) val isSelected = this.isSelected(position, row, tag)
when (tag) { when (tag) {
@ -735,19 +720,13 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
HandRowType.PLAYER_NUMBER -> this.handHistory.numberOfPlayers.toString() HandRowType.PLAYER_NUMBER -> this.handHistory.numberOfPlayers.toString()
HandRowType.COMMENT -> this.handHistory.comment ?: context.getString(R.string.comment) HandRowType.COMMENT -> this.handHistory.comment ?: context.getString(R.string.comment)
HandRowType.ANTE -> this.handHistory.ante.formatted() HandRowType.ANTE -> this.handHistory.ante.formatted()
// HandRowType.BLINDS -> { HandRowType.HERO_POSITION -> context.getString(R.string.set_hero_position)
// when (tag) { HandRowType.PLAYER_POSITION -> context.getString(R.string.set_position_details)
// 0 -> this.handHistory.smallBlind?.formatted()
// 1 -> this.handHistory.bigBlind?.formatted()
// 2 -> this.handHistory.ante.formatted()
// else -> throw PAIllegalStateException("Unmanaged case with $row, tag = $tag")
// }
// }
is ComputedAction -> row.action.formattedAmount is ComputedAction -> row.action.formattedAmount
is StreetCardsRow -> row.cardsForTag(tag)?.formatted(context) is StreetCardsRow -> row.cardsForTag(tag)?.formatted(context)
is PlayerSetupRow -> { is PlayerSetupRow -> {
when (tag) { when (tag) {
PlayerSetupRow.Tag.POSITION.ordinal -> row.position?.value PlayerSetupRow.Tag.POSITION.ordinal -> row.position.value
PlayerSetupRow.Tag.HAND.ordinal -> row.cardHolder?.cards?.formatted(context) PlayerSetupRow.Tag.HAND.ordinal -> row.cardHolder?.cards?.formatted(context)
PlayerSetupRow.Tag.STACK.ordinal -> row.playerSetup?.stack?.formatted() PlayerSetupRow.Tag.STACK.ordinal -> row.playerSetup?.stack?.formatted()
else -> throw PAIllegalStateException("Unmanaged case with $row, tag = $tag") else -> throw PAIllegalStateException("Unmanaged case with $row, tag = $tag")
@ -764,10 +743,13 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
override fun <T : Any> contentForRow(row: RowRepresentable, context: Context, clazz: KClass<T>) : List<T> { override fun <T : Any> contentForRow(row: RowRepresentable, context: Context, clazz: KClass<T>) : List<T> {
when (clazz) { when (clazz) {
Position::class -> { Position::class -> {
return this.handHistory.undefinedPositions() as List<T> return when (row) {
HandRowType.HERO_POSITION -> this.sortedActions.positions.toList() as List<T>
HandRowType.PLAYER_POSITION -> this.handHistory.undefinedPositions() as List<T>
else -> throw PAIllegalStateException("undefined contentForRow:Position for $row")
}
} }
Card::class -> { Card::class -> {
val cards = when (row) { val cards = when (row) {
is StreetCardsRow -> { is StreetCardsRow -> {
this.handHistory.cardsForStreet(row.street) this.handHistory.cardsForStreet(row.street)
@ -782,6 +764,11 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
} }
return (cards ?: listOf<Card>()) as List<T> return (cards ?: listOf<Card>()) as List<T>
} }
Player::class -> {
val position = (row as PositionalRow).positionIndex
val player = this.handHistory.playerSetupForPosition(position)?.player
return player?.let { listOf(it) as List<T> } ?: listOf()
}
} }
return listOf() return listOf()
} }
@ -837,7 +824,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
val hh = this.handHistory val hh = this.handHistory
return hh.playerSetups.sortedBy { it.position }.map { return hh.playerSetups.sortedBy { it.position }.map {
val position = this.positionForIndex(it.position) val position = this.positionForIndex(it.position)
createPlayerSetupRow(it, position, hero = false, readMode = true) createPlayerSetupRow(position, it.position, hero = false, readMode = true)
} }
} }
@ -851,27 +838,15 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
val hh = this.handHistory val hh = this.handHistory
val arrangedSetups = mutableListOf<PlayerSetupRow>() val arrangedSetups = mutableListOf<PlayerSetupRow>()
if (hh.playerSetups.size < hh.numberOfPlayers) {
arrangedSetups.add(createPlayerSetupRow(hero = false))
}
val existingSetups = hh.playerSetups.sortedBy { it.position }.map { val existingSetups = hh.playerSetups.sortedBy { it.position }.map {
val position = this.positionForIndex(it.position) val position = this.positionForIndex(it.position)
val hero = (it.position == hh.heroIndex) val hero = (it.position == hh.heroIndex)
createPlayerSetupRow(it, position, hero) createPlayerSetupRow(position, it.position, hero)
} }
arrangedSetups.addAll(existingSetups) arrangedSetups.addAll(existingSetups)
// val heroSetup = arrangedSetups.firstOrNull { it.playerSetup?.position == hh.heroIndex }
// heroSetup?.let {
// it.hero = true
// arrangedSetups.remove(it)
// arrangedSetups.add(0, it)
// } ?: run {
// arrangedSetups.add(0, createPlayerSetupRow(hero = true))
// }
return arrangedSetups return arrangedSetups
} }
@ -879,43 +854,23 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
* Convenience method to create a PlayerSetupRow * Convenience method to create a PlayerSetupRow
*/ */
private fun createPlayerSetupRow( private fun createPlayerSetupRow(
playerSetup: PlayerSetup? = null, position: Position,
position: Position? = null, positionIndex: Int,
hero: Boolean, hero: Boolean,
readMode: Boolean = false readMode: Boolean = false
): PlayerSetupRow { ): PlayerSetupRow {
return PlayerSetupRow(hero, readMode, position, playerSetup?.position, this.handHistory, playerSetup, this.playerHandMaxCards) return PlayerSetupRow(hero, readMode, position, positionIndex, this.handHistory, this.playerHandMaxCards)
} }
/*** /***
* Sets both positionIndex and [position] for a PlayerSetup inside a [playerSetupRow] * Sets both positionIndex and [position] for a PlayerSetup inside a [playerSetupRow]
*/ */
fun setPlayerSetupPosition(playerSetupRow: PlayerSetupRow, position: Position) { fun createPlayerSetupForPosition(position: Position) {
val positionIndex = this.sortedActions.positions.indexOf(position) val positionIndex = this.sortedActions.positions.indexOf(position)
var setupCreated = false this.handHistory.createPlayerSetup(positionIndex)
playerSetupRow.playerSetup?.let { playerSetup ->
playerSetup.position = positionIndex
} ?: run {
playerSetupRow.playerSetup = this.handHistory.createPlayerSetup(positionIndex)
setupCreated = true
}
playerSetupRow.position = position
if (!playerSetupRow.hero && setupCreated) {
if (this.handHistory.undefinedPositions().isNotEmpty()) {
val newPlayerRow = createPlayerSetupRow(hero = false)
val index = this.indexOfRowRepresentable(playerSetupRow)
this.rowsLiveData.value?.add(index + 1, newPlayerRow)
}
}
if (playerSetupRow.hero) {
this.handHistory.heroIndex = positionIndex
}
// refresh rows
this.createRowRepresentation()
} }
/*** /***
@ -926,7 +881,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
} }
/*** /***
* Sets the ante value * Sets the [ante] value
*/ */
fun setAnte(ante: Double) { fun setAnte(ante: Double) {
this.handHistory.ante = ante this.handHistory.ante = ante
@ -943,8 +898,11 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
this.sortedActions.updateBigBlindRemainingStack() this.sortedActions.updateBigBlindRemainingStack()
} }
/***
* Defines the [player] at the saved [clickPlayerPosition]
*/
fun playerSelected(player: Player) { fun playerSelected(player: Player) {
this.clickPosition?.let { position -> this.clickPlayerPosition?.let { position ->
when (val row = this.rowRepresentables[position]) { when (val row = this.rowRepresentables[position]) {
is PlayerSetupRow -> { is PlayerSetupRow -> {
@ -958,6 +916,9 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
} ?: throw PAIllegalStateException("Click position not set for player selection") } ?: throw PAIllegalStateException("Click position not set for player selection")
} }
/***
* Sets the heroIndex based on the given [position]
*/
fun setHeroPosition(position: Position) { fun setHeroPosition(position: Position) {
this.handHistory.heroIndex = this.sortedActions.positions.indexOf(position) this.handHistory.heroIndex = this.sortedActions.positions.indexOf(position)
} }

@ -1,39 +1,33 @@
package net.pokeranalytics.android.ui.modules.handhistory.model package net.pokeranalytics.android.ui.modules.handhistory.model
import io.realm.Realm import io.realm.Realm
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.handhistory.Position import net.pokeranalytics.android.model.handhistory.Position
import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.model.realm.handhistory.PlayerSetup import net.pokeranalytics.android.model.realm.handhistory.PlayerSetup
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
open class PlayerCardsRow(private var playerSetupCreationListener: PlayerSetupCreationListener?, open class PlayerCardsRow(private var playerSetupCreationListener: PlayerSetupCreationListener?,
var position: Position?, var position: Position,
private var positionIndex: Int?, override var positionIndex: Int,
private var handHistory: HandHistory, private var handHistory: HandHistory,
var playerSetup: PlayerSetup?, var maxCards: Int? = null) : CardsRow(), PositionalRow {
var maxCards: Int? = null) : CardsRow() {
constructor(position: Position?, constructor(position: Position,
positionIndex: Int?, positionIndex: Int,
handHistory: HandHistory, handHistory: HandHistory,
playerSetup: PlayerSetup?, maxCards: Int? = null) : this(null, position, positionIndex, handHistory, maxCards)
maxCards: Int? = null) : this(null, position, positionIndex, handHistory, playerSetup, maxCards)
enum class Tag { enum class Tag {
CARDS CARDS
} }
override val cardHolder: CardHolder? override val cardHolder: CardHolder?
get() { return this.playerSetup } get() { return this.handHistory.playerSetupForPosition(this.positionIndex) }
override val viewType: Int = HandRowType.PLAYER_SUMMARY.ordinal override val viewType: Int = HandRowType.PLAYER_SUMMARY.ordinal
override fun createHolder() { override fun createHolder() {
val position = this.positionIndex this.handHistory.createPlayerSetup(this.positionIndex)
?: throw PAIllegalStateException("Can't create a PlayerSetup without a position")
this.playerSetup = this.handHistory.createPlayerSetup(position)
} }
override fun cardLimit() : Int? { override fun cardLimit() : Int? {
@ -51,4 +45,7 @@ open class PlayerCardsRow(private var playerSetupCreationListener: PlayerSetupCr
return listOf(Tag.CARDS.ordinal) return listOf(Tag.CARDS.ordinal)
} }
val playerSetup: PlayerSetup?
get() { return this.handHistory.playerSetupForPosition(this.positionIndex) }
} }

@ -5,17 +5,15 @@ import net.pokeranalytics.android.R
import net.pokeranalytics.android.exceptions.PAIllegalStateException import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.model.handhistory.Position import net.pokeranalytics.android.model.handhistory.Position
import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import net.pokeranalytics.android.model.realm.handhistory.PlayerSetup
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
class PlayerSetupRow(var hero: Boolean = false, class PlayerSetupRow(var hero: Boolean = false,
var readMode: Boolean = false, private var readMode: Boolean = false,
position: Position?, position: Position,
positionIndex: Int?, positionIndex: Int,
handHistory: HandHistory, handHistory: HandHistory,
playerSetup: PlayerSetup?,
maxCards: Int? = null) : maxCards: Int? = null) :
PlayerCardsRow(position, positionIndex, handHistory, playerSetup, maxCards) { PlayerCardsRow(position, positionIndex, handHistory, maxCards) {
enum class State { enum class State {
POSITIONS_ONLY, POSITIONS_ONLY,
@ -52,7 +50,7 @@ class PlayerSetupRow(var hero: Boolean = false,
setup.player?.name?.let { setup.player?.name?.let {
it it
} ?: run { } ?: run {
this.position?.value this.position.value
} }
} ?: run { } ?: run {
context.getString(R.string.set_position_details) context.getString(R.string.set_position_details)

@ -4,12 +4,12 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<com.google.android.material.button.MaterialButton <net.pokeranalytics.android.ui.view.PlayerImageView
android:id="@+id/player_button" android:id="@+id/player_image_rha"
style="@style/PokerAnalyticsTheme.HHButton" android:layout_marginStart="8dp"
android:layout_width="44dp" android:layout_width="48dp"
android:layout_height="44dp" android:layout_height="48dp"
android:layout_marginStart="8dp"/> android:background="@android:color/transparent" />
<com.google.android.material.button.MaterialButton <com.google.android.material.button.MaterialButton
android:id="@+id/positionButton" android:id="@+id/positionButton"

@ -5,12 +5,12 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<com.google.android.material.button.MaterialButton <net.pokeranalytics.android.ui.view.PlayerImageView
android:id="@+id/player_button" android:id="@+id/player_image_rhar"
style="@style/PokerAnalyticsTheme.HHButton" android:layout_marginStart="8dp"
android:layout_width="44dp" android:layout_width="48dp"
android:layout_height="44dp" android:layout_height="48dp"
android:layout_marginStart="8dp"/> android:background="@android:color/transparent" />
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/playersText" android:id="@+id/playersText"

@ -12,12 +12,6 @@
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_marginStart="8dp" /> android:layout_marginStart="8dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/position_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<LinearLayout <LinearLayout
android:id="@+id/settings_container" android:id="@+id/settings_container"
android:layout_width="match_parent" android:layout_width="match_parent"

@ -6,7 +6,6 @@
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/title" android:id="@+id/title"
android:text="@string/set_hero_position"
style="@style/PokerAnalyticsTheme.TextView.RowTitle" style="@style/PokerAnalyticsTheme.TextView.RowTitle"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
Loading…
Cancel
Save