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

Commit 8931a1d2 authored by Behnam Heydarshahi's avatar Behnam Heydarshahi
Browse files

Cache tile state at adapter level

When receiving a new state update, only update UI if state has changed.
Drop icon supplier and use icon which can be used for comparison.

Bug: 356254554
Flag: com.android.systemui.qs_new_tiles
Test: manual. Open and close the shade. Verify new tiles on the first page no longer call handleStateChange 6-10 times. 2 times is ideal.
Test: manual. Run quicksettings-3-jank-suite and verify perfetto_cuj_systemui-NOTIFICATION_SHADE_QS_EXPAND_COLLAPSE-counter_metrics-missed_app_frames-mean does not increase.
Change-Id: I43ac4dd4cd88789db5f1c4b9ef774fdbd8a72446
parent 37cef638
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import java.io.PrintWriter
import java.util.concurrent.CopyOnWriteArraySet
import java.util.function.Supplier
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.collectIndexed
@@ -158,6 +157,8 @@ constructor(

    override fun isTileReady(): Boolean = qsTileViewModel.currentState != null

    private var cachedState = QSTile.AdapterState()

    override fun setListening(client: Any?, listening: Boolean) {
        client ?: return
        if (listening) {
@@ -168,8 +169,11 @@ constructor(
                        .filterNotNull()
                        .map { mapState(context, it, qsTileViewModel.config) }
                        .onEach { legacyState ->
                            val changed = legacyState.copyTo(cachedState)
                            if (changed) {
                                callbacks.forEach { it.onStateChanged(legacyState) }
                            }
                        }
                        .launchIn(applicationScope)
            }
        } else {
@@ -235,7 +239,7 @@ constructor(
                handlesLongClick =
                    viewModelState.supportedActions.contains(QSTileState.UserAction.LONG_CLICK)

                iconSupplier = Supplier {
                icon =
                    when (val stateIcon = viewModelState.icon()) {
                        is Icon.Loaded ->
                            if (viewModelState.iconRes == null) DrawableIcon(stateIcon.drawable)
@@ -243,7 +247,7 @@ constructor(
                        is Icon.Resource -> ResourceIcon.get(stateIcon.res)
                        null -> null
                    }
                }

                state = viewModelState.activationState.legacyState

                contentDescription = viewModelState.contentDescription