From 1338e21da1f3a2ee3e0f75dae8bbbf8f1705e3cb Mon Sep 17 00:00:00 2001 From: Laurent Date: Tue, 17 Mar 2020 14:54:42 +0100 Subject: [PATCH] Highlights hero --- .../android/model/realm/handhistory/Action.kt | 9 ++++---- .../model/realm/handhistory/HandHistory.kt | 2 +- .../modules/handhistory/HandHistoryAdapter.kt | 9 +++++++- .../handhistory/HandHistoryFragment.kt | 22 ++++++++++--------- .../modules/handhistory/model/ActionList.kt | 7 ++++++ .../handhistory/model/ActionReadRow.kt | 4 +++- .../handhistory/model/ComputedAction.kt | 7 +++++- .../handhistory/model/HandHistoryRow.kt | 1 + .../handhistory/model/HandHistoryViewModel.kt | 18 +++++---------- .../handhistory/model/PlayerCardsRow.kt | 5 +++++ 10 files changed, 54 insertions(+), 30 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 ce90eb68..172365d0 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 @@ -15,21 +15,22 @@ import net.pokeranalytics.android.util.extensions.formatted * An extension to transform a list of ComputedAction into * a more compact and read-friendly list of ActionReadRow */ -fun List.compact(positions: LinkedHashSet): List { +fun List.compact(positions: LinkedHashSet, heroIndex: Int?): List { val rows = mutableListOf() this.forEach { if (it.type == Action.Type.FOLD && rows.lastOrNull()?.action == Action.Type.FOLD) { rows.lastOrNull()?.positions?.add(positions.elementAt(it.position)) } else { - rows.add(it.toReadRow(positions)) + rows.add(it.toReadRow(positions, heroIndex)) } } return rows } -fun Action.toReadRow(positions: LinkedHashSet): ActionReadRow { +fun Action.toReadRow(positions: LinkedHashSet, heroIndex: Int?): ActionReadRow { val pos = positions.elementAt(this.position) - return ActionReadRow(mutableListOf(pos), this.position, this.type, this.amount) + val isHero = (heroIndex == this.position) + return ActionReadRow(mutableListOf(pos), this.position, this.type, this.amount, isHero) } open class Action : RealmObject() { diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt index 788ac1cb..20d3b89c 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/handhistory/HandHistory.kt @@ -309,7 +309,7 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Identifiabl string = string.addLineReturn(2) - val streetActions = sortedActions.filter { it.street == street }.compact(positions) + val streetActions = sortedActions.filter { it.street == street }.compact(positions, this.heroIndex) if (streetActions.isNotEmpty()) { val streetItems = mutableListOf(context.getString(street.resId)) diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt index 200224a5..88d5a680 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryAdapter.kt @@ -448,6 +448,8 @@ class HandHistoryAdapter( // Position itemView.findViewById