From 024ea38b525aeab556f28bf741f6d99ac2de47d5 Mon Sep 17 00:00:00 2001 From: Laurent Date: Wed, 25 Mar 2020 11:40:16 +0100 Subject: [PATCH] background for amount edittext --- .../model/realm/handhistory/HandHistory.kt | 6 ++-- .../modules/handhistory/HandHistoryAdapter.kt | 33 +++++++++++-------- .../res/drawable/rounded_kaki_darker_rect.xml | 6 ++++ .../drawable/rounded_kaki_darkest_rect.xml | 6 ++++ ...round.xml => rounded_kaki_medium_rect.xml} | 1 - app/src/main/res/layout/row_hand_action.xml | 2 +- app/src/main/res/values/colors.xml | 1 + 7 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 app/src/main/res/drawable/rounded_kaki_darker_rect.xml create mode 100644 app/src/main/res/drawable/rounded_kaki_darkest_rect.xml rename app/src/main/res/drawable/{rounded_card_back_background.xml => rounded_kaki_medium_rect.xml} (73%) 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 07bd8be6..bf4ef27e 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 @@ -431,8 +431,8 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, // Board cardSets.add(this.board) - // Try to add cards while we haven't reach at least 4 - while (views.size < 5 && cardSets.isNotEmpty()) { + // Try to add cards but not too much + while (views.size < 6 && cardSets.isNotEmpty()) { val cardSet = cardSets.removeAt(0) @@ -448,7 +448,7 @@ open class HandHistory : RealmObject(), Deletable, RowRepresentable, Filterable, val blankCard = Card() (1..5).forEach { _ -> val view = blankCard.view(context, layoutInflater, viewGroup, true) - view.setBackgroundResource(R.drawable.rounded_card_back_background) + view.setBackgroundResource(R.drawable.rounded_kaki_medium_rect) views.add(view) } } 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 da548e8b..ce7993bc 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 @@ -160,14 +160,15 @@ class HandHistoryAdapter( return itemView.context.getColor(color) } - fun editTextSelected(editText: EditText, selected: Boolean) { + fun editTextSelected(editText: EditText) { - editText.setBackgroundColor(color(selected)) +// editText.setBackgroundColor(color(selected)) val row = dataSource.rowRepresentableForPosition(this.currentPosition) ?: throw PAIllegalStateException("Row Representable not found at index: $currentPosition") delegate?.onRowSelected(this.currentPosition, row, editText.tag as Int) + setEditTextBackground(editText, true, true) } override fun onBind(position: Int, row: RowRepresentable, adapter: RecyclerAdapter) { @@ -188,30 +189,40 @@ class HandHistoryAdapter( editText.setTextIsSelectable(true) // Enabled - editText.isEnabled = adapter.dataSource.isEnabled(row, tag) + val isEnabled = adapter.dataSource.isEnabled(row, tag) + editText.isEnabled = isEnabled // Text val string = adapter.dataSource.charSequenceForRow(row, itemView.context, tag) editText.setText(string) // Focus - val focused = adapter.dataSource.isSelected(position, row, tag) - toggleFocus(editText, focused) + val isFocused = adapter.dataSource.isSelected(position, row, tag) + toggleFocus(editText, isFocused) editText.isFocusable = adapter.dataSource.isFocusable(position, row, tag) editText.isFocusableInTouchMode = adapter.dataSource.isFocusable(position, row, tag) // Put cursor at the end - if (focused) { + if (isFocused) { editText.setSelection(editText.text.length) } // Background - editText.setBackgroundColor(color(focused)) + setEditTextBackground(editText, isEnabled, isFocused) } } + private fun setEditTextBackground(editText: EditText, 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) + } + protected fun configureTextView(tag: Int, row: RowRepresentable, adapter: RecyclerAdapter) { val textView = itemView.findViewWithTag(tag) ?: throw PAIllegalStateException("TextView not found for tag: $tag, class: $this") textView.text = adapter.dataSource.charSequenceForRow(row, itemView.context, tag) @@ -230,7 +241,7 @@ class HandHistoryAdapter( editText.requestFocus() - editTextSelected(editText, true) + editTextSelected(editText) } return@setOnTouchListener true } @@ -447,7 +458,7 @@ class HandHistoryAdapter( amountEditText.requestFocus() - editTextSelected(amountEditText, true) + editTextSelected(amountEditText) } return@setOnTouchListener true } @@ -551,13 +562,9 @@ class HandHistoryAdapter( this.delegate = adapter.delegate - // Position Button itemView.position_button.text = adapter.dataSource.charSequenceForRow(row, itemView.context, PlayerSetupRow.Tag.POSITION.ordinal) -// val positionSelected = adapter.dataSource.isSelected(position, row, PlayerSetupRow.Tag.POSITION.ordinal) -// itemView.position_button.backgroundTintList = ColorStateList.valueOf(color(positionSelected)) - val positionalRow = row as PositionalRow itemView.position_button.backgroundTintList = ColorStateList.valueOf(color(positionalRow.isHero)) diff --git a/app/src/main/res/drawable/rounded_kaki_darker_rect.xml b/app/src/main/res/drawable/rounded_kaki_darker_rect.xml new file mode 100644 index 00000000..521055fb --- /dev/null +++ b/app/src/main/res/drawable/rounded_kaki_darker_rect.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/rounded_kaki_darkest_rect.xml b/app/src/main/res/drawable/rounded_kaki_darkest_rect.xml new file mode 100644 index 00000000..45642574 --- /dev/null +++ b/app/src/main/res/drawable/rounded_kaki_darkest_rect.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/rounded_card_back_background.xml b/app/src/main/res/drawable/rounded_kaki_medium_rect.xml similarity index 73% rename from app/src/main/res/drawable/rounded_card_back_background.xml rename to app/src/main/res/drawable/rounded_kaki_medium_rect.xml index e9e089fb..bd45849f 100644 --- a/app/src/main/res/drawable/rounded_card_back_background.xml +++ b/app/src/main/res/drawable/rounded_kaki_medium_rect.xml @@ -3,5 +3,4 @@ - \ No newline at end of file diff --git a/app/src/main/res/layout/row_hand_action.xml b/app/src/main/res/layout/row_hand_action.xml index 011c8401..0f6d320a 100644 --- a/app/src/main/res/layout/row_hand_action.xml +++ b/app/src/main/res/layout/row_hand_action.xml @@ -32,7 +32,7 @@ style="@style/PokerAnalyticsTheme.HHEditText" android:layout_width="0dp" android:layout_weight="2" - android:layout_height="44dp" + android:layout_height="wrap_content" android:layout_marginStart="8dp" android:layout_marginEnd="8dp" android:paddingEnd="4dp" diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 7cc1f9aa..73a04032 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -34,6 +34,7 @@ #657d60 #9bae8d #283227 + #1E231E #FF5F57