|
|
|
@ -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) |
|
|
|
} |
|
|
|
} |
|
|
|
|