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

Commit ddc4d173 authored by Behnam Heydarshahi's avatar Behnam Heydarshahi Committed by Android (Google) Code Review
Browse files

Merge "Cache tile state at adapter level" into main

parents 2c399676 8931a1d2
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