Loading src/com/android/customization/module/CustomizationInjector.kt +0 −5 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ import com.android.customization.picker.clock.ui.viewmodel.ClockCarouselViewMode import com.android.customization.picker.clock.ui.viewmodel.ClockSettingsViewModel import com.android.customization.picker.color.ui.viewmodel.ColorPickerViewModel import com.android.customization.picker.quickaffordance.domain.interactor.KeyguardQuickAffordancePickerInteractor import com.android.systemui.shared.clocks.ClockRegistry import com.android.wallpaper.module.Injector import com.android.wallpaper.picker.customization.data.repository.WallpaperColorsRepository Loading @@ -35,10 +34,6 @@ interface CustomizationInjector : Injector { context: Context, ): KeyguardQuickAffordancePickerInteractor fun getClockRegistry(context: Context): ClockRegistry? fun getClockPickerInteractor(context: Context): ClockPickerInteractor fun getColorPickerViewModelFactory(context: Context): ColorPickerViewModel.Factory fun getClockCarouselViewModelFactory( Loading src/com/android/customization/module/ThemePickerInjector.kt +11 −51 Original line number Diff line number Diff line Loading @@ -38,8 +38,6 @@ import com.android.customization.model.themedicon.data.repository.ThemeIconRepos import com.android.customization.model.themedicon.domain.interactor.ThemedIconInteractor import com.android.customization.model.themedicon.domain.interactor.ThemedIconSnapshotRestorer import com.android.customization.module.logging.ThemesUserEventLogger import com.android.customization.picker.clock.data.repository.ClockPickerRepositoryImpl import com.android.customization.picker.clock.data.repository.ClockRegistryProvider import com.android.customization.picker.clock.domain.interactor.ClockPickerInteractor import com.android.customization.picker.clock.domain.interactor.ClockPickerSnapshotRestorer import com.android.customization.picker.clock.ui.view.ClockViewFactory Loading @@ -62,6 +60,7 @@ import com.android.customization.picker.settings.ui.viewmodel.ColorContrastSecti import com.android.systemui.shared.clocks.ClockRegistry import com.android.systemui.shared.notifications.data.repository.NotificationSettingsRepository import com.android.systemui.shared.notifications.domain.interactor.NotificationSettingsInteractor import com.android.systemui.shared.settings.data.repository.SecureSettingsRepository import com.android.wallpaper.config.BaseFlags import com.android.wallpaper.module.CustomizationSections import com.android.wallpaper.module.FragmentFactory Loading @@ -86,7 +85,6 @@ open class ThemePickerInjector @Inject constructor( @MainDispatcher private val mainScope: CoroutineScope, @MainDispatcher private val mainDispatcher: CoroutineDispatcher, @BackgroundDispatcher private val bgScope: CoroutineScope, @BackgroundDispatcher private val bgDispatcher: CoroutineDispatcher, ) : WallpaperPicker2Injector(mainScope, bgDispatcher), CustomizationInjector { Loading @@ -97,10 +95,8 @@ constructor( null private var fragmentFactory: FragmentFactory? = null private var notificationsSnapshotRestorer: NotificationsSnapshotRestorer? = null private var clockPickerInteractor: ClockPickerInteractor? = null private var clockCarouselViewModelFactory: ClockCarouselViewModel.Factory? = null private var clockViewFactory: ClockViewFactory? = null private var clockPickerSnapshotRestorer: ClockPickerSnapshotRestorer? = null private var notificationSettingsInteractor: NotificationSettingsInteractor? = null private var notificationSectionViewModelFactory: NotificationSectionViewModel.Factory? = null private var colorPickerViewModelFactory: ColorPickerViewModel.Factory? = null Loading @@ -112,7 +108,6 @@ constructor( private var gridInteractor: GridInteractor? = null private var gridSnapshotRestorer: GridSnapshotRestorer? = null private var gridScreenViewModelFactory: GridScreenViewModel.Factory? = null private var clockRegistryProvider: ClockRegistryProvider? = null // Injected objects, sorted by type @Inject Loading @@ -126,6 +121,10 @@ constructor( @Inject lateinit var themesUserEventLogger: Lazy<ThemesUserEventLogger> @Inject lateinit var colorPickerInteractor: Lazy<ColorPickerInteractor> @Inject lateinit var colorPickerSnapshotRestorer: Lazy<ColorPickerSnapshotRestorer> @Inject lateinit var clockRegistry: Lazy<ClockRegistry> @Inject lateinit var secureSettingsRepository: Lazy<SecureSettingsRepository> @Inject lateinit var clockPickerInteractor: Lazy<ClockPickerInteractor> @Inject lateinit var clockPickerSnapshotRestorer: Lazy<ClockPickerSnapshotRestorer> override fun getCustomizationSections(activity: ComponentActivity): CustomizationSections { val appContext = activity.applicationContext Loading @@ -139,7 +138,7 @@ constructor( getNotificationSectionViewModelFactory(appContext), getFlags(), getClockCarouselViewModelFactory( interactor = getClockPickerInteractor(appContext), interactor = clockPickerInteractor.get(), clockViewFactory = clockViewFactory, resources = resources, ), Loading Loading @@ -188,7 +187,7 @@ constructor( this[KEY_THEMED_ICON_SNAPSHOT_RESTORER] = getThemedIconSnapshotRestorer(context) this[KEY_APP_GRID_SNAPSHOT_RESTORER] = getGridSnapshotRestorer(context) this[KEY_COLOR_PICKER_SNAPSHOT_RESTORER] = colorPickerSnapshotRestorer.get() this[KEY_CLOCKS_SNAPSHOT_RESTORER] = getClockPickerSnapshotRestorer(context) this[KEY_CLOCKS_SNAPSHOT_RESTORER] = clockPickerSnapshotRestorer.get() } } Loading Loading @@ -260,7 +259,7 @@ constructor( NotificationSettingsRepository( scope = getApplicationCoroutineScope(), backgroundDispatcher = bgDispatcher, secureSettingsRepository = getSecureSettingsRepository(context), secureSettingsRepository = secureSettingsRepository.get(), ), ) .also { notificationSettingsInteractor = it } Loading @@ -278,36 +277,6 @@ constructor( .also { notificationsSnapshotRestorer = it } } override fun getClockRegistry(context: Context): ClockRegistry { return (clockRegistryProvider ?: ClockRegistryProvider( context = context.applicationContext, coroutineScope = getApplicationCoroutineScope(), mainDispatcher = mainDispatcher, backgroundDispatcher = bgDispatcher, ) .also { clockRegistryProvider = it }) .get() } override fun getClockPickerInteractor( context: Context, ): ClockPickerInteractor { val appContext = context.applicationContext return clockPickerInteractor ?: ClockPickerInteractor( repository = ClockPickerRepositoryImpl( secureSettingsRepository = getSecureSettingsRepository(appContext), registry = getClockRegistry(appContext), scope = getApplicationCoroutineScope(), mainDispatcher = mainDispatcher, ), snapshotRestorer = { getClockPickerSnapshotRestorer(appContext) }, ) .also { clockPickerInteractor = it } } override fun getClockCarouselViewModelFactory( interactor: ClockPickerInteractor, clockViewFactory: ClockViewFactory, Loading @@ -331,7 +300,7 @@ constructor( ScreenSizeCalculator.getInstance() .getScreenSize(activity.windowManager.defaultDisplay), WallpaperManager.getInstance(activity.applicationContext), getClockRegistry(activity.applicationContext), clockRegistry.get(), ) .also { clockViewFactory = it Loading @@ -347,20 +316,11 @@ constructor( } } private fun getClockPickerSnapshotRestorer( context: Context, ): ClockPickerSnapshotRestorer { return clockPickerSnapshotRestorer ?: ClockPickerSnapshotRestorer(getClockPickerInteractor(context)).also { clockPickerSnapshotRestorer = it } } override fun getWallpaperColorResources( wallpaperColors: WallpaperColors, context: Context ): WallpaperColorResources { return ThemedWallpaperColorResources(wallpaperColors, getSecureSettingsRepository(context)) return ThemedWallpaperColorResources(wallpaperColors, secureSettingsRepository.get()) } override fun getColorPickerViewModelFactory(context: Context): ColorPickerViewModel.Factory { Loading Loading @@ -424,7 +384,7 @@ constructor( return clockSettingsViewModelFactory ?: ClockSettingsViewModel.Factory( context.applicationContext, getClockPickerInteractor(context), clockPickerInteractor.get(), colorPickerInteractor.get(), getUserEventLogger(), ) { clockId -> Loading src/com/android/customization/picker/clock/data/repository/ClockPickerRepositoryImpl.kt +12 −5 Original line number Diff line number Diff line Loading @@ -24,6 +24,9 @@ import com.android.customization.picker.clock.shared.model.ClockMetadataModel import com.android.systemui.plugins.clocks.ClockMetadata import com.android.systemui.shared.clocks.ClockRegistry import com.android.systemui.shared.settings.data.repository.SecureSettingsRepository import com.android.wallpaper.picker.di.modules.MainDispatcher import javax.inject.Inject import javax.inject.Singleton import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi Loading @@ -42,11 +45,14 @@ import kotlinx.coroutines.flow.shareIn import org.json.JSONObject /** Implementation of [ClockPickerRepository], using [ClockRegistry]. */ class ClockPickerRepositoryImpl( @Singleton class ClockPickerRepositoryImpl @Inject constructor( private val secureSettingsRepository: SecureSettingsRepository, private val registry: ClockRegistry, scope: CoroutineScope, mainDispatcher: CoroutineDispatcher, @MainDispatcher mainScope: CoroutineScope, @MainDispatcher mainDispatcher: CoroutineDispatcher, ) : ClockPickerRepository { @OptIn(ExperimentalCoroutinesApi::class) Loading Loading @@ -94,7 +100,8 @@ class ClockPickerRepositoryImpl( ?.toModel( isSelected = true, selectedColorId = metadata?.getSelectedColorId(), colorTone = metadata?.getColorTone() colorTone = metadata?.getColorTone() ?: ClockMetadataModel.DEFAULT_COLOR_TONE_PROGRESS, seedColor = registry.seedColor ) Loading Loading @@ -151,7 +158,7 @@ class ClockPickerRepositoryImpl( .map { isDynamic -> if (isDynamic) ClockSize.DYNAMIC else ClockSize.SMALL } .distinctUntilChanged() .shareIn( scope = scope, scope = mainScope, started = SharingStarted.Eagerly, replay = 1, ) Loading src/com/android/customization/picker/clock/domain/interactor/ClockPickerInteractor.kt +21 −15 Original line number Diff line number Diff line Loading @@ -23,7 +23,8 @@ import com.android.customization.picker.clock.data.repository.ClockPickerReposit import com.android.customization.picker.clock.shared.ClockSize import com.android.customization.picker.clock.shared.model.ClockMetadataModel import com.android.customization.picker.clock.shared.model.ClockSnapshotModel import javax.inject.Provider import javax.inject.Inject import javax.inject.Singleton import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.firstOrNull Loading @@ -33,9 +34,12 @@ import kotlinx.coroutines.flow.map * Interactor for accessing application clock settings, as well as selecting and configuring custom * clocks. */ class ClockPickerInteractor( @Singleton class ClockPickerInteractor @Inject constructor( private val repository: ClockPickerRepository, private val snapshotRestorer: Provider<ClockPickerSnapshotRestorer>, private val snapshotRestorer: ClockPickerSnapshotRestorer, ) { val allClocks: Flow<List<ClockMetadataModel>> = repository.allClocks Loading Loading @@ -78,7 +82,7 @@ class ClockPickerInteractor( setClockOption(ClockSnapshotModel(clockSize = size)) } suspend fun setClockOption(clockSnapshotModel: ClockSnapshotModel) { private suspend fun setClockOption(clockSnapshotModel: ClockSnapshotModel) { // [ClockCarouselViewModel] is monitoring the [ClockPickerInteractor.setSelectedClock] job, // so it needs to finish last. storeCurrentClockOption(clockSnapshotModel) Loading @@ -94,6 +98,11 @@ class ClockPickerInteractor( clockSnapshotModel.clockId?.let { repository.setSelectedClock(it) } } private suspend fun storeCurrentClockOption(clockSnapshotModel: ClockSnapshotModel) { val option = getCurrentClockToRestore(clockSnapshotModel) snapshotRestorer.storeSnapshot(option) } /** * Gets the [ClockSnapshotModel] from the storage and override with [latestOption]. * Loading @@ -103,19 +112,16 @@ class ClockPickerInteractor( * [selectedColorId] and [seedColor] have null state collide with nullable type, but we know * they are presented whenever there's a [colorToneProgress]. */ suspend fun getCurrentClockToRestore(latestOption: ClockSnapshotModel? = null) = private suspend fun getCurrentClockToRestore(latestOption: ClockSnapshotModel) = ClockSnapshotModel( clockId = latestOption?.clockId ?: selectedClockId.firstOrNull(), clockSize = latestOption?.clockSize ?: selectedClockSize.firstOrNull(), colorToneProgress = latestOption?.colorToneProgress ?: colorToneProgress.firstOrNull(), selectedColorId = latestOption?.colorToneProgress?.let { latestOption.selectedColorId } clockId = latestOption.clockId ?: selectedClockId.firstOrNull(), clockSize = latestOption.clockSize ?: selectedClockSize.firstOrNull(), colorToneProgress = latestOption.colorToneProgress ?: colorToneProgress.firstOrNull(), selectedColorId = latestOption.colorToneProgress?.let { latestOption.selectedColorId } ?: selectedColorId.firstOrNull(), seedColor = latestOption?.colorToneProgress?.let { latestOption.seedColor } seedColor = latestOption.colorToneProgress?.let { latestOption.seedColor } ?: seedColor.firstOrNull(), ) private suspend fun storeCurrentClockOption(clockSnapshotModel: ClockSnapshotModel) { val option = getCurrentClockToRestore(clockSnapshotModel) snapshotRestorer.get().storeSnapshot(option) } } src/com/android/customization/picker/clock/domain/interactor/ClockPickerSnapshotRestorer.kt +36 −4 Original line number Diff line number Diff line Loading @@ -19,14 +19,22 @@ package com.android.customization.picker.clock.domain.interactor import android.text.TextUtils import android.util.Log import com.android.customization.picker.clock.data.repository.ClockPickerRepository import com.android.customization.picker.clock.shared.model.ClockSnapshotModel import com.android.wallpaper.picker.undo.domain.interactor.SnapshotRestorer import com.android.wallpaper.picker.undo.domain.interactor.SnapshotStore import com.android.wallpaper.picker.undo.shared.model.RestorableSnapshot import javax.inject.Inject import javax.inject.Singleton import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.map /** Handles state restoration for clocks. */ class ClockPickerSnapshotRestorer(private val interactor: ClockPickerInteractor) : SnapshotRestorer { @Singleton class ClockPickerSnapshotRestorer @Inject constructor(private val repository: ClockPickerRepository) : SnapshotRestorer { private var snapshotStore: SnapshotStore = SnapshotStore.NOOP private var originalOption: ClockSnapshotModel? = null Loading @@ -34,7 +42,23 @@ class ClockPickerSnapshotRestorer(private val interactor: ClockPickerInteractor) store: SnapshotStore, ): RestorableSnapshot { snapshotStore = store originalOption = interactor.getCurrentClockToRestore() originalOption = ClockSnapshotModel( clockId = repository.selectedClock .map { clock -> clock.clockId } .distinctUntilChanged() .firstOrNull(), clockSize = repository.selectedClockSize.firstOrNull(), colorToneProgress = repository.selectedClock.map { clock -> clock.colorToneProgress }.firstOrNull(), selectedColorId = repository.selectedClock .map { clock -> clock.selectedColorId } .distinctUntilChanged() .firstOrNull(), seedColor = repository.selectedClock.map { clock -> clock.seedColor }.firstOrNull(), ) return snapshot(originalOption) } Loading @@ -58,7 +82,15 @@ class ClockPickerSnapshotRestorer(private val interactor: ClockPickerInteractor) ) } interactor.setClockOption(optionToRestore) optionToRestore.clockSize?.let { repository.setClockSize(it) } optionToRestore.colorToneProgress?.let { repository.setClockColor( selectedColorId = optionToRestore.selectedColorId, colorToneProgress = optionToRestore.colorToneProgress, seedColor = optionToRestore.seedColor ) } optionToRestore.clockId?.let { repository.setSelectedClock(it) } } } Loading Loading
src/com/android/customization/module/CustomizationInjector.kt +0 −5 Original line number Diff line number Diff line Loading @@ -24,7 +24,6 @@ import com.android.customization.picker.clock.ui.viewmodel.ClockCarouselViewMode import com.android.customization.picker.clock.ui.viewmodel.ClockSettingsViewModel import com.android.customization.picker.color.ui.viewmodel.ColorPickerViewModel import com.android.customization.picker.quickaffordance.domain.interactor.KeyguardQuickAffordancePickerInteractor import com.android.systemui.shared.clocks.ClockRegistry import com.android.wallpaper.module.Injector import com.android.wallpaper.picker.customization.data.repository.WallpaperColorsRepository Loading @@ -35,10 +34,6 @@ interface CustomizationInjector : Injector { context: Context, ): KeyguardQuickAffordancePickerInteractor fun getClockRegistry(context: Context): ClockRegistry? fun getClockPickerInteractor(context: Context): ClockPickerInteractor fun getColorPickerViewModelFactory(context: Context): ColorPickerViewModel.Factory fun getClockCarouselViewModelFactory( Loading
src/com/android/customization/module/ThemePickerInjector.kt +11 −51 Original line number Diff line number Diff line Loading @@ -38,8 +38,6 @@ import com.android.customization.model.themedicon.data.repository.ThemeIconRepos import com.android.customization.model.themedicon.domain.interactor.ThemedIconInteractor import com.android.customization.model.themedicon.domain.interactor.ThemedIconSnapshotRestorer import com.android.customization.module.logging.ThemesUserEventLogger import com.android.customization.picker.clock.data.repository.ClockPickerRepositoryImpl import com.android.customization.picker.clock.data.repository.ClockRegistryProvider import com.android.customization.picker.clock.domain.interactor.ClockPickerInteractor import com.android.customization.picker.clock.domain.interactor.ClockPickerSnapshotRestorer import com.android.customization.picker.clock.ui.view.ClockViewFactory Loading @@ -62,6 +60,7 @@ import com.android.customization.picker.settings.ui.viewmodel.ColorContrastSecti import com.android.systemui.shared.clocks.ClockRegistry import com.android.systemui.shared.notifications.data.repository.NotificationSettingsRepository import com.android.systemui.shared.notifications.domain.interactor.NotificationSettingsInteractor import com.android.systemui.shared.settings.data.repository.SecureSettingsRepository import com.android.wallpaper.config.BaseFlags import com.android.wallpaper.module.CustomizationSections import com.android.wallpaper.module.FragmentFactory Loading @@ -86,7 +85,6 @@ open class ThemePickerInjector @Inject constructor( @MainDispatcher private val mainScope: CoroutineScope, @MainDispatcher private val mainDispatcher: CoroutineDispatcher, @BackgroundDispatcher private val bgScope: CoroutineScope, @BackgroundDispatcher private val bgDispatcher: CoroutineDispatcher, ) : WallpaperPicker2Injector(mainScope, bgDispatcher), CustomizationInjector { Loading @@ -97,10 +95,8 @@ constructor( null private var fragmentFactory: FragmentFactory? = null private var notificationsSnapshotRestorer: NotificationsSnapshotRestorer? = null private var clockPickerInteractor: ClockPickerInteractor? = null private var clockCarouselViewModelFactory: ClockCarouselViewModel.Factory? = null private var clockViewFactory: ClockViewFactory? = null private var clockPickerSnapshotRestorer: ClockPickerSnapshotRestorer? = null private var notificationSettingsInteractor: NotificationSettingsInteractor? = null private var notificationSectionViewModelFactory: NotificationSectionViewModel.Factory? = null private var colorPickerViewModelFactory: ColorPickerViewModel.Factory? = null Loading @@ -112,7 +108,6 @@ constructor( private var gridInteractor: GridInteractor? = null private var gridSnapshotRestorer: GridSnapshotRestorer? = null private var gridScreenViewModelFactory: GridScreenViewModel.Factory? = null private var clockRegistryProvider: ClockRegistryProvider? = null // Injected objects, sorted by type @Inject Loading @@ -126,6 +121,10 @@ constructor( @Inject lateinit var themesUserEventLogger: Lazy<ThemesUserEventLogger> @Inject lateinit var colorPickerInteractor: Lazy<ColorPickerInteractor> @Inject lateinit var colorPickerSnapshotRestorer: Lazy<ColorPickerSnapshotRestorer> @Inject lateinit var clockRegistry: Lazy<ClockRegistry> @Inject lateinit var secureSettingsRepository: Lazy<SecureSettingsRepository> @Inject lateinit var clockPickerInteractor: Lazy<ClockPickerInteractor> @Inject lateinit var clockPickerSnapshotRestorer: Lazy<ClockPickerSnapshotRestorer> override fun getCustomizationSections(activity: ComponentActivity): CustomizationSections { val appContext = activity.applicationContext Loading @@ -139,7 +138,7 @@ constructor( getNotificationSectionViewModelFactory(appContext), getFlags(), getClockCarouselViewModelFactory( interactor = getClockPickerInteractor(appContext), interactor = clockPickerInteractor.get(), clockViewFactory = clockViewFactory, resources = resources, ), Loading Loading @@ -188,7 +187,7 @@ constructor( this[KEY_THEMED_ICON_SNAPSHOT_RESTORER] = getThemedIconSnapshotRestorer(context) this[KEY_APP_GRID_SNAPSHOT_RESTORER] = getGridSnapshotRestorer(context) this[KEY_COLOR_PICKER_SNAPSHOT_RESTORER] = colorPickerSnapshotRestorer.get() this[KEY_CLOCKS_SNAPSHOT_RESTORER] = getClockPickerSnapshotRestorer(context) this[KEY_CLOCKS_SNAPSHOT_RESTORER] = clockPickerSnapshotRestorer.get() } } Loading Loading @@ -260,7 +259,7 @@ constructor( NotificationSettingsRepository( scope = getApplicationCoroutineScope(), backgroundDispatcher = bgDispatcher, secureSettingsRepository = getSecureSettingsRepository(context), secureSettingsRepository = secureSettingsRepository.get(), ), ) .also { notificationSettingsInteractor = it } Loading @@ -278,36 +277,6 @@ constructor( .also { notificationsSnapshotRestorer = it } } override fun getClockRegistry(context: Context): ClockRegistry { return (clockRegistryProvider ?: ClockRegistryProvider( context = context.applicationContext, coroutineScope = getApplicationCoroutineScope(), mainDispatcher = mainDispatcher, backgroundDispatcher = bgDispatcher, ) .also { clockRegistryProvider = it }) .get() } override fun getClockPickerInteractor( context: Context, ): ClockPickerInteractor { val appContext = context.applicationContext return clockPickerInteractor ?: ClockPickerInteractor( repository = ClockPickerRepositoryImpl( secureSettingsRepository = getSecureSettingsRepository(appContext), registry = getClockRegistry(appContext), scope = getApplicationCoroutineScope(), mainDispatcher = mainDispatcher, ), snapshotRestorer = { getClockPickerSnapshotRestorer(appContext) }, ) .also { clockPickerInteractor = it } } override fun getClockCarouselViewModelFactory( interactor: ClockPickerInteractor, clockViewFactory: ClockViewFactory, Loading @@ -331,7 +300,7 @@ constructor( ScreenSizeCalculator.getInstance() .getScreenSize(activity.windowManager.defaultDisplay), WallpaperManager.getInstance(activity.applicationContext), getClockRegistry(activity.applicationContext), clockRegistry.get(), ) .also { clockViewFactory = it Loading @@ -347,20 +316,11 @@ constructor( } } private fun getClockPickerSnapshotRestorer( context: Context, ): ClockPickerSnapshotRestorer { return clockPickerSnapshotRestorer ?: ClockPickerSnapshotRestorer(getClockPickerInteractor(context)).also { clockPickerSnapshotRestorer = it } } override fun getWallpaperColorResources( wallpaperColors: WallpaperColors, context: Context ): WallpaperColorResources { return ThemedWallpaperColorResources(wallpaperColors, getSecureSettingsRepository(context)) return ThemedWallpaperColorResources(wallpaperColors, secureSettingsRepository.get()) } override fun getColorPickerViewModelFactory(context: Context): ColorPickerViewModel.Factory { Loading Loading @@ -424,7 +384,7 @@ constructor( return clockSettingsViewModelFactory ?: ClockSettingsViewModel.Factory( context.applicationContext, getClockPickerInteractor(context), clockPickerInteractor.get(), colorPickerInteractor.get(), getUserEventLogger(), ) { clockId -> Loading
src/com/android/customization/picker/clock/data/repository/ClockPickerRepositoryImpl.kt +12 −5 Original line number Diff line number Diff line Loading @@ -24,6 +24,9 @@ import com.android.customization.picker.clock.shared.model.ClockMetadataModel import com.android.systemui.plugins.clocks.ClockMetadata import com.android.systemui.shared.clocks.ClockRegistry import com.android.systemui.shared.settings.data.repository.SecureSettingsRepository import com.android.wallpaper.picker.di.modules.MainDispatcher import javax.inject.Inject import javax.inject.Singleton import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi Loading @@ -42,11 +45,14 @@ import kotlinx.coroutines.flow.shareIn import org.json.JSONObject /** Implementation of [ClockPickerRepository], using [ClockRegistry]. */ class ClockPickerRepositoryImpl( @Singleton class ClockPickerRepositoryImpl @Inject constructor( private val secureSettingsRepository: SecureSettingsRepository, private val registry: ClockRegistry, scope: CoroutineScope, mainDispatcher: CoroutineDispatcher, @MainDispatcher mainScope: CoroutineScope, @MainDispatcher mainDispatcher: CoroutineDispatcher, ) : ClockPickerRepository { @OptIn(ExperimentalCoroutinesApi::class) Loading Loading @@ -94,7 +100,8 @@ class ClockPickerRepositoryImpl( ?.toModel( isSelected = true, selectedColorId = metadata?.getSelectedColorId(), colorTone = metadata?.getColorTone() colorTone = metadata?.getColorTone() ?: ClockMetadataModel.DEFAULT_COLOR_TONE_PROGRESS, seedColor = registry.seedColor ) Loading Loading @@ -151,7 +158,7 @@ class ClockPickerRepositoryImpl( .map { isDynamic -> if (isDynamic) ClockSize.DYNAMIC else ClockSize.SMALL } .distinctUntilChanged() .shareIn( scope = scope, scope = mainScope, started = SharingStarted.Eagerly, replay = 1, ) Loading
src/com/android/customization/picker/clock/domain/interactor/ClockPickerInteractor.kt +21 −15 Original line number Diff line number Diff line Loading @@ -23,7 +23,8 @@ import com.android.customization.picker.clock.data.repository.ClockPickerReposit import com.android.customization.picker.clock.shared.ClockSize import com.android.customization.picker.clock.shared.model.ClockMetadataModel import com.android.customization.picker.clock.shared.model.ClockSnapshotModel import javax.inject.Provider import javax.inject.Inject import javax.inject.Singleton import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.firstOrNull Loading @@ -33,9 +34,12 @@ import kotlinx.coroutines.flow.map * Interactor for accessing application clock settings, as well as selecting and configuring custom * clocks. */ class ClockPickerInteractor( @Singleton class ClockPickerInteractor @Inject constructor( private val repository: ClockPickerRepository, private val snapshotRestorer: Provider<ClockPickerSnapshotRestorer>, private val snapshotRestorer: ClockPickerSnapshotRestorer, ) { val allClocks: Flow<List<ClockMetadataModel>> = repository.allClocks Loading Loading @@ -78,7 +82,7 @@ class ClockPickerInteractor( setClockOption(ClockSnapshotModel(clockSize = size)) } suspend fun setClockOption(clockSnapshotModel: ClockSnapshotModel) { private suspend fun setClockOption(clockSnapshotModel: ClockSnapshotModel) { // [ClockCarouselViewModel] is monitoring the [ClockPickerInteractor.setSelectedClock] job, // so it needs to finish last. storeCurrentClockOption(clockSnapshotModel) Loading @@ -94,6 +98,11 @@ class ClockPickerInteractor( clockSnapshotModel.clockId?.let { repository.setSelectedClock(it) } } private suspend fun storeCurrentClockOption(clockSnapshotModel: ClockSnapshotModel) { val option = getCurrentClockToRestore(clockSnapshotModel) snapshotRestorer.storeSnapshot(option) } /** * Gets the [ClockSnapshotModel] from the storage and override with [latestOption]. * Loading @@ -103,19 +112,16 @@ class ClockPickerInteractor( * [selectedColorId] and [seedColor] have null state collide with nullable type, but we know * they are presented whenever there's a [colorToneProgress]. */ suspend fun getCurrentClockToRestore(latestOption: ClockSnapshotModel? = null) = private suspend fun getCurrentClockToRestore(latestOption: ClockSnapshotModel) = ClockSnapshotModel( clockId = latestOption?.clockId ?: selectedClockId.firstOrNull(), clockSize = latestOption?.clockSize ?: selectedClockSize.firstOrNull(), colorToneProgress = latestOption?.colorToneProgress ?: colorToneProgress.firstOrNull(), selectedColorId = latestOption?.colorToneProgress?.let { latestOption.selectedColorId } clockId = latestOption.clockId ?: selectedClockId.firstOrNull(), clockSize = latestOption.clockSize ?: selectedClockSize.firstOrNull(), colorToneProgress = latestOption.colorToneProgress ?: colorToneProgress.firstOrNull(), selectedColorId = latestOption.colorToneProgress?.let { latestOption.selectedColorId } ?: selectedColorId.firstOrNull(), seedColor = latestOption?.colorToneProgress?.let { latestOption.seedColor } seedColor = latestOption.colorToneProgress?.let { latestOption.seedColor } ?: seedColor.firstOrNull(), ) private suspend fun storeCurrentClockOption(clockSnapshotModel: ClockSnapshotModel) { val option = getCurrentClockToRestore(clockSnapshotModel) snapshotRestorer.get().storeSnapshot(option) } }
src/com/android/customization/picker/clock/domain/interactor/ClockPickerSnapshotRestorer.kt +36 −4 Original line number Diff line number Diff line Loading @@ -19,14 +19,22 @@ package com.android.customization.picker.clock.domain.interactor import android.text.TextUtils import android.util.Log import com.android.customization.picker.clock.data.repository.ClockPickerRepository import com.android.customization.picker.clock.shared.model.ClockSnapshotModel import com.android.wallpaper.picker.undo.domain.interactor.SnapshotRestorer import com.android.wallpaper.picker.undo.domain.interactor.SnapshotStore import com.android.wallpaper.picker.undo.shared.model.RestorableSnapshot import javax.inject.Inject import javax.inject.Singleton import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.firstOrNull import kotlinx.coroutines.flow.map /** Handles state restoration for clocks. */ class ClockPickerSnapshotRestorer(private val interactor: ClockPickerInteractor) : SnapshotRestorer { @Singleton class ClockPickerSnapshotRestorer @Inject constructor(private val repository: ClockPickerRepository) : SnapshotRestorer { private var snapshotStore: SnapshotStore = SnapshotStore.NOOP private var originalOption: ClockSnapshotModel? = null Loading @@ -34,7 +42,23 @@ class ClockPickerSnapshotRestorer(private val interactor: ClockPickerInteractor) store: SnapshotStore, ): RestorableSnapshot { snapshotStore = store originalOption = interactor.getCurrentClockToRestore() originalOption = ClockSnapshotModel( clockId = repository.selectedClock .map { clock -> clock.clockId } .distinctUntilChanged() .firstOrNull(), clockSize = repository.selectedClockSize.firstOrNull(), colorToneProgress = repository.selectedClock.map { clock -> clock.colorToneProgress }.firstOrNull(), selectedColorId = repository.selectedClock .map { clock -> clock.selectedColorId } .distinctUntilChanged() .firstOrNull(), seedColor = repository.selectedClock.map { clock -> clock.seedColor }.firstOrNull(), ) return snapshot(originalOption) } Loading @@ -58,7 +82,15 @@ class ClockPickerSnapshotRestorer(private val interactor: ClockPickerInteractor) ) } interactor.setClockOption(optionToRestore) optionToRestore.clockSize?.let { repository.setClockSize(it) } optionToRestore.colorToneProgress?.let { repository.setClockColor( selectedColorId = optionToRestore.selectedColorId, colorToneProgress = optionToRestore.colorToneProgress, seedColor = optionToRestore.seedColor ) } optionToRestore.clockId?.let { repository.setSelectedClock(it) } } } Loading