Highlights hero

hh
Laurent 6 years ago
parent 65015641ba
commit 1338e21da1
  1. 9
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt
  2. 2
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt
  3. 9
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  4. 20
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  5. 7
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt
  6. 4
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionReadRow.kt
  7. 7
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt
  8. 1
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryRow.kt
  9. 16
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  10. 5
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/PlayerCardsRow.kt

@ -15,21 +15,22 @@ import net.pokeranalytics.android.util.extensions.formatted
* An extension to transform a list of ComputedAction into * An extension to transform a list of ComputedAction into
* a more compact and read-friendly list of ActionReadRow * a more compact and read-friendly list of ActionReadRow
*/ */
fun List<Action>.compact(positions: LinkedHashSet<Position>): List<ActionReadRow> { fun List<Action>.compact(positions: LinkedHashSet<Position>, heroIndex: Int?): List<ActionReadRow> {
val rows = mutableListOf<ActionReadRow>() val rows = mutableListOf<ActionReadRow>()
this.forEach { this.forEach {
if (it.type == Action.Type.FOLD && rows.lastOrNull()?.action == Action.Type.FOLD) { if (it.type == Action.Type.FOLD && rows.lastOrNull()?.action == Action.Type.FOLD) {
rows.lastOrNull()?.positions?.add(positions.elementAt(it.position)) rows.lastOrNull()?.positions?.add(positions.elementAt(it.position))
} else { } else {
rows.add(it.toReadRow(positions)) rows.add(it.toReadRow(positions, heroIndex))
} }
} }
return rows return rows
} }
fun Action.toReadRow(positions: LinkedHashSet<Position>): ActionReadRow { fun Action.toReadRow(positions: LinkedHashSet<Position>, heroIndex: Int?): ActionReadRow {
val pos = positions.elementAt(this.position) val pos = positions.elementAt(this.position)
return ActionReadRow(mutableListOf(pos), this.position, this.type, this.amount) val isHero = (heroIndex == this.position)
return ActionReadRow(mutableListOf(pos), this.position, this.type, this.amount, isHero)
} }
open class Action : RealmObject() { open class Action : RealmObject() {

@ -309,7 +309,7 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Identifiabl
string = string.addLineReturn(2) string = string.addLineReturn(2)
val streetActions = sortedActions.filter { it.street == street }.compact(positions) val streetActions = sortedActions.filter { it.street == street }.compact(positions, this.heroIndex)
if (streetActions.isNotEmpty()) { if (streetActions.isNotEmpty()) {
val streetItems = mutableListOf<CharSequence>(context.getString(street.resId)) val streetItems = mutableListOf<CharSequence>(context.getString(street.resId))

@ -448,6 +448,8 @@ class HandHistoryAdapter(
// 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
// button.setBackgroundColor(color(computedAction.isHero))
button.backgroundTintList = ColorStateList.valueOf(color(computedAction.isHero))
} }
// Action // Action
@ -509,6 +511,7 @@ class HandHistoryAdapter(
// Position // Position
itemView.findViewById<Button>(R.id.positionButton)?.let { positionButton -> itemView.findViewById<Button>(R.id.positionButton)?.let { positionButton ->
positionButton.text = playerCardView.position.value positionButton.text = playerCardView.position.value
positionButton.setBackgroundColor(color(playerCardView.isHero))
} }
configurePlayerImage(itemView.hps_player_image, position, row) configurePlayerImage(itemView.hps_player_image, position, row)
@ -530,10 +533,14 @@ class HandHistoryAdapter(
this.delegate = adapter.delegate this.delegate = adapter.delegate
// Position Button // Position Button
itemView.position_button.text = adapter.dataSource.charSequenceForRow(row, itemView.context, PlayerSetupRow.Tag.POSITION.ordinal) itemView.position_button.text = adapter.dataSource.charSequenceForRow(row, itemView.context, PlayerSetupRow.Tag.POSITION.ordinal)
val positionSelected = adapter.dataSource.isSelected(position, row, PlayerSetupRow.Tag.POSITION.ordinal) val positionSelected = adapter.dataSource.isSelected(position, row, PlayerSetupRow.Tag.POSITION.ordinal)
itemView.position_button.backgroundTintList = ColorStateList.valueOf(color(positionSelected)) // itemView.position_button.backgroundTintList = ColorStateList.valueOf(color(positionSelected))
val positionalRow = row as PositionalRow
itemView.position_button.backgroundTintList = ColorStateList.valueOf(color(positionalRow.isHero))
configureCardsLayout(itemView.ps_hand_layout, false) configureCardsLayout(itemView.ps_hand_layout, false)

@ -402,16 +402,18 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
override fun onItemClick(position: Int, row: RowRepresentable, tag: Int) { override fun onItemClick(position: Int, row: RowRepresentable, tag: Int) {
when (row) { when (row) {
is PlayerSetupRow -> { is PositionalRow -> {
when (tag) { this.model.tappedPlayerPositionIndex = row.positionIndex
PlayerSetupRow.Tag.PLAYER.ordinal -> {
this.model.clickPlayerPosition = position
DataListActivity.newDialogInstance(this, LiveData.PLAYER, true) DataListActivity.newDialogInstance(this, LiveData.PLAYER, true)
} // when (tag) {
else -> { // PlayerSetupRow.Tag.PLAYER.ordinal -> {
Timber.d("onItemClick not configured for row: $row, position: $position, tag: $tag") // this.model.clickPlayerPosition = position
} // DataListActivity.newDialogInstance(this, LiveData.PLAYER, true)
} // }
// else -> {
// Timber.d("onItemClick not configured for row: $row, position: $position, tag: $tag")
// }
// }
} }
} }

@ -18,6 +18,7 @@ interface ActionManager {
fun blindsUpdated(type: Action.Type, amount: Double) fun blindsUpdated(type: Action.Type, amount: Double)
fun minimumBetAmount(index: Int): Double fun minimumBetAmount(index: Int): Double
fun totalPotSize(index: Int): Double fun totalPotSize(index: Int): Double
val heroIndex: Int?
} }
interface ActionListListener : PlayerSetupCreationListener { interface ActionListListener : PlayerSetupCreationListener {
@ -72,6 +73,12 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
*/ */
var positions: LinkedHashSet<Position> = linkedSetOf() var positions: LinkedHashSet<Position> = linkedSetOf()
/***
* Returns the hero index
*/
override val heroIndex: Int?
get() { return this.handHistory.heroIndex }
/*** /***
* Selects an action type for the action at the provided [index] * Selects an action type for the action at the provided [index]
* In case of UNDEFINED_ALLIN, we define which type of allin it is. * In case of UNDEFINED_ALLIN, we define which type of allin it is.

@ -8,7 +8,8 @@ import net.pokeranalytics.android.ui.view.RowRepresentable
class ActionReadRow(var positions: MutableList<Position>, class ActionReadRow(var positions: MutableList<Position>,
override var positionIndex: Int, override var positionIndex: Int,
var action: Action.Type?, var action: Action.Type?,
var amount: Double?) : RowRepresentable, PositionalRow { var amount: Double?,
override val isHero: Boolean) : RowRepresentable, PositionalRow {
enum class Tag { enum class Tag {
PLAYER PLAYER
@ -16,4 +17,5 @@ class ActionReadRow(var positions: MutableList<Position>,
override val viewType: Int = HandRowType.ACTION_READ.ordinal override val viewType: Int = HandRowType.ACTION_READ.ordinal
} }

@ -42,6 +42,11 @@ class ComputedAction(var manager: ActionManager,
AMOUNT AMOUNT
} }
override val isHero: Boolean
get() {
return this.manager.heroIndex == this.action.position
}
/*** /***
* Returns whether the action requires the user to enter an amount for the selected action * Returns whether the action requires the user to enter an amount for the selected action
*/ */
@ -287,7 +292,7 @@ class ComputedAction(var manager: ActionManager,
* The "read mode" representation of the action * The "read mode" representation of the action
*/ */
fun toReadRow(): ActionReadRow { fun toReadRow(): ActionReadRow {
return ActionReadRow(mutableListOf(this.position), this.positionIndex, this.action.type, this.action.amount) return ActionReadRow(mutableListOf(this.position), this.positionIndex, this.action.type, this.action.amount, this.isHero)
} }
override val positionIndex: Int override val positionIndex: Int

@ -18,4 +18,5 @@ interface HandHistoryRow : RowRepresentable {
interface PositionalRow { interface PositionalRow {
val positionIndex: Int val positionIndex: Int
val isHero: Boolean
} }

@ -128,7 +128,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
/*** /***
* The position of a click * The position of a click
*/ */
var clickPlayerPosition: Int? = null var tappedPlayerPositionIndex: Int? = null
/*** /***
* The maximum number of cards in a player's hand * The maximum number of cards in a player's hand
@ -897,20 +897,14 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
} }
/*** /***
* Defines the [player] at the saved [clickPlayerPosition] * Defines the [player] at the saved [tappedPlayerPositionIndex]
*/ */
fun playerSelected(player: Player) { fun playerSelected(player: Player) {
this.clickPlayerPosition?.let { position -> this.tappedPlayerPositionIndex?.let { positionIndex ->
when (val row = this.rowRepresentables[position]) {
is PlayerSetupRow -> {
val playerSetup = row.playerSetup ?: this.handHistory.createPlayerSetup(position)
player.realm.executeTransaction { player.realm.executeTransaction {
playerSetup.player = player val ps = this.handHistory.playerSetupForPosition(positionIndex) ?: this.handHistory.createPlayerSetup(positionIndex)
ps.player = player
} }
}
}
} ?: throw PAIllegalStateException("Click position not set for player selection") } ?: throw PAIllegalStateException("Click position not set for player selection")
} }

@ -48,4 +48,9 @@ open class PlayerCardsRow(private var playerSetupCreationListener: PlayerSetupCr
val playerSetup: PlayerSetup? val playerSetup: PlayerSetup?
get() { return this.handHistory.playerSetupForPosition(this.positionIndex) } get() { return this.handHistory.playerSetupForPosition(this.positionIndex) }
override val isHero: Boolean
get() {
return this.handHistory.heroIndex == this.positionIndex
}
} }
Loading…
Cancel
Save