Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c7925cf5 authored by Jiaming Cheng's avatar Jiaming Cheng
Browse files

[QSDetailedView] Fix a cast list view ripple issue

Tapping on one list item would cause the ripple effect to appear on a
different item, particularly for items in the middle of the list.

This is because all middle list items were sharing the same Drawable
instance. Drawables can have a shared state, a touch event on one item
would update the state for all items using that same instance.

This CL fixes these issues by:
Creating a new, unique drawable instance for each list item by calling
constantState.newDrawable().mutate(). This ensures that each item has its
own independent state, so the ripple effect is only shown on the item that
was actually tapped.

Bug: 378513588
Flag: com.android.systemui.qs_tile_detailed_view
Test: Only ui fix. Existing unit tests still pass.
Change-Id: Ie28dd13ab4109bb3fb65e2877f3b0a92efcfc936
parent f22eda35
Loading
Loading
Loading
Loading
+9 −10
Original line number Diff line number Diff line
@@ -167,12 +167,6 @@ fun CastControllerDisconnectButton(contentManager: MediaRouteControllerContentMa

private fun customizeView(listView: ListView) {
    val context = listView.context
    val entryBackgroundStart =
        context.getDrawable(SystemUiR.drawable.settingslib_entry_bg_off_start)
    val entryBackgroundEnd = context.getDrawable(SystemUiR.drawable.settingslib_entry_bg_off_end)
    val entryBackgroundMiddle =
        context.getDrawable(SystemUiR.drawable.settingslib_entry_bg_off_middle)
    val entryBackgroundSingle = context.getDrawable(SystemUiR.drawable.settingslib_entry_bg_off)

    // This code will run after the ListView has had a chance to complete its layout.
    listView.post {
@@ -191,11 +185,16 @@ private fun customizeView(listView: ListView) {
                val entry = child.getChildAt(0) as LinearLayout
                entry.background =
                    when {
                        totalItemCount == 1 -> entryBackgroundSingle
                        adapterPosition == 0 -> entryBackgroundStart
                        adapterPosition == totalItemCount - 1 -> entryBackgroundEnd
                        else -> entryBackgroundMiddle
                        totalItemCount == 1 ->
                            context.getDrawable(SystemUiR.drawable.settingslib_entry_bg_off)
                        adapterPosition == 0 ->
                            context.getDrawable(SystemUiR.drawable.settingslib_entry_bg_off_start)
                        adapterPosition == totalItemCount - 1 ->
                            context.getDrawable(SystemUiR.drawable.settingslib_entry_bg_off_end)
                        else ->
                            context.getDrawable(SystemUiR.drawable.settingslib_entry_bg_off_middle)
                    }

                setPadding(context, child)

                val titleTextView = entry.requireViewById<TextView>(R.id.text1)