Skip to content

Commit 37661e1

Browse files
committed
Theme picker: scrollable modern list + robust swatch binding
Address Greptile review: - Wrap the modern theme list in a ScrollView so it stays usable on compact screens as Theme.MODERN_THEMES grows. - Bind the preference swatch off the holder's actual view state (widgetFrame.childCount) instead of an instance flag, so a recycled/ re-inflated holder still gets its swatch. Drops the unused 'inited' field.
1 parent fa9a271 commit 37661e1

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import android.view.ViewGroup
1010
import android.widget.GridLayout
1111
import android.widget.ImageView
1212
import android.widget.LinearLayout
13+
import android.widget.ScrollView
1314
import android.widget.TextView
1415
import androidx.appcompat.app.AlertDialog
1516
import androidx.core.content.res.ResourcesCompat
@@ -45,16 +46,16 @@ class ThemePickerPreference
4546
context, attrs, defStyle
4647
) {
4748

48-
private var inited = false
49-
5049
override fun onBindViewHolder(holder: PreferenceViewHolder) {
5150
super.onBindViewHolder(holder)
5251

5352
val widgetFrame = holder.findViewById(android.R.id.widget_frame) as? LinearLayout
5453
?: return
5554

56-
if (!inited) {
57-
inited = true
55+
// Key off the holder's actual view state, not an instance flag: the
56+
// RecyclerView can recycle/re-inflate this row's holder, in which case a
57+
// stale instance flag would leave the new frame without its swatch.
58+
if (widgetFrame.childCount == 0) {
5859
widgetFrame.addView(
5960
nekoImageView(context.getColorAttr(R.attr.colorPrimary), 48, 0)
6061
)
@@ -125,7 +126,9 @@ class ThemePickerPreference
125126

126127
dialog = MaterialAlertDialogBuilder(context)
127128
.setTitle(title)
128-
.setView(container)
129+
// Wrap in a ScrollView so the list stays usable on compact screens as
130+
// Theme.MODERN_THEMES grows beyond the dialog's height.
131+
.setView(ScrollView(context).apply { addView(container) })
129132
.setNegativeButton(android.R.string.cancel, null)
130133
.show()
131134
}

0 commit comments

Comments
 (0)