From 5e6d18cfddfbfda634a73e3b8eef801eca950e6b Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 18 Mar 2020 15:06:07 +0100 Subject: [PATCH] Improved readability --- .../android/model/realm/handhistory/Action.kt | 8 +++++++- .../ui/modules/handhistory/model/ComputedAction.kt | 12 +++--------- .../handhistory/model/HandHistoryViewModel.kt | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt index 31a1a644..9d8a631b 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt @@ -30,7 +30,13 @@ fun List.compact(positions: LinkedHashSet, heroIndex: Int?): L fun Action.toReadRow(positions: LinkedHashSet, heroIndex: Int?): ActionReadRow { val pos = positions.elementAt(this.position) val isHero = (heroIndex == this.position) - return ActionReadRow(mutableListOf(pos), this.position, this.type, this.amount, isHero) + + var amount = this.amount + if (this.type?.isCall == true) { + amount = this.effectiveAmount + } + + return ActionReadRow(mutableListOf(pos), this.position, this.type, amount, isHero) } open class Action : RealmObject() { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt index 688856f0..4e6b9605 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt @@ -5,6 +5,7 @@ import net.pokeranalytics.android.model.handhistory.Position import net.pokeranalytics.android.model.handhistory.Street import net.pokeranalytics.android.model.realm.handhistory.Action import net.pokeranalytics.android.model.realm.handhistory.HandHistory +import net.pokeranalytics.android.model.realm.handhistory.toReadRow import net.pokeranalytics.android.ui.modules.handhistory.HandRowType import kotlin.math.max import kotlin.math.min @@ -13,13 +14,13 @@ import kotlin.math.min * An extension to transform a list of ComputedAction into * a more compact and read-friendly list of ActionReadRow */ -fun List.compact(): List { +fun List.compact(positions: LinkedHashSet, heroIndex: Int?): List { val rows = mutableListOf() this.forEach { if (it.action.type == Action.Type.FOLD && rows.lastOrNull()?.action == Action.Type.FOLD) { rows.lastOrNull()?.positions?.add(it.position) } else { - rows.add(it.toReadRow()) + rows.add(it.action.toReadRow(positions, heroIndex)) } } return rows @@ -287,13 +288,6 @@ class ComputedAction(var manager: ActionManager, override val viewType: Int = HandRowType.ACTION.ordinal - /*** - * The "read mode" representation of the action - */ - fun toReadRow(): ActionReadRow { - return ActionReadRow(mutableListOf(this.position), this.positionIndex, this.action.type, this.action.amount, this.isHero) - } - override val positionIndex: Int get() { return this.action.position } diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt index 66218992..522fdec8 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt @@ -256,7 +256,7 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra val actions = this.sortedActions.filter { it.street == street } if (actions.isNotEmpty()) { addStreetHeader(rows, street) - rows.addAll(actions.compact()) + rows.addAll(actions.compact(this.sortedActions.positions, this.handHistory.heroIndex)) } } }