Fix App List pages flickers

When there is a package change event happens on the device, the page is
auto refreshed, which caused the flickers.

Before this change, the app list item will be re-create for every app
list refresh, because System.identityHashCode(this) is part of item key.

System.identityHashCode(this) is added to fix an issue in the
AppListSwitchItem.

To fix this issue, removed remember in the AppListSwitchItem to make
sure TwoTargetSwitchPreference always has the latest values, so
System.identityHashCode(this) no loner need to be part of item key.

By removing System.identityHashCode(this) from the item key, the flicker
issue is fixed.

Fix: 267699436
Test: Manually with Settings
Change-Id: Iabf0c56271c5486272c921a4b4020f9e3d2b984b
This commit is contained in:
Chaohui Wang
2023-02-13 13:55:44 +08:00
parent a087b29ea5
commit 87d5631d1d
2 changed files with 7 additions and 10 deletions

View File

@@ -159,7 +159,7 @@ private fun <T : AppRecord> AppListModel<T>.AppListWidget(
}
private fun <T : AppRecord> T.itemKey(option: Int) =
listOf(option, app.packageName, app.userId, System.identityHashCode(this))
listOf(option, app.packageName, app.userId)
/** Returns group title if this is the first item of the group. */
private fun <T : AppRecord> AppListModel<T>.getGroupTitleIfFirst(

View File

@@ -2,7 +2,6 @@ package com.android.settingslib.spaprivileged.template.app
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
import androidx.compose.runtime.remember
import com.android.settingslib.spa.framework.theme.SettingsDimension
import com.android.settingslib.spa.widget.preference.SwitchPreferenceModel
import com.android.settingslib.spa.widget.preference.TwoTargetSwitchPreference
@@ -16,14 +15,12 @@ fun <T : AppRecord> AppListItemModel<T>.AppListSwitchItem(
onCheckedChange: ((newChecked: Boolean) -> Unit)?,
) {
TwoTargetSwitchPreference(
model = remember {
object : SwitchPreferenceModel {
override val title = label
override val summary = this@AppListSwitchItem.summary
override val checked = checked
override val changeable = changeable
override val onCheckedChange = onCheckedChange
}
model = object : SwitchPreferenceModel {
override val title = label
override val summary = this@AppListSwitchItem.summary
override val checked = checked
override val changeable = changeable
override val onCheckedChange = onCheckedChange
},
icon = { AppIcon(record.app, SettingsDimension.appIconItemSize) },
onClick = onClick,