|
|
|
|
@ -31,6 +31,16 @@ class HHSelection(var index: Int, var keyboard: HHKeyboard) |
|
|
|
|
|
|
|
|
|
class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentralizer, ActionListListener { |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* The hand history |
|
|
|
|
*/ |
|
|
|
|
private lateinit var handHistory: HandHistory |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
private var isNew: Boolean = true |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Indicates whether the hand history is being edited or not |
|
|
|
|
*/ |
|
|
|
|
@ -72,14 +82,19 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra |
|
|
|
|
var rowsLiveData: MutableLiveData<MutableList<RowRepresentable>> = MutableLiveData() |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* The hand history |
|
|
|
|
* All actions sorted by index |
|
|
|
|
*/ |
|
|
|
|
private lateinit var handHistory: HandHistory |
|
|
|
|
private var sortedActions: ActionList = ActionList(this) |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* All actions sorted by index |
|
|
|
|
* First Straddle selected |
|
|
|
|
*/ |
|
|
|
|
private var sortedActions: ActionList = ActionList(this) |
|
|
|
|
private var firstStraddlePosition: Position? = null |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* The hand setup |
|
|
|
|
*/ |
|
|
|
|
private var handSetup: HandSetup = HandSetup() |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* The board cards sorted by position |
|
|
|
|
@ -98,22 +113,35 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Configures a new HandHistory object using a [handSetup] |
|
|
|
|
* Straddle selected positions |
|
|
|
|
*/ |
|
|
|
|
private var straddlePositions: LinkedHashSet<Position> = linkedSetOf() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Creates and configures a new HandHistory object using a [handSetup] |
|
|
|
|
*/ |
|
|
|
|
fun configure(handSetup: HandSetup) { |
|
|
|
|
fun createNewHandHistory(handSetup: HandSetup) { |
|
|
|
|
|
|
|
|
|
this.handSetup = handSetup |
|
|
|
|
val handHistory = HandHistory() |
|
|
|
|
handHistory.configure(handSetup) |
|
|
|
|
this.playerHandMaxCards = handSetup.game?.playerHandMaxCards |
|
|
|
|
|
|
|
|
|
this.setHandHistory(handHistory) |
|
|
|
|
this.loadHandHistory(handHistory) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/*** |
|
|
|
|
* Sets the hand history and loads it |
|
|
|
|
*/ |
|
|
|
|
fun setHandHistory(handHistory: HandHistory) { |
|
|
|
|
this.isNew = false |
|
|
|
|
loadHandHistory(handHistory) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun loadHandHistory(handHistory: HandHistory) { |
|
|
|
|
this.handHistory = handHistory |
|
|
|
|
setNumberOfPlayers(handHistory.numberOfPlayers) |
|
|
|
|
load() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -122,6 +150,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra |
|
|
|
|
* Pre-computes the potsizes for the video export |
|
|
|
|
*/ |
|
|
|
|
private fun load() { |
|
|
|
|
this.setNumberOfPlayers(handHistory.numberOfPlayers) |
|
|
|
|
this.sortedActions.load(this.handHistory) |
|
|
|
|
this.createRowRepresentation() |
|
|
|
|
} |
|
|
|
|
@ -134,10 +163,15 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra |
|
|
|
|
|
|
|
|
|
rows.add(CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = R.string.settings, value = "")) |
|
|
|
|
|
|
|
|
|
rows.add(HandRowType.BLINDS) |
|
|
|
|
|
|
|
|
|
if (this.isNew) { // don't allow any straddle changes if not new |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val positions = Position.positionsPerPlayers(this.handHistory.numberOfPlayers) |
|
|
|
|
positions.remove(Position.SB) |
|
|
|
|
positions.remove(Position.BB) |
|
|
|
|
rows.add(StraddleRowRepresentable(positions, this.straddlePositions)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Street.values().forEach { street -> |
|
|
|
|
|
|
|
|
|
@ -415,7 +449,6 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra |
|
|
|
|
this.createRowRepresentation() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun amountChanged(amount: String?) { |
|
|
|
|
this.currentAmount = amount |
|
|
|
|
} |
|
|
|
|
@ -439,10 +472,19 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun isSelected(position: Int, row: RowRepresentable, tag: Int): Boolean { |
|
|
|
|
val currentSelection = this.selectionLiveData |
|
|
|
|
val isSelectedIndex = (position == currentSelection.value?.index) |
|
|
|
|
val isSelectedAction = (tag == currentSelection.value?.keyboard?.ordinal) |
|
|
|
|
return isSelectedIndex && isSelectedAction |
|
|
|
|
|
|
|
|
|
return when (row) { |
|
|
|
|
HandRowType.BLINDS -> { |
|
|
|
|
this.handHistory.bigBlindAnte |
|
|
|
|
} |
|
|
|
|
is ComputedAction -> { |
|
|
|
|
val currentSelection = this.selectionLiveData |
|
|
|
|
val isSelectedIndex = (position == currentSelection.value?.index) |
|
|
|
|
val isSelectedAction = (tag == currentSelection.value?.keyboard?.ordinal) |
|
|
|
|
isSelectedIndex && isSelectedAction |
|
|
|
|
} |
|
|
|
|
else -> false |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun cardSelectionEnded() { |
|
|
|
|
@ -453,4 +495,39 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra |
|
|
|
|
// this.builder.setBuilderListener(builderListener) |
|
|
|
|
// } |
|
|
|
|
|
|
|
|
|
override fun stringForRow(row: RowRepresentable, tag: Int): String { |
|
|
|
|
|
|
|
|
|
return when (row) { |
|
|
|
|
HandRowType.BLINDS -> { |
|
|
|
|
when (tag) { |
|
|
|
|
0 -> this.handHistory.smallBlind?.formatted() ?: "" |
|
|
|
|
1 -> this.handHistory.bigBlind?.formatted() ?: "" |
|
|
|
|
2 -> this.handHistory.ante.formatted() |
|
|
|
|
else -> throw PAIllegalStateException("Unmanaged case with $row, tag = $tag") |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
else -> throw PAIllegalStateException("Unmanaged case with $row, tag = $tag") |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun changeStraddleSelection(positions: LinkedHashSet<Position>) { |
|
|
|
|
|
|
|
|
|
if (positions.isEmpty()) { |
|
|
|
|
this.firstStraddlePosition = null |
|
|
|
|
this.handSetup.clearStraddles() |
|
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
if (this.firstStraddlePosition == null) { |
|
|
|
|
this.firstStraddlePosition = positions.firstOrNull() |
|
|
|
|
} |
|
|
|
|
this.handSetup.setStraddlePositions(this.firstStraddlePosition!!, positions) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
this.handHistory.configure(this.handSetup) // restart initial setup |
|
|
|
|
this.sortedActions.load(this.handHistory) // recreate the sorted Actions |
|
|
|
|
this.createRowRepresentation() // make the table rows |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |