diff options
author | Santiago Etchebehere <santie@google.com> | 2023-10-19 07:29:07 -0700 |
---|---|---|
committer | Chris Poultney <poultney@google.com> | 2023-10-19 16:19:48 +0000 |
commit | 4dcfb0d5f0409a33445243ae963b1ff514b89427 (patch) | |
tree | 46d86087e2d8cafe585743ccf8329bbd041d8a21 /src/com | |
parent | 80262ef74f9a481b2fba73b725a3fea56c226de2 (diff) | |
download | ThemePicker-4dcfb0d5f0409a33445243ae963b1ff514b89427.tar.gz |
Cache affordances and selection picker side
Bug: 302425391
Test: manually verified that quick affordances work as expected
Change-Id: I24a05119721847243afbe7e7ba326cdd328c870b
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/customization/module/ThemePickerInjector.kt | 2 | ||||
-rw-r--r-- | src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt | 18 |
2 files changed, 13 insertions, 7 deletions
diff --git a/src/com/android/customization/module/ThemePickerInjector.kt b/src/com/android/customization/module/ThemePickerInjector.kt index 6072f391..ecd5e57a 100644 --- a/src/com/android/customization/module/ThemePickerInjector.kt +++ b/src/com/android/customization/module/ThemePickerInjector.kt @@ -249,7 +249,7 @@ internal constructor( val client = getKeyguardQuickAffordancePickerProviderClient(context) val appContext = context.applicationContext return KeyguardQuickAffordancePickerInteractor( - KeyguardQuickAffordancePickerRepository(client), + KeyguardQuickAffordancePickerRepository(client, getApplicationCoroutineScope()), client ) { getKeyguardQuickAffordanceSnapshotRestorer(appContext) diff --git a/src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt b/src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt index 10473a27..6bfe3484 100644 --- a/src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt +++ b/src/com/android/customization/picker/quickaffordance/data/repository/KeyguardQuickAffordancePickerRepository.kt @@ -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( |