Fixes issue with stacks + show player as allin

hh
Laurent 5 years ago
parent f0787ab8ab
commit 37fd11d162
  1. 3
      app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt
  2. 6
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt
  3. 5
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt
  4. 3
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt
  5. 13
      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. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt
  8. 10
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/ReplayerConfiguration.kt
  9. 20
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/replayer/TableDrawer.kt
  10. 11
      app/src/main/res/layout/row_hand_action_read.xml

@ -51,6 +51,7 @@ class PokerAnalyticsApplication : Application() {
.build() .build()
Realm.setDefaultConfiguration(realmConfiguration) Realm.setDefaultConfiguration(realmConfiguration)
// val realm = Realm.getDefaultInstance() // val realm = Realm.getDefaultInstance()
// realm.executeTransaction { // realm.executeTransaction {
// realm.where(Session::class.java).findAll().deleteAllFromRealm() // realm.where(Session::class.java).findAll().deleteAllFromRealm()
@ -76,6 +77,8 @@ class PokerAnalyticsApplication : Application() {
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
Timber.d("UserPreferences.defaultCurrency: ${UserDefaults.currency.symbol}") Timber.d("UserPreferences.defaultCurrency: ${UserDefaults.currency.symbol}")
Timber.d("Realm path = ${Realm.getDefaultInstance().path}")
// this.createFakeSessions() // this.createFakeSessions()
} }

@ -23,13 +23,13 @@ fun List<Action>.compact(positions: LinkedHashSet<Position>, heroIndex: Int?): L
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, heroIndex)) rows.add(it.toReadRow(positions, heroIndex, null)) // TODO stack. The method is used for text export only atm
} }
} }
return rows return rows
} }
fun Action.toReadRow(positions: LinkedHashSet<Position>, heroIndex: Int?): ActionReadRow { fun Action.toReadRow(positions: LinkedHashSet<Position>, heroIndex: Int?, stack: Double?): ActionReadRow {
val pos = positions.elementAt(this.position) val pos = positions.elementAt(this.position)
val isHero = (heroIndex == this.position) val isHero = (heroIndex == this.position)
@ -38,7 +38,7 @@ fun Action.toReadRow(positions: LinkedHashSet<Position>, heroIndex: Int?): Actio
amount = this.effectiveAmount amount = this.effectiveAmount
} }
return ActionReadRow(mutableListOf(pos), this.position, this.type, amount, isHero) return ActionReadRow(mutableListOf(pos), this.position, this.type, amount, stack, isHero)
} }
open class Action : RealmObject() { open class Action : RealmObject() {

@ -21,6 +21,7 @@ import net.pokeranalytics.android.model.interfaces.Identifiable
import net.pokeranalytics.android.model.interfaces.TimeFilterable import net.pokeranalytics.android.model.interfaces.TimeFilterable
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.ui.modules.handhistory.evaluator.EvaluatorBridge import net.pokeranalytics.android.ui.modules.handhistory.evaluator.EvaluatorBridge
import net.pokeranalytics.android.ui.modules.handhistory.model.ActionList
import net.pokeranalytics.android.ui.modules.handhistory.model.ActionReadRow import net.pokeranalytics.android.ui.modules.handhistory.model.ActionReadRow
import net.pokeranalytics.android.ui.modules.handhistory.model.CardHolder import net.pokeranalytics.android.ui.modules.handhistory.model.CardHolder
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
@ -328,6 +329,10 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable,
// Actions per street // Actions per street
val sortedActions = this.actions.sortedBy { it.index } val sortedActions = this.actions.sortedBy { it.index }
// val actionList = ActionList()
// actionList.load(this)
Street.values().forEach { street -> Street.values().forEach { street ->
string = string.addLineReturn(2) string = string.addLineReturn(2)

@ -428,6 +428,7 @@ class HandHistoryAdapter(
init { init {
itemView.player_image_rhar.tag = ActionReadRow.Tag.PLAYER.ordinal itemView.player_image_rhar.tag = ActionReadRow.Tag.PLAYER.ordinal
itemView.stackText.tag = ActionReadRow.Tag.STACK.ordinal
} }
override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) {
@ -444,7 +445,7 @@ class HandHistoryAdapter(
} }
itemView.amountText.text = actionReadRow.amount?.formatted itemView.amountText.text = actionReadRow.amount?.formatted
itemView.stackText.text = actionReadRow.stack?.formatted
} }
} }

