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

Commit 1223468b authored by Santiago Etchebehere's avatar Santiago Etchebehere Committed by Chris Poultney
Browse files

Cache affordances and selection picker side

Bug: 302425391
Test: manually verified that quick affordances work as expected

Change-Id: I24a05119721847243afbe7e7ba326cdd328c870b
Merged-In: I24a05119721847243afbe7e7ba326cdd328c870b
parent 3a47831f
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -267,7 +267,12 @@ internal constructor(
        val client = getKeyguardQuickAffordancePickerProviderClient(context)
        val appContext = context.applicationContext
        return KeyguardQuickAffordancePickerInteractor(
            KeyguardQuickAffordancePickerRepository(client, getFlags(), appContext),
            KeyguardQuickAffordancePickerRepository(
                client,
                getApplicationCoroutineScope(),
                getFlags(),
                appContext
            ),
            client
        ) {
            getKeyguardQuickAffordanceSnapshotRestorer(appContext)
+12 −6
Original line number Diff line number Diff line
@@ -23,8 +23,11 @@ import com.android.customization.picker.quickaffordance.shared.model.KeyguardQui
import com.android.customization.picker.quickaffordance.shared.model.KeyguardQuickAffordancePickerSlotModel as SlotModel
import com.android.systemui.shared.customization.data.content.CustomizationProviderClient as Client
import com.android.wallpaper.config.BaseFlags
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.shareIn

/**
 * Abstracts access to application state related to functionality for selecting, picking, or setting
@@ -32,6 +35,7 @@ import kotlinx.coroutines.flow.map
 */
class KeyguardQuickAffordancePickerRepository(
    private val client: Client,
    private val scope: CoroutineScope,
    private val flags: BaseFlags,
    private val context: Context
) {
@@ -46,15 +50,17 @@ class KeyguardQuickAffordancePickerRepository(

    /** List of all available quick affordances. */
    val affordances: Flow<List<AffordanceModel>> =
        client.observeAffordances().map { affordances ->
            affordances.map { affordance -> affordance.toModel() }
        }
        client
            .observeAffordances()
            .map { affordances -> affordances.map { affordance -> affordance.toModel() } }
            .shareIn(scope, replay = 1, started = SharingStarted.Lazily)

    /** List of slot-affordance pairs, modeling what the user has currently chosen for each slot. */
    val selections: Flow<List<SelectionModel>> =
        client.observeSelections().map { selections ->
            selections.map { selection -> selection.toModel() }
        }
        client
            .observeSelections()
            .map { selections -> selections.map { selection -> selection.toModel() } }
            .shareIn(scope, replay = 1, started = SharingStarted.Lazily)

    private fun Client.Slot.toModel(): SlotModel {
        return SlotModel(
+1 −0
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ class KeyguardQuickAffordancePickerRepositoryTest {
        underTest =
            KeyguardQuickAffordancePickerRepository(
                client = client,
                scope = testScope.backgroundScope,
                flags =
                    object : BaseFlags() {
                        override fun getCachedFlags(
+1 −0
Original line number Diff line number Diff line
@@ -65,6 +65,7 @@ class KeyguardQuickAffordancePickerInteractorTest {
                repository =
                    KeyguardQuickAffordancePickerRepository(
                        client = client,
                        scope = testScope.backgroundScope,
                        flags = testFlags,
                        context = ApplicationProvider.getApplicationContext(),
                    ),
+1 −0
Original line number Diff line number Diff line
@@ -87,6 +87,7 @@ class KeyguardQuickAffordancePickerViewModelTest {
                repository =
                    KeyguardQuickAffordancePickerRepository(
                        client = client,
                        scope = testScope.backgroundScope,
                        flags = injector.getFlags(),
                        context = context,
                    ),