Skip to content

Commit fa9a271

Browse files
committed
Harden theme picker: null-safe widget cast + accessibility
Address CodeRabbit findings: - Use safe cast (as?) with early return for the widget_frame lookup. - Add contentDescription to modern list rows (theme name) and classic grid swatches (Color theme %d) for screen-reader support.
1 parent 762083f commit fa9a271

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

app/src/main/java/moe/matsuri/nb4a/ui/ThemePickerPreference.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class ThemePickerPreference
5050
override fun onBindViewHolder(holder: PreferenceViewHolder) {
5151
super.onBindViewHolder(holder)
5252

53-
val widgetFrame = holder.findViewById(android.R.id.widget_frame) as LinearLayout
53+
val widgetFrame = holder.findViewById(android.R.id.widget_frame) as? LinearLayout
54+
?: return
5455

5556
if (!inited) {
5657
inited = true
@@ -147,6 +148,8 @@ class ThemePickerPreference
147148
android.R.attr.selectableItemBackground, outValue, true
148149
)
149150
setBackgroundResource(outValue.resourceId)
151+
// Announce the theme name to screen readers when the row is focused.
152+
contentDescription = name
150153

151154
val leading = when {
152155
swatchColor != null -> nekoImageView(swatchColor, 28, 0)
@@ -195,6 +198,8 @@ class ThemePickerPreference
195198
if (Theme.MODERN_THEMES.any { it.id == themeId }) continue
196199

197200
addView(nekoImageView(color, 64, 0).apply {
201+
contentDescription =
202+
context.getString(R.string.theme_classic_color_swatch, themeId)
198203
setOnClickListener {
199204
select(themeId)
200205
dialog.dismiss()

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<string name="theme">Theme</string>
1717
<string name="theme_dynamic">Dynamic (Material You)</string>
1818
<string name="theme_classic_colors">Classic colors…</string>
19+
<string name="theme_classic_color_swatch">Color theme %1$d</string>
1920
<string name="document">Document</string>
2021
<string name="group_default">Ungrouped</string>
2122
<string name="quick_toggle">Toggle</string>

0 commit comments

Comments
 (0)