From 76264ddabbd4f10fc9bf8592b9d82199e01bd89f Mon Sep 17 00:00:00 2001 From: Laurent Date: Thu, 26 Mar 2020 12:34:36 +0100 Subject: [PATCH] HH settings are now hidden by default --- .../pokeranalytics/android/calculus/Stat.kt | 4 +- .../ui/adapter/RowRepresentableDataSource.kt | 8 +++ .../modules/handhistory/HandHistoryAdapter.kt | 8 +++ .../handhistory/HandHistoryFragment.kt | 17 ++++-- .../handhistory/model/HandHistoryViewModel.kt | 61 ++++++++++++++----- .../android/ui/view/holder/RowViewHolder.kt | 23 +++++++ app/src/main/res/drawable/ic_arrow_down.xml | 9 +++ app/src/main/res/drawable/ic_arrow_right.xml | 3 +- app/src/main/res/drawable/ic_arrow_up.xml | 9 +++ .../main/res/layout/row_hand_history_view.xml | 2 - .../res/layout/row_hhsettings_straddle.xml | 1 + 11 files changed, 122 insertions(+), 23 deletions(-) create mode 100644 app/src/main/res/drawable/ic_arrow_down.xml create mode 100644 app/src/main/res/drawable/ic_arrow_up.xml diff --git a/app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt b/app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt index e1b38679..555c6dce 100644 --- a/app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt +++ b/app/src/main/java/net/pokeranalytics/android/calculus/Stat.kt @@ -236,12 +236,12 @@ enum class Stat(override var uniqueIdentifier: Int) : IntIdentifiable, RowRepres get() { return when (this) { HOURLY_DURATION, AVERAGE_HOURLY_DURATION, - STANDARD_DEVIATION, STANDARD_DEVIATION_HOURLY, STANDARD_DEVIATION_BB_PER_100_HANDS -> false + STANDARD_DEVIATION, STANDARD_DEVIATION_HOURLY, + STANDARD_DEVIATION_BB_PER_100_HANDS -> false else -> true } } - val legendHideRightValue: Boolean get() { return when (this) { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/adapter/RowRepresentableDataSource.kt b/app/src/main/java/net/pokeranalytics/android/ui/adapter/RowRepresentableDataSource.kt index 7adb2aed..7d203a60 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/adapter/RowRepresentableDataSource.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/adapter/RowRepresentableDataSource.kt @@ -1,6 +1,7 @@ package net.pokeranalytics.android.ui.adapter import android.content.Context +import net.pokeranalytics.android.R import net.pokeranalytics.android.exceptions.PAIllegalStateException import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor @@ -144,6 +145,13 @@ interface DisplayableDataSource { return 0 } + /*** + * Returns an arrowIcon + */ + fun arrowIcon(position: Int, row: RowRepresentable): Int? { + return R.drawable.ic_arrow_right + } + /** * Returns whether the row, or its component, should be enabled */ 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 ea87d690..c82ea359 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 @@ -44,6 +44,7 @@ import net.pokeranalytics.android.util.extensions.formatted enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable { DEFAULT(R.layout.row_title), HEADER(R.layout.row_header_value), + SETTINGS_HEADER(R.layout.row_title_icon_arrow), ACTION(R.layout.row_hand_action), PLAYER_SUMMARY(R.layout.row_hand_player_summary), STREET(R.layout.row_hand_cards), @@ -82,6 +83,7 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable { COMMENT -> R.string.comment ANTE -> R.string.ante BIG_BLIND_ANTE, BIG_BLIND_ANTE_READ -> R.string.bb_ante_option + SETTINGS_HEADER -> R.string.settings else -> null } } @@ -90,6 +92,7 @@ enum class HandRowType(var layoutRes: Int) : ViewIdentifier, RowRepresentable { get() { return when(this) { COMMENT -> R.drawable.picto_comment + SETTINGS_HEADER -> R.drawable.picto_gear else -> null } } @@ -115,6 +118,7 @@ class HandHistoryAdapter( return when (rowType) { HandRowType.DEFAULT -> RowViewHolder(layout) HandRowType.HEADER -> RowViewHolder(layout) + HandRowType.SETTINGS_HEADER -> RowViewHolder(layout) HandRowType.ACTION -> RowActionHolder(layout) HandRowType.STREET -> RowStreetHolder(layout) HandRowType.PLAYER_SUMMARY -> RowPlayerSummaryHolder(layout) @@ -350,6 +354,10 @@ class HandHistoryAdapter( val straddleRow = row as StraddleRowRepresentable + adapter.dataSource.backgroundColor(position, row)?.let { color -> + itemView.findViewById(R.id.container)?.setBackgroundColor(itemView.context.getColor(color)) + } + itemView.positionsChipGroup.removeAllViews() straddleRow.positions.forEach { pos -> diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt index f388d713..3cff8f76 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/HandHistoryFragment.kt @@ -308,6 +308,11 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL super.onRowSelected(position, row, tag) Timber.d("onRowSelected: $position, tag = $tag, row = $row") + if (row == HandRowType.SETTINGS_HEADER) { + val ru = this.model.toggleSettingsRows() + this.handHistoryAdapter.notifyDataSetChanged() + return + } val alreadySelected = this.model.isSelected(position, row, tag) if (alreadySelected || !this.model.isEdited) { @@ -333,11 +338,15 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL } } - this.model.selectionLiveData.value?.index?.let { oldIndex -> - refreshRowAtIndexAndCurrent(oldIndex) - } + if (row is HandHistoryRow) { - this.model.selectionLiveData.value = HHSelection(position, tag) + this.model.selectionLiveData.value?.index?.let { oldIndex -> + refreshRowAtIndexAndCurrent(oldIndex) + } + + this.model.selectionLiveData.value = HHSelection(position, tag) + + } } 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 29c869a5..2968e7dd 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 @@ -24,6 +24,7 @@ import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor import net.pokeranalytics.android.ui.view.rowrepresentable.CustomizableRowRepresentable import net.pokeranalytics.android.util.extensions.formatted import timber.log.Timber +import kotlin.math.abs import kotlin.reflect.KClass enum class HHKeyboard { @@ -56,6 +57,11 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra */ private var isNew: Boolean = true + /*** + * Indicates if the settings are expanded + */ + private var settingsExpanded = false + /*** * Indicates whether the hand history is being edited or not */ @@ -146,6 +152,11 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra */ private var straddlePositions: LinkedHashSet = linkedSetOf() + /*** + * Number of settings rows + */ + private var settingsRowCount: Int = 1 + /*** * Creates and configures a new HandHistory object using a [handSetup] */ @@ -265,30 +276,47 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra return rows } + override fun backgroundColor(position: Int, row: RowRepresentable): Int? { + return if (position < this.settingsRowCount) R.color.gray_darker else R.color.transparent + } + + override fun arrowIcon(position: Int, row: RowRepresentable): Int? { + return when (row) { + HandRowType.SETTINGS_HEADER -> { + if (this.settingsExpanded) R.drawable.ic_arrow_up else R.drawable.ic_arrow_down + } + else -> null + } + } + private fun editionRowRepresentation(): MutableList { val rows: MutableList = mutableListOf() - rows.add(HandRowType.COMMENT) + rows.add(HandRowType.SETTINGS_HEADER) + if (this.settingsExpanded) { + rows.add(HandRowType.ANTE) -// rows.add(CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = R.string.settings, value = "")) + if (this.handSetup.type != Session.Type.CASH_GAME) { + rows.add(HandRowType.BIG_BLIND_ANTE) + } - rows.add(HandRowType.PLAYER_NUMBER) - rows.add(HandRowType.ANTE) + // Straddle + val positions = Position.positionsPerPlayers(this.handHistory.numberOfPlayers) + if (this.handSetup.type != Session.Type.TOURNAMENT && this.isNew && positions.size > 2) { // don't allow any straddle changes if not new, or if it's a headsup - if (this.handSetup.type != Session.Type.CASH_GAME) { - rows.add(HandRowType.BIG_BLIND_ANTE) + rows.add(CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = R.string.straddle, value = "")) + positions.remove(Position.SB) + positions.remove(Position.BB) + rows.add(StraddleRowRepresentable(positions, this.straddlePositions)) + } } - // Straddle - val positions = Position.positionsPerPlayers(this.handHistory.numberOfPlayers) - if (this.handSetup.type != Session.Type.TOURNAMENT && this.isNew && positions.size > 2) { // don't allow any straddle changes if not new, or if it's a headsup + // Updates the settings row count to set the proper background + this.settingsRowCount = rows.size - rows.add(CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = R.string.straddle, value = "")) - positions.remove(Position.SB) - positions.remove(Position.BB) - rows.add(StraddleRowRepresentable(positions, this.straddlePositions)) - } + rows.add(HandRowType.COMMENT) + rows.add(HandRowType.PLAYER_NUMBER) // Used to set the hero position rows.add(CustomizableRowRepresentable(customViewType = HandRowType.HEADER, resId = R.string.set_hero_position, value = "")) @@ -946,4 +974,9 @@ class HandHistoryViewModel : ViewModel(), RowRepresentableDataSource, CardCentra this.createRowRepresentation() // refresh } + fun toggleSettingsRows() { + this.settingsExpanded = !this.settingsExpanded + this.createRowRepresentation() + } + } \ No newline at end of file diff --git a/app/src/main/java/net/pokeranalytics/android/ui/view/holder/RowViewHolder.kt b/app/src/main/java/net/pokeranalytics/android/ui/view/holder/RowViewHolder.kt index 75535805..0a915410 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/view/holder/RowViewHolder.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/view/holder/RowViewHolder.kt @@ -1,5 +1,6 @@ package net.pokeranalytics.android.ui.view.holder +import android.content.res.ColorStateList import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.AppCompatImageView @@ -86,6 +87,10 @@ class RowViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), Bindabl } } + adapter.dataSource.backgroundColor(position, row)?.let { color -> + itemView.findViewById(R.id.container)?.setBackgroundColor(itemView.context.getColor(color)) + } + } else -> { // Standard row @@ -129,6 +134,24 @@ class RowViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), Bindabl } } + // Arrow Icon + itemView.findViewById(R.id.nextArrow)?.let { imageView -> + imageView.setImageDrawable(null) + + val arrow = adapter.dataSource.arrowIcon(position, row) ?: row.imageRes + arrow?.let { + imageView.setImageResource(it) + } + +// adapter.dataSource.arrowIcon(position, row)?.let { +// imageView.setImageResource(it) +// } ?: run { +// row.imageRes?.let { imageRes -> +// imageView.setImageResource(imageRes) +// } +// } + } + // Action itemView.findViewById(R.id.action)?.let { imageView -> imageView.setImageDrawable(null) diff --git a/app/src/main/res/drawable/ic_arrow_down.xml b/app/src/main/res/drawable/ic_arrow_down.xml new file mode 100644 index 00000000..a9510d51 --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_down.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_arrow_right.xml b/app/src/main/res/drawable/ic_arrow_right.xml index ff5a73ff..19d1897e 100644 --- a/app/src/main/res/drawable/ic_arrow_right.xml +++ b/app/src/main/res/drawable/ic_arrow_right.xml @@ -1,5 +1,6 @@ - + diff --git a/app/src/main/res/drawable/ic_arrow_up.xml b/app/src/main/res/drawable/ic_arrow_up.xml new file mode 100644 index 00000000..59b4d185 --- /dev/null +++ b/app/src/main/res/drawable/ic_arrow_up.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/row_hand_history_view.xml b/app/src/main/res/layout/row_hand_history_view.xml index 3dde39b3..2f19edf9 100644 --- a/app/src/main/res/layout/row_hand_history_view.xml +++ b/app/src/main/res/layout/row_hand_history_view.xml @@ -59,8 +59,6 @@ android:id="@+id/nextArrow" android:layout_width="24dp" android:layout_height="24dp" - android:src="@drawable/ic_arrow_right" - android:tint="@color/gray_light" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="@+id/guidelineEnd" app:layout_constraintTop_toTopOf="parent" /> diff --git a/app/src/main/res/layout/row_hhsettings_straddle.xml b/app/src/main/res/layout/row_hhsettings_straddle.xml index 348868ae..9a8429a9 100644 --- a/app/src/main/res/layout/row_hhsettings_straddle.xml +++ b/app/src/main/res/layout/row_hhsettings_straddle.xml @@ -2,6 +2,7 @@