Fixes various bugs

hh
Laurent 6 years ago
parent 4092fdedef
commit 9254c40425
  1. 40
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt
  2. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ActionList.kt
  3. 6
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt
  4. 33
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt
  5. 28
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetHeaderRow.kt

@ -260,11 +260,14 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.model.setPlayerSetupPosition(row, value)
val index = this.indexOfRowRepresentable(row)
this.handHistoryAdapter.notifyItemChanged(index)
if (row.tagForCompletion(this.model.handHistory) != null) {
this.findNextActionToEdit(index)
}
}
}
}
}
}
}
@ -286,6 +289,25 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.findNextActionToEdit()
}
override fun amountValidated() {
Timber.d(">>> amount validated")
getRealm().executeTransaction {
this.model.amountValidated()
}
// this.handHistoryAdapter.notifyDataSetChanged()
this.findNextActionToEdit()
}
override fun amountChanged(amount: String?) {
this.model.amountChanged(amount)
}
override fun amountCleared() {
getRealm().executeTransaction {
this.model.clearAmount()
}
}
override fun cardValueSelected(value: Card.Value) {
getRealm().executeTransaction {
this.model.cardValueSelected(value)
@ -321,24 +343,6 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL
this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index)
}
override fun amountValidated() {
Timber.d(">>> amount validated")
getRealm().executeTransaction {
this.model.amountValidated()
}
// this.handHistoryAdapter.notifyDataSetChanged()
this.findNextActionToEdit()
}
override fun amountChanged(amount: String?) {
this.model.amountChanged(amount)
}
override fun amountCleared() {
getRealm().executeTransaction {
this.model.clearAmount()
}
}
/***
* Configures the action keyboard:

@ -476,7 +476,7 @@ class ActionList(var listener: ActionListListener) : ArrayList<ComputedAction>()
*/
override fun getStreetNextCalls(index: Int): List<ComputedAction> {
val streetNextSignificantIndex = getStreetNextSignificantAction(index)?.action?.index
?: this.lastIndexOfStreet(index)
?: this.lastIndexOfStreet(index) + 1 // +1 because of "until"
return this.filter {
it.action.index in ((index + 1) until streetNextSignificantIndex)
&& (it.action.type?.isCall ?: false)

@ -113,7 +113,8 @@ class ComputedAction(var manager: ActionManager,
Action.Type.POST_BB, Action.Type.BET, Action.Type.RAISE, Action.Type.BET_ALLIN, Action.Type.RAISE_ALLIN -> {
getStreetNextCalls().forEach {
it.setEffectiveAmount(amount)
it.updateEffectiveAmount()
// it.setEffectiveAmount(amount)
}
getPlayerNextActions().forEach {
it.updateEffectiveAmount()
@ -131,9 +132,6 @@ class ComputedAction(var manager: ActionManager,
}
}
}
// getStreetLastSignificantAction(this.street, index - 1)?.action?.amount?.let {
// }
}
}
else -> {}

@ -222,27 +222,29 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
*/
private fun addStreetHeader(rowRepresentables: MutableList<RowRepresentable>, street: Street) {
val firstIndexOfStreet = this.sortedActions.firstOrNull { it.street == street }?.action?.index
?: this.sortedActions.size
val potSize = this.handHistory.anteSum + this.sortedActions.take(firstIndexOfStreet).sumByDouble { it.action.effectiveAmount }
val potString = if (potSize > 0) potSize.formatted() else "" // "" required otherwise random values come up
val headerView = CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = street.resId, value = potString)
rowRepresentables.add(headerView)
rowRepresentables.add(StreetHeaderRow(street))
if (street.totalBoardCards > 0) {
// create new StreetCardsRow
val boardView =
StreetCardsRow(
street,
this.handHistory
)
val boardView = StreetCardsRow(street, this.handHistory)
rowRepresentables.add(boardView)
}
}
// private fun refreshStreetPots() {
// this.rowRepresentables.filterIsInstance<StreetHeaderRow>().forEach {
// it.value = formattedPotSizeForStreet(it.street)
// }
// }
private fun formattedPotSizeForStreet(street: Street): String {
val firstIndexOfStreet = this.sortedActions.firstOrNull { it.street == street }?.action?.index
?: this.sortedActions.size
val potSize = this.handHistory.anteSum + this.sortedActions.take(firstIndexOfStreet).sumByDouble { it.action.effectiveAmount }
return if (potSize > 0) potSize.formatted() else "" // "" required otherwise random values come up
}
/***
* Sets the number of players playing the hand
* Defines the appropriate positions for this player count
@ -352,7 +354,8 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
}
}
is ComputedAction -> {
row.setAmount(amount)
this.sortedActions.setAmount(this.actionIndexForSelection, amount)
// this.refreshStreetPots()
}
is PlayerSetupRow -> {
row.setStack(amount)
@ -360,7 +363,6 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
else -> {}
}
// this.sortedActions.setAmount(this.actionIndexForSelection, amount)
this.currentAmount = null
}
} catch (e: NumberFormatException) {
@ -565,6 +567,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra
}
}
is PlayerCardsRow -> row.cardHolder?.cards?.formatted(context)
is StreetHeaderRow -> this.formattedPotSizeForStreet(row.street)
else -> throw PAIllegalStateException("Unmanaged case with $row, tag = $tag")
}

@ -0,0 +1,28 @@
package net.pokeranalytics.android.ui.modules.handhistory.model
import android.content.Context
import net.pokeranalytics.android.model.handhistory.Street
import net.pokeranalytics.android.ui.modules.handhistory.HandRowType
import net.pokeranalytics.android.ui.view.RowRepresentable
/**
* A class to display a titleResId (and a value) as a Row Representable object
*/
class StreetHeaderRow(var street: Street) : RowRepresentable {
override fun localizedTitle(context: Context): String {
this.resId?.let {
return context.getString(it)
}
return "LOCALISATION NOT FOUND"
}
override val viewType: Int = HandRowType.HEADER.identifier
override val resId: Int?
get() {
return this.street.resId
}
}
Loading…
Cancel
Save