Improved readability

hh
Laurent 6 years ago
parent 4794c4c810
commit 5e6d18cfdd
  1. 8
      app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/Action.kt
  2. 12
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/ComputedAction.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/HandHistoryViewModel.kt

@ -30,7 +30,13 @@ fun List<Action>.compact(positions: LinkedHashSet<Position>, heroIndex: Int?): L
fun Action.toReadRow(positions: LinkedHashSet<Position>, 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() {

@ -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<ComputedAction>.compact(): List<ActionReadRow> {
fun List<ComputedAction>.compact(positions: LinkedHashSet<Position>, heroIndex: Int?): List<ActionReadRow> {
val rows = mutableListOf<ActionReadRow>()
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 }

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

Loading…
Cancel
Save