From 3279abcaffa1fb93a19c7e211df67e62e56c1a81 Mon Sep 17 00:00:00 2001 From: Laurent Date: Thu, 2 Jul 2020 08:54:54 +0200 Subject: [PATCH] Various fixes and improvements --- .../modules/handhistory/HandHistoryAdapter.kt | 9 ++++--- .../handhistory/HandHistoryFragment.kt | 25 +++++++++---------- .../handhistory/model/StreetCardsRow.kt | 4 +++ .../res/drawable/rounded_board_background.xml | 2 +- 4 files changed, 22 insertions(+), 18 deletions(-) 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 06498716..b48f3166 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 @@ -173,7 +173,7 @@ class HandHistoryAdapter( delegate?.onRowSelected(this.currentPosition, row, tag) - setEditTextBackground(editText = editText, isEnabled = true, isFocused = true) + setViewBackground(view = editText, isEnabled = true, isFocused = true) } override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { @@ -213,19 +213,19 @@ class HandHistoryAdapter( } // Background - setEditTextBackground(editText, isEnabled, isFocused) + setViewBackground(editText, isEnabled, isFocused) } } - private fun setEditTextBackground(editText: EditText, isEnabled: Boolean, isFocused: Boolean) { + private fun setViewBackground(view: View, isEnabled: Boolean, isFocused: Boolean) { val background = when { !isEnabled -> R.drawable.rounded_kaki_darkest_rect // disabled isFocused -> R.drawable.rounded_kaki_medium_rect // focused else -> R.drawable.rounded_kaki_darker_rect // default } - editText.background = itemView.context.getDrawable(background) + view.background = itemView.context.getDrawable(background) } protected fun configureTextView(tag: Int, row: RowRepresentable, adapter: RecyclerAdapter) { @@ -347,6 +347,7 @@ class HandHistoryAdapter( // Listener layout.setOnClickListener { delegate?.onRowSelected(this.currentPosition, row, layout.tag as Int) + setViewBackground(layout, true, true) } } 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 0e92e503..0f6f736c 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 @@ -403,22 +403,21 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL } } - if (row is HandHistoryRow) { - - if (this.model.hasSelection()) { - this.model.amountValidated() // validates any edited amount before possibly clearing action - refreshRowAtIndexAndCurrent(this.model.currentSelection.index) - } + when (row) { + is HandHistoryRow -> { -// this.model.selectionLiveData.value?.index?.let { oldIndex -> -// refreshRowAtIndexAndCurrent(oldIndex) -// } + if (this.model.hasSelection()) { + this.model.amountValidated() // validates any edited amount before possibly clearing action + refreshRowAtIndexAndCurrent(this.model.currentSelection.index) + } - val newSelection = HHSelection(position, tag) - this.model.setSelection(newSelection) + val newSelection = HHSelection(position, tag) + this.model.setSelection(newSelection) -// this.model.selectionLiveData.value = HHSelection(position, tag) + } + is StreetCardsRow -> { + } } } @@ -528,7 +527,7 @@ class HandHistoryFragment : RealmFragment(), RowRepresentableDelegate, KeyboardL override fun clearCards() { this.model.clearCards() - this.handHistoryAdapter.notifyItemChanged(this.model.currentSelection.index) + this.handHistoryAdapter.notifyDataSetChanged() // multiple rows can be impacted } override fun cardSelectionEnded() { diff --git a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetCardsRow.kt b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetCardsRow.kt index 93b7b7d8..62939334 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetCardsRow.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/modules/handhistory/model/StreetCardsRow.kt @@ -33,6 +33,10 @@ class StreetCardsRow(var street: Street, var handHistory: HandHistory) : CardsRo } } + override fun clear() { + this.cardHolder?.cards?.removeAll { it.street == street } + } + override fun isFieldNeedsInput(tag: Int, handHistory: HandHistory): Boolean { val street = Street.values()[tag] return this.cardCount < street.totalBoardCards || this.handHistory.cards.elementAtOrNull(street.totalBoardCards - 1)?.suit == null diff --git a/app/src/main/res/drawable/rounded_board_background.xml b/app/src/main/res/drawable/rounded_board_background.xml index 7bc43fd2..b0463061 100644 --- a/app/src/main/res/drawable/rounded_board_background.xml +++ b/app/src/main/res/drawable/rounded_board_background.xml @@ -1,6 +1,6 @@ - +