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

Commit 4dcfb0d5 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
parent 80262ef7
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -249,7 +249,7 @@ internal constructor(
        val client = getKeyguardQuickAffordancePickerProviderClient(context)
        val appContext = context.applicationContext
        return KeyguardQuickAffordancePickerInteractor(
            KeyguardQuickAffordancePickerRepository(client),
            KeyguardQuickAffordancePickerRepository(client, getApplicationCoroutineScope()),
            client
        ) {
            getKeyguardQuickAffordanceSnapshotRestorer(appContext)
+12 −6
Original line number Diff line number Diff line
@@ -21,8 +21,11 @@ import com.android.customization.picker.quickaffordance.shared.model.KeyguardQui
import com.android.customization.picker.quickaffordance.shared.model.KeyguardQuickAffordancePickerSelectionModel as SelectionModel
import com.android.customization.picker.quickaffordance.shared.model.KeyguardQuickAffordancePickerSlotModel as SlotModel
import com.android.systemui.shared.customization.data.content.CustomizationProviderClient as Client
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
@@ -30,6 +33,7 @@ import kotlinx.coroutines.flow.map
 */
class KeyguardQuickAffordancePickerRepository(
    private val client: Client,
    private val scope: CoroutineScope
) {
    /** List of slots available on the device. */
    val slots: Flow<List<SlotModel>> =
@@ -37,15 +41,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(
+9 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ package com.android.customization.model.picker.quickaffordance.data.repository
import androidx.test.filters.SmallTest
import com.android.customization.picker.quickaffordance.data.repository.KeyguardQuickAffordancePickerRepository
import com.android.systemui.shared.customization.data.content.FakeCustomizationProviderClient
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestScope
@@ -28,6 +29,7 @@ import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner

@@ -51,9 +53,16 @@ class KeyguardQuickAffordancePickerRepositoryTest {
        underTest =
            KeyguardQuickAffordancePickerRepository(
                client = client,
                scope = testScope.backgroundScope,
            )
    }

    // We need at least one test to prevent Studio errors
    @Test
    fun creationSucceeds() {
        assertThat(underTest).isNotNull()
    }

    @After
    fun tearDown() {
        Dispatchers.resetMain()
+1 −0
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ class KeyguardQuickAffordancePickerInteractorTest {
                repository =
                    KeyguardQuickAffordancePickerRepository(
                        client = client,
                        scope = testScope.backgroundScope,
                    ),
                client = client,
                snapshotRestorer = {
+1 −0
Original line number Diff line number Diff line
@@ -89,6 +89,7 @@ class KeyguardQuickAffordancePickerViewModelTest {
                repository =
                    KeyguardQuickAffordancePickerRepository(
                        client = client,
                        scope = testScope.backgroundScope,
                    ),
                client = client,
                snapshotRestorer = {