From e91550017115e4eeeb964b30b568802882c07e6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ensar=20Saraj=C4=8Di=C4=87?= Date: Wed, 30 Aug 2023 11:25:50 +0200 Subject: [PATCH] Fix category coloring behavior --- .../keyboard/views/MyKeyboardView.kt | 40 +++++++++---------- .../main/res/layout/item_emoji_category.xml | 6 +-- .../res/layout/keyboard_view_keyboard.xml | 18 +++------ 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt index 72dc67a..259c65b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt @@ -20,6 +20,7 @@ import android.util.TypedValue import android.view.* import android.view.animation.AccelerateInterpolator import android.view.inputmethod.EditorInfo +import android.widget.ImageButton import android.widget.LinearLayout import android.widget.PopupWindow import android.widget.RadioGroup @@ -1560,30 +1561,25 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut allItems.addAll(emojis.map(EmojisAdapter.Item::Emoji)) } val checkIds = mutableMapOf() - val checkedChangedListener: (RadioGroup, Int) -> Unit = { _, checkedId -> - (keyboardViewBinding?.emojisList?.layoutManager as? GridLayoutManager)?.scrollToPositionWithOffset( - allItems.indexOfFirst { it is EmojisAdapter.Item.Category && it.value == checkIds[checkedId] }, - 0 - ) - } keyboardViewBinding?.emojiCategoriesStrip?.apply { + val strip = this removeAllViews() - this.setOnCheckedChangeListener(checkedChangedListener) categories.entries.forEach { (category, emojis) -> ItemEmojiCategoryBinding.inflate(LayoutInflater.from(context), this, true).apply { root.id = generateViewId() checkIds[root.id] = category - root.setButtonDrawable(emojis.first().getCategoryIcon()) - root.buttonTintList = ColorStateList( - arrayOf( - intArrayOf(android.R.attr.state_checked), - intArrayOf(-android.R.attr.state_checked), - ), - intArrayOf( - context.getProperPrimaryColor(), - context.getProperTextColor() + root.setImageResource(emojis.first().getCategoryIcon()) + root.setOnClickListener { + strip.children.filterIsInstance().forEach { + it.imageTintList = ColorStateList.valueOf(context.getProperTextColor()) + } + root.imageTintList = ColorStateList.valueOf(context.getProperPrimaryColor()) + (keyboardViewBinding?.emojisList?.layoutManager as? GridLayoutManager)?.scrollToPositionWithOffset( + allItems.indexOfFirst { it is EmojisAdapter.Item.Category && it.value == category }, + 0 ) - ) + } + root.imageTintList = ColorStateList.valueOf(context.getProperTextColor()) } } } @@ -1615,10 +1611,12 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut .lastOrNull { it.value is EmojisAdapter.Item.Category && it.index <= firstVisibleIndex } ?.also { activeCategory -> val id = checkIds.entries.first { it.value == (activeCategory.value as EmojisAdapter.Item.Category).value }.key - keyboardViewBinding?.emojiCategoriesStrip?.apply { - setOnCheckedChangeListener(null) - check(id) - setOnCheckedChangeListener(checkedChangedListener) + keyboardViewBinding?.emojiCategoriesStrip?.children?.filterIsInstance()?.forEach { + if (it.id == id) { + it.imageTintList = ColorStateList.valueOf(context.getProperPrimaryColor()) + } else { + it.imageTintList = ColorStateList.valueOf(context.getProperTextColor()) + } } } } diff --git a/app/src/main/res/layout/item_emoji_category.xml b/app/src/main/res/layout/item_emoji_category.xml index 3fdd618..4ba7223 100644 --- a/app/src/main/res/layout/item_emoji_category.xml +++ b/app/src/main/res/layout/item_emoji_category.xml @@ -1,10 +1,10 @@ - + android:src="@drawable/ic_emoji_category_activities" /> diff --git a/app/src/main/res/layout/keyboard_view_keyboard.xml b/app/src/main/res/layout/keyboard_view_keyboard.xml index 11a18f1..9ff0921 100644 --- a/app/src/main/res/layout/keyboard_view_keyboard.xml +++ b/app/src/main/res/layout/keyboard_view_keyboard.xml @@ -202,21 +202,15 @@ android:text="@string/abc" android:textStyle="bold" /> - - - + android:gravity="center" + android:orientation="horizontal" />