@ -5,6 +5,7 @@ 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.handhistory.Action import net.pokeranalytics.android.model.realm.handhistory.Action
import net.pokeranalytics.android.model.realm.handhistory.HandHistory import net.pokeranalytics.android.model.realm.handhistory.HandHistory
import timber.log.Timber
interface ActionManager { interface ActionManager {
fun selectAction(index: Int, actionType: Action.Type) fun selectAction(index: Int, actionType: Action.Type)
@ -53,7 +54,6 @@ class ActionList(var listener: ActionListListener? = null) : ArrayList<ComputedA
var totalPotSize = 0.0 var totalPotSize = 0.0
// sorted actions // sorted actions
val computedActions = mutableListOf<ComputedAction>()
val sortedActions = handHistory.actions.sortedBy { it.index } val sortedActions = handHistory.actions.sortedBy { it.index }
sortedActions.forEach { action -> sortedActions.forEach { action ->
totalPotSize += action.effectiveAmount totalPotSize += action.effectiveAmount
@ -65,9 +65,9 @@ class ActionList(var listener: ActionListListener? = null) : ArrayList<ComputedA
totalPotSize, totalPotSize,
position position
) )
computedActions.add(ca) this.add(ca)
Timber.d(">> CA: position:${ca.position}, ${ca.action.amount}, ${ca.stackBeforeActing}, ${ca.stackAfterActing}")
} }
this.addAll(computedActions)
// Adds action // Adds action
updateFollowupActions(sortedActions.size - 1) updateFollowupActions(sortedActions.size - 1)
@ -744,4 +744,11 @@ class ActionList(var listener: ActionListListener? = null) : ArrayList<ComputedA
.lastOrNull { it.positionIndex == position && it.action.type?.isPassive == false } .lastOrNull { it.positionIndex == position && it.action.type?.isPassive == false }
} }
/***
* Returns if the player at [position] is allin at [index] or before
*/
fun isPlayerAllin(position: Int, index: Int): Boolean {
return this.take(index + 1).lastOrNull { it.positionIndex == position && it.action.type?.isAllin == true } != null
}
} }

@ -9,10 +9,12 @@ 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?, var amount: Double?,
var stack: Double?,
override val isHero: Boolean) : RowRepresentable, PositionalRow { override val isHero: Boolean) : RowRepresentable, PositionalRow {
enum class Tag { enum class Tag {
PLAYER PLAYER,
STACK
} }
override val viewType: Int = HandRowType.ACTION_READ.ordinal override val viewType: Int = HandRowType.ACTION_READ.ordinal

@ -24,7 +24,7 @@ fun List<ComputedAction>.compact(positions: LinkedHashSet<Position>, heroIndex:
if (it.action.type == Action.Type.FOLD && rows.lastOrNull()?.action == Action.Type.FOLD) { if (it.action.type == Action.Type.FOLD && rows.lastOrNull()?.action == Action.Type.FOLD) {
rows.lastOrNull()?.positions?.add(it.position) rows.lastOrNull()?.positions?.add(it.position)
} else { } else {
rows.add(it.action.toReadRow(positions, heroIndex)) rows.add(it.action.toReadRow(positions, heroIndex, it.stackAfterActing))
} }
} }
return rows return rows

@ -444,6 +444,16 @@ class ReplayerConfiguration(var handHistory: HandHistory) {
this.currentFrame = 0 this.currentFrame = 0
} }
fun isPlayerAllin(playerIndex: Int): Boolean {
this.lastActionAtStep?.action?.index?.let { index ->
return this.actionList.isPlayerAllin(playerIndex, index)
}
return false
}
/***
* Returns whether the replayer has finished showing steps & frames or not
*/
val isReplayFinished: Boolean val isReplayFinished: Boolean
get() { get() {
return this.currentStepIndex >= this.steps.size - 1 && this.currentFrame >= this.numberOfFramesForCurrentStep - 1 return this.currentStepIndex >= this.steps.size - 1 && this.currentFrame >= this.numberOfFramesForCurrentStep - 1

@ -136,9 +136,14 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
drawPlayerRectangle(i, true, config, canvas, context) drawPlayerRectangle(i, true, config, canvas, context)
drawAction(i, computedAction, config, canvas, context) drawAction(i, computedAction, config, canvas, context)
} else { } else {
val remainingStack = config.playerRemainingStack(i) val info = if (config.isPlayerAllin(i)) {
context.getString(R.string.allin)
} else {
val remainingStack = config.playerRemainingStack(i)
remainingStack?.formatted
}
drawPlayerRectangle(i, false, config, canvas, context) drawPlayerRectangle(i, false, config, canvas, context)
drawPositionAndStack(i, remainingStack, config, canvas) drawPositionAndInfo(i, info, config, canvas)
} }
} }
@ -403,7 +408,7 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
} }
} }
private fun drawPositionAndStack(i: Int, stack: Double?, config: ReplayerConfiguration, canvas: Canvas) { private fun drawPositionAndInfo(i: Int, secondLine: String?, config: ReplayerConfiguration, canvas: Canvas) {
val hh = config.handHistory val hh = config.handHistory
// Player position // Player position
@ -414,10 +419,11 @@ class TableDrawer(bitmap: Bitmap) : Canvas(bitmap) {
canvas.drawText(name, pnPoint.x, pnPoint.y, this.textPaint) canvas.drawText(name, pnPoint.x, pnPoint.y, this.textPaint)
// Player stack // Player stack
val psPoint = config.pointForPlayerStack(i) secondLine?.let {
this.textPaint.textSize = psPoint.fontSize val psPoint = config.pointForPlayerStack(i)
val stackFormatted = stack?.formatted ?: "" this.textPaint.textSize = psPoint.fontSize
canvas.drawText(stackFormatted, psPoint.x, psPoint.y, this.textPaint) canvas.drawText(it, psPoint.x, psPoint.y, this.textPaint)
}
} }

@ -53,6 +53,15 @@
</LinearLayout> </LinearLayout>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/stackText"
style="@style/PokerAnalyticsTheme.TextView.RowTitle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="end|center_vertical"
android:maxLines="1"
android:layout_marginEnd="16dp"
tools:text="120" />
</LinearLayout> </LinearLayout>
Loading…
Cancel
Save