@@ -20,6 +20,7 @@ import android.util.TypedValue
2020import android.view.*
2121import android.view.animation.AccelerateInterpolator
2222import android.view.inputmethod.EditorInfo
23+ import android.widget.ImageButton
2324import android.widget.LinearLayout
2425import android.widget.PopupWindow
2526import android.widget.RadioGroup
@@ -1560,30 +1561,25 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
15601561 allItems.addAll(emojis.map(EmojisAdapter .Item ::Emoji ))
15611562 }
15621563 val checkIds = mutableMapOf<Int , String >()
1563- val checkedChangedListener: (RadioGroup , Int ) -> Unit = { _, checkedId ->
1564- (keyboardViewBinding?.emojisList?.layoutManager as ? GridLayoutManager )?.scrollToPositionWithOffset(
1565- allItems.indexOfFirst { it is EmojisAdapter .Item .Category && it.value == checkIds[checkedId] },
1566- 0
1567- )
1568- }
15691564 keyboardViewBinding?.emojiCategoriesStrip?.apply {
1565+ val strip = this
15701566 removeAllViews()
1571- this .setOnCheckedChangeListener(checkedChangedListener)
15721567 categories.entries.forEach { (category, emojis) ->
15731568 ItemEmojiCategoryBinding .inflate(LayoutInflater .from(context), this , true ).apply {
15741569 root.id = generateViewId()
15751570 checkIds[root.id] = category
1576- root.setButtonDrawable (emojis.first().getCategoryIcon())
1577- root.buttonTintList = ColorStateList (
1578- arrayOf(
1579- intArrayOf(android. R .attr.state_checked),
1580- intArrayOf( - android. R .attr.state_checked),
1581- ),
1582- intArrayOf (
1583- context.getProperPrimaryColor() ,
1584- context.getProperTextColor()
1571+ root.setImageResource (emojis.first().getCategoryIcon())
1572+ root.setOnClickListener {
1573+ strip.children.filterIsInstance< ImageButton >().forEach {
1574+ it.imageTintList = ColorStateList .valueOf(context.getProperTextColor())
1575+ }
1576+ root.imageTintList = ColorStateList .valueOf(context.getProperPrimaryColor())
1577+ (keyboardViewBinding?.emojisList?.layoutManager as ? GridLayoutManager )?.scrollToPositionWithOffset (
1578+ allItems.indexOfFirst { it is EmojisAdapter . Item . Category && it.value == category } ,
1579+ 0
15851580 )
1586- )
1581+ }
1582+ root.imageTintList = ColorStateList .valueOf(context.getProperTextColor())
15871583 }
15881584 }
15891585 }
@@ -1615,10 +1611,12 @@ class MyKeyboardView @JvmOverloads constructor(context: Context, attrs: Attribut
16151611 .lastOrNull { it.value is EmojisAdapter .Item .Category && it.index <= firstVisibleIndex }
16161612 ?.also { activeCategory ->
16171613 val id = checkIds.entries.first { it.value == (activeCategory.value as EmojisAdapter .Item .Category ).value }.key
1618- keyboardViewBinding?.emojiCategoriesStrip?.apply {
1619- setOnCheckedChangeListener(null )
1620- check(id)
1621- setOnCheckedChangeListener(checkedChangedListener)
1614+ keyboardViewBinding?.emojiCategoriesStrip?.children?.filterIsInstance<ImageButton >()?.forEach {
1615+ if (it.id == id) {
1616+ it.imageTintList = ColorStateList .valueOf(context.getProperPrimaryColor())
1617+ } else {
1618+ it.imageTintList = ColorStateList .valueOf(context.getProperTextColor())
1619+ }
16221620 }
16231621 }
16241622 }
0 commit comments