Fix category coloring behavior
This commit is contained in:
parent
e38ba4ed19
commit
e915500171
|
@ -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<Int, String>()
|
||||
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<ImageButton>().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<ImageButton>()?.forEach {
|
||||
if (it.id == id) {
|
||||
it.imageTintList = ColorStateList.valueOf(context.getProperPrimaryColor())
|
||||
} else {
|
||||
it.imageTintList = ColorStateList.valueOf(context.getProperTextColor())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RadioButton
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<ImageButton xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/emoji_value"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/ripple_all_corners_medium"
|
||||
android:gravity="center"
|
||||
android:importantForAccessibility="no"
|
||||
android:padding="@dimen/small_margin"
|
||||
android:button="@drawable/ic_emoji_category_smileys" />
|
||||
android:src="@drawable/ic_emoji_category_activities" />
|
||||
|
|
|
@ -202,21 +202,15 @@
|
|||
android:text="@string/abc"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<HorizontalScrollView
|
||||
android:id="@+id/emoji_categories_scrollable_strip"
|
||||
<LinearLayout
|
||||
android:id="@+id/emoji_categories_strip"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginStart="@dimen/activity_margin"
|
||||
android:layout_gravity="center"
|
||||
android:layout_toStartOf="@+id/emoji_palette_backspace"
|
||||
android:layout_toEndOf="@+id/emoji_palette_mode_change"
|
||||
android:layout_toStartOf="@+id/emoji_palette_backspace">
|
||||
<RadioGroup
|
||||
android:id="@+id/emoji_categories_strip"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center"/>
|
||||
</HorizontalScrollView>
|
||||
android:gravity="center"
|
||||
android:orientation="horizontal" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/emoji_palette_backspace"
|
||||
|
|
Loading…
Reference in New Issue