From aef9649fae97aba23df772e4af474b200876e7af Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Sat, 25 Apr 2026 13:26:15 +0200 Subject: [PATCH] fix: Tags color --- .../kunzisoft/keepass/adapters/TagsAdapter.kt | 42 ++++++------------- .../keepass/view/TagsCompletionView.kt | 15 ++++++- .../main/res/color/text_secondary_color.xml | 2 +- .../main/res/drawable/ic_check_white_14dp.xml | 9 ++++ app/src/main/res/layout/item_tag.xml | 7 ++-- app/src/main/res/layout/item_tag_chip.xml | 42 ++++++------------- app/src/main/res/layout/item_tag_edit.xml | 16 +++---- app/src/main/res/layout/item_tag_small.xml | 7 ++-- app/src/main/res/values/styles.xml | 1 + 9 files changed, 66 insertions(+), 75 deletions(-) create mode 100644 app/src/main/res/drawable/ic_check_white_14dp.xml diff --git a/app/src/main/java/com/kunzisoft/keepass/adapters/TagsAdapter.kt b/app/src/main/java/com/kunzisoft/keepass/adapters/TagsAdapter.kt index 4f1149472..ee96a9e1b 100644 --- a/app/src/main/java/com/kunzisoft/keepass/adapters/TagsAdapter.kt +++ b/app/src/main/java/com/kunzisoft/keepass/adapters/TagsAdapter.kt @@ -28,6 +28,7 @@ import android.view.ViewGroup import android.widget.TextView import androidx.annotation.ColorInt import androidx.core.view.ViewCompat +import androidx.core.widget.TextViewCompat import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView import com.kunzisoft.keepass.R @@ -80,35 +81,19 @@ class TagsAdapter( } when (globalViewType) { TagViewType.SMALL -> { - // Tint text depending on selection - holder.name.setTextColor(if (tagIsSelected) mColorOnSecondary else mColorSecondary) - // Tint background depending on selection - ViewCompat.setBackgroundTintList( - holder.name, - ColorStateList.valueOf( - (if (tagIsSelected) mColorOnSecondary else mColorSecondary) - ) - ) + val color = if (tagIsSelected) mColorOnSecondary else mColorSecondary + // Tint depending on selection + holder.name.setTextColor(color) + ViewCompat.setBackgroundTintList(holder.name, ColorStateList.valueOf(color)) } TagViewType.CHIP -> { - holder.container?.let { - ViewCompat.setBackgroundTintList( - it, - ColorStateList.valueOf( - (if (tagIsSelected) mColorSecondary else mTextColor) - ) - ) - } - holder.check?.let { checkView -> - checkView.visibility = if (tagIsSelected) View.VISIBLE else View.GONE - ViewCompat.setBackgroundTintList( - checkView, - ColorStateList.valueOf( - (if (tagIsSelected) mColorSecondary else mTextColor) - ) - ) - } - holder.name.setTextColor(if (tagIsSelected) mColorSecondary else mTextColor) + val color = if (tagIsSelected) mColorSecondary else mTextColor + ViewCompat.setBackgroundTintList(holder.name, ColorStateList.valueOf(color)) + holder.name.setTextColor(color) + holder.name.setCompoundDrawablesRelativeWithIntrinsicBounds( + if (tagIsSelected) R.drawable.ic_check_white_14dp else 0, 0, 0, 0 + ) + TextViewCompat.setCompoundDrawableTintList(holder.name, ColorStateList.valueOf(color)) } else -> { // No text color change in standard mode @@ -186,9 +171,6 @@ class TagsAdapter( } class TagViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { - - var container: View? = itemView.findViewById(R.id.tag_container) - var check: View? = itemView.findViewById(R.id.tag_check) var name: TextView = itemView.findViewById(R.id.tag_name) fun bind(item: Tag, listener: OnItemClickListener?) { diff --git a/app/src/main/java/com/kunzisoft/keepass/view/TagsCompletionView.kt b/app/src/main/java/com/kunzisoft/keepass/view/TagsCompletionView.kt index bb2236631..6fc8735a0 100644 --- a/app/src/main/java/com/kunzisoft/keepass/view/TagsCompletionView.kt +++ b/app/src/main/java/com/kunzisoft/keepass/view/TagsCompletionView.kt @@ -2,11 +2,15 @@ package com.kunzisoft.keepass.view import android.app.Activity import android.content.Context +import android.content.res.ColorStateList +import android.graphics.Color import android.util.AttributeSet import android.view.LayoutInflater import android.view.View import android.view.ViewGroup -import android.widget.TextView +import androidx.annotation.ColorInt +import androidx.appcompat.widget.AppCompatTextView +import androidx.core.view.ViewCompat import com.kunzisoft.keepass.R import com.kunzisoft.keepass.database.element.Tags import com.tokenautocomplete.CharacterTokenizer @@ -17,6 +21,8 @@ class TagsCompletionView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null ) : TokenCompleteTextView(context, attrs) { + @ColorInt + private val mColorSecondary: Int private val layoutInflater = context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE) as? LayoutInflater? @@ -24,6 +30,10 @@ class TagsCompletionView @JvmOverloads constructor( allowCollapse(false) setTokenizer(CharacterTokenizer(Tags.DELIMITERS, Tags.DELIMITER.toString())) setTokenClickStyle(TokenClickStyle.Delete) + + context.obtainStyledAttributes(intArrayOf(R.attr.colorSecondary)).also { taColorSecondary -> + this.mColorSecondary = taColorSecondary.getColor(0, Color.GRAY) + }.recycle() } override fun defaultObject(completionText: String): String { @@ -33,8 +43,9 @@ class TagsCompletionView @JvmOverloads constructor( override fun getViewForObject(obj: String): View? { val viewGroup = layoutInflater?.inflate(R.layout.item_tag_edit, parent as ViewGroup, false) as? ViewGroup? - viewGroup?.findViewById(R.id.tag_name)?.apply { + viewGroup?.findViewById(R.id.tag_name)?.apply { text = obj + ViewCompat.setBackgroundTintList(this, ColorStateList.valueOf(mColorSecondary)) } return viewGroup } diff --git a/app/src/main/res/color/text_secondary_color.xml b/app/src/main/res/color/text_secondary_color.xml index a7ac5fa81..4858d747b 100644 --- a/app/src/main/res/color/text_secondary_color.xml +++ b/app/src/main/res/color/text_secondary_color.xml @@ -1,5 +1,5 @@ - + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_check_white_14dp.xml b/app/src/main/res/drawable/ic_check_white_14dp.xml new file mode 100644 index 000000000..a7fc3fe99 --- /dev/null +++ b/app/src/main/res/drawable/ic_check_white_14dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/item_tag.xml b/app/src/main/res/layout/item_tag.xml index 194b3f25b..942091ffd 100644 --- a/app/src/main/res/layout/item_tag.xml +++ b/app/src/main/res/layout/item_tag.xml @@ -17,17 +17,18 @@ You should have received a copy of the GNU General Public License along with KeePassDX. If not, see . --> -. --> - - - - \ No newline at end of file + android:minHeight="24dp" + android:gravity="center_vertical" + android:layout_marginHorizontal="4dp" + android:layout_marginVertical="4dp" + android:paddingHorizontal="6dp" + android:layout_gravity="center_vertical" + tools:text="text" + android:textSize="14sp" /> \ No newline at end of file diff --git a/app/src/main/res/layout/item_tag_edit.xml b/app/src/main/res/layout/item_tag_edit.xml index 6f3b3d49b..f0f453ed5 100644 --- a/app/src/main/res/layout/item_tag_edit.xml +++ b/app/src/main/res/layout/item_tag_edit.xml @@ -17,24 +17,27 @@ You should have received a copy of the GNU General Public License along with KeePassDX. If not, see . --> - + android:paddingStart="6dp" + android:paddingEnd="22dp" /> - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/item_tag_small.xml b/app/src/main/res/layout/item_tag_small.xml index 8213a6905..71342284c 100644 --- a/app/src/main/res/layout/item_tag_small.xml +++ b/app/src/main/res/layout/item_tag_small.xml @@ -17,20 +17,21 @@ You should have received a copy of the GNU General Public License along with KeePassDX. If not, see . --> - \ No newline at end of file + android:layout_marginBottom="2dp" /> \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 2af9beae4..9a93d9eae 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -282,6 +282,7 @@ 8dp true @color/text_secondary_color + @color/text_secondary_color false 24dp false