Skip to content

Commit e915500

Browse files
committed
Fix category coloring behavior
1 parent e38ba4e commit e915500

File tree

3 files changed

+28
-36
lines changed

3 files changed

+28
-36
lines changed

app/src/main/kotlin/com/simplemobiletools/keyboard/views/MyKeyboardView.kt

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import android.util.TypedValue
2020
import android.view.*
2121
import android.view.animation.AccelerateInterpolator
2222
import android.view.inputmethod.EditorInfo
23+
import android.widget.ImageButton
2324
import android.widget.LinearLayout
2425
import android.widget.PopupWindow
2526
import 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
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<RadioButton
3-
xmlns:android="http://schemas.android.com/apk/res/android"
2+
<ImageButton xmlns:android="http://schemas.android.com/apk/res/android"
43
android:id="@+id/emoji_value"
54
android:layout_width="wrap_content"
65
android:layout_height="wrap_content"
76
android:background="@drawable/ripple_all_corners_medium"
87
android:gravity="center"
8+
android:importantForAccessibility="no"
99
android:padding="@dimen/small_margin"
10-
android:button="@drawable/ic_emoji_category_smileys" />
10+
android:src="@drawable/ic_emoji_category_activities" />

app/src/main/res/layout/keyboard_view_keyboard.xml

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -202,21 +202,15 @@
202202
android:text="@string/abc"
203203
android:textStyle="bold" />
204204

205-
<HorizontalScrollView
206-
android:id="@+id/emoji_categories_scrollable_strip"
205+
<LinearLayout
206+
android:id="@+id/emoji_categories_strip"
207207
android:layout_width="match_parent"
208208
android:layout_height="match_parent"
209-
android:layout_marginStart="@dimen/activity_margin"
209+
android:layout_gravity="center"
210+
android:layout_toStartOf="@+id/emoji_palette_backspace"
210211
android:layout_toEndOf="@+id/emoji_palette_mode_change"
211-
android:layout_toStartOf="@+id/emoji_palette_backspace">
212-
<RadioGroup
213-
android:id="@+id/emoji_categories_strip"
214-
android:orientation="horizontal"
215-
android:layout_width="wrap_content"
216-
android:layout_height="wrap_content"
217-
android:layout_gravity="center"
218-
android:gravity="center"/>
219-
</HorizontalScrollView>
212+
android:gravity="center"
213+
android:orientation="horizontal" />
220214

221215
<ImageButton
222216
android:id="@+id/emoji_palette_backspace"

0 commit comments

Comments
 (0)