From 5bbf436e4e75ccf2054597262abc7d24dc6b2088 Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Sun, 23 Jul 2023 12:40:39 +0200 Subject: [PATCH] fix: color selection --- .../keepass/adapters/NodesAdapter.kt | 33 +++++++++++++------ .../main/res/layout/item_list_nodes_entry.xml | 8 +++-- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/com/kunzisoft/keepass/adapters/NodesAdapter.kt b/app/src/main/java/com/kunzisoft/keepass/adapters/NodesAdapter.kt index 41c7160b9..711dcfd1a 100644 --- a/app/src/main/java/com/kunzisoft/keepass/adapters/NodesAdapter.kt +++ b/app/src/main/java/com/kunzisoft/keepass/adapters/NodesAdapter.kt @@ -90,6 +90,8 @@ class NodesAdapter ( private var mNodeClickCallback: NodeClickCallback? = null private var mClipboardHelper = ClipboardHelper(context) + @ColorInt + private val mColorSurfaceContainer: Int @ColorInt private val mTextColorPrimary: Int @ColorInt @@ -116,6 +118,9 @@ class NodesAdapter ( this.mNodeSortedListCallback = NodeSortedListCallback() this.mNodeSortedList = SortedList(Node::class.java, mNodeSortedListCallback) + val taColorSurfaceContainer = context.theme.obtainStyledAttributes(intArrayOf(R.attr.colorSurfaceContainer)) + this.mColorSurfaceContainer = taColorSurfaceContainer.getColor(0, Color.BLACK) + taColorSurfaceContainer.recycle() // Retrieve the color to tint the icon val taTextColorPrimary = context.theme.obtainStyledAttributes(intArrayOf(android.R.attr.textColorPrimary)) this.mTextColorPrimary = taTextColorPrimary.getColor(0, Color.BLACK) @@ -430,16 +435,8 @@ class NodesAdapter ( if (entry.containsAttachment()) View.VISIBLE else View.GONE // Assign colors - ViewCompat.setBackgroundTintList( - holder.container, - ColorStateList.valueOf( - if (!holder.container.isSelected) { - (if (mShowEntryColors) entry.backgroundColor else null) ?: Color.TRANSPARENT - } else { - mColorSecondary - } - ) - ) + assignBackgroundColor(holder.container, entry) + assignBackgroundColor(holder.otpContainer, entry) val foregroundColor = if (mShowEntryColors) entry.foregroundColor else null if (!holder.container.isSelected) { if (foregroundColor != null) { @@ -539,6 +536,22 @@ class NodesAdapter ( } } + private fun assignBackgroundColor(view: View?, entry: Entry) { + view?.let { + ViewCompat.setBackgroundTintList( + view, + ColorStateList.valueOf( + if (!view.isSelected) { + (if (mShowEntryColors) entry.backgroundColor else null) + ?: mColorSurfaceContainer + } else { + mColorSecondary + } + ) + ) + } + } + class OtpRunnable(val view: View?): Runnable { var action: (() -> Unit)? = null diff --git a/app/src/main/res/layout/item_list_nodes_entry.xml b/app/src/main/res/layout/item_list_nodes_entry.xml index 5e64a2922..17ed739ed 100644 --- a/app/src/main/res/layout/item_list_nodes_entry.xml +++ b/app/src/main/res/layout/item_list_nodes_entry.xml @@ -131,9 +131,13 @@ android:layout_height="wrap_content" android:layout_marginEnd="8dp" android:layout_marginRight="8dp" - android:background="?android:attr/selectableItemBackground" + android:background="@drawable/background_item_selection" android:orientation="horizontal" - android:padding="4dp" + android:paddingStart="8dp" + android:paddingLeft="8dp" + android:paddingEnd="4dp" + android:paddingRight="4dp" + android:paddingVertical="4dp" app:layout_constraintBottom_toTopOf="@+id/node_attachment_icon" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent">