Loading src/com/android/customization/picker/color/data/repository/ColorPickerRepositoryImpl.kt +23 −4 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ */ package com.android.customization.picker.color.data.repository import android.app.WallpaperColors import android.util.Log import com.android.customization.model.CustomizationManager import com.android.customization.model.color.ColorCustomizationManager Loading @@ -25,6 +24,7 @@ import com.android.customization.model.color.ColorOptionImpl import com.android.customization.picker.color.shared.model.ColorOptionModel import com.android.customization.picker.color.shared.model.ColorType import com.android.systemui.monet.Style import com.android.wallpaper.model.WallpaperColorsModel import com.android.wallpaper.model.WallpaperColorsViewModel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.StateFlow Loading @@ -39,9 +39,9 @@ class ColorPickerRepositoryImpl( private val colorManager: ColorCustomizationManager, ) : ColorPickerRepository { private val homeWallpaperColors: StateFlow<WallpaperColors?> = private val homeWallpaperColors: StateFlow<WallpaperColorsModel?> = wallpaperColorsViewModel.homeWallpaperColors private val lockWallpaperColors: StateFlow<WallpaperColors?> = private val lockWallpaperColors: StateFlow<WallpaperColorsModel?> = wallpaperColorsViewModel.lockWallpaperColors override val colorOptions: Flow<Map<ColorType, List<ColorOptionModel>>> = Loading @@ -50,7 +50,26 @@ class ColorPickerRepositoryImpl( } .map { (homeColors, lockColors) -> suspendCancellableCoroutine { continuation -> colorManager.setWallpaperColors(homeColors, lockColors) if ( homeColors is WallpaperColorsModel.Loading || lockColors is WallpaperColorsModel.Loading ) { continuation.resumeWith( Result.success( mapOf( ColorType.WALLPAPER_COLOR to listOf(), ColorType.PRESET_COLOR to listOf() ) ) ) return@suspendCancellableCoroutine } val homeColorsLoaded = homeColors as WallpaperColorsModel.Loaded val lockColorsLoaded = lockColors as WallpaperColorsModel.Loaded colorManager.setWallpaperColors( homeColorsLoaded.colors, lockColorsLoaded.colors ) colorManager.fetchRevampedUIOptions( object : CustomizationManager.OptionsFetchedListener<ColorOption?> { override fun onOptionsLoaded(options: MutableList<ColorOption?>?) { Loading src/com/android/customization/picker/color/ui/fragment/ColorPickerFragment.kt +57 −1 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ package com.android.customization.picker.color.ui.fragment import android.app.WallpaperManager import android.os.Bundle import android.view.LayoutInflater import android.view.View Loading @@ -23,10 +24,13 @@ import android.widget.FrameLayout import androidx.cardview.widget.CardView import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.get import androidx.lifecycle.lifecycleScope import com.android.customization.model.mode.DarkModeSectionController import com.android.customization.module.ThemePickerInjector import com.android.customization.picker.color.ui.binder.ColorPickerBinder import com.android.wallpaper.R import com.android.wallpaper.model.WallpaperColorsModel import com.android.wallpaper.model.WallpaperColorsViewModel import com.android.wallpaper.module.CustomizationSections import com.android.wallpaper.module.InjectorProvider import com.android.wallpaper.picker.AppbarFragment Loading @@ -34,8 +38,11 @@ import com.android.wallpaper.picker.customization.ui.binder.ScreenPreviewBinder import com.android.wallpaper.picker.customization.ui.viewmodel.ScreenPreviewViewModel import com.android.wallpaper.util.DisplayUtils import com.android.wallpaper.util.PreviewUtils import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.launch import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.withContext @OptIn(ExperimentalCoroutinesApi::class) class ColorPickerFragment : AppbarFragment() { Loading Loading @@ -66,6 +73,7 @@ class ColorPickerFragment : AppbarFragment() { val wallpaperInfoFactory = injector.getCurrentWallpaperInfoFactory(requireContext()) val displayUtils: DisplayUtils = injector.getDisplayUtils(requireContext()) val wcViewModel = injector.getWallpaperColorsViewModel() val wallpaperManager = WallpaperManager.getInstance(requireContext()) binding = ColorPickerBinder.bind( Loading Loading @@ -102,6 +110,18 @@ class ColorPickerFragment : AppbarFragment() { suspendCancellableCoroutine { continuation -> wallpaperInfoFactory.createCurrentWallpaperInfos( { homeWallpaper, lockWallpaper, _ -> lifecycleScope.launch { if ( wcViewModel.lockWallpaperColors.value is WallpaperColorsModel.Loading ) { loadInitialColors( wallpaperManager, wcViewModel, CustomizationSections.Screen.LOCK_SCREEN ) } } continuation.resume(lockWallpaper ?: homeWallpaper, null) }, forceReload, Loading Loading @@ -137,6 +157,18 @@ class ColorPickerFragment : AppbarFragment() { suspendCancellableCoroutine { continuation -> wallpaperInfoFactory.createCurrentWallpaperInfos( { homeWallpaper, lockWallpaper, _ -> lifecycleScope.launch { if ( wcViewModel.homeWallpaperColors.value is WallpaperColorsModel.Loading ) { loadInitialColors( wallpaperManager, wcViewModel, CustomizationSections.Screen.HOME_SCREEN ) } } continuation.resume(homeWallpaper ?: lockWallpaper, null) }, forceReload, Loading @@ -144,7 +176,7 @@ class ColorPickerFragment : AppbarFragment() { } }, onWallpaperColorChanged = { colors -> wcViewModel.setLockWallpaperColors(colors) wcViewModel.setHomeWallpaperColors(colors) }, wallpaperInteractor = injector.getWallpaperInteractor(requireContext()), screen = CustomizationSections.Screen.HOME_SCREEN, Loading @@ -168,6 +200,30 @@ class ColorPickerFragment : AppbarFragment() { return view } private suspend fun loadInitialColors( wallpaperManager: WallpaperManager, colorViewModel: WallpaperColorsViewModel, screen: CustomizationSections.Screen, ) { withContext(Dispatchers.IO) { val colors = wallpaperManager.getWallpaperColors( if (screen == CustomizationSections.Screen.LOCK_SCREEN) { WallpaperManager.FLAG_LOCK } else { WallpaperManager.FLAG_SYSTEM } ) withContext(Dispatchers.Main) { if (screen == CustomizationSections.Screen.LOCK_SCREEN) { colorViewModel.setLockWallpaperColors(colors) } else { colorViewModel.setHomeWallpaperColors(colors) } } } } override fun onSaveInstanceState(savedInstanceState: Bundle) { super.onSaveInstanceState(savedInstanceState) binding?.saveInstanceState(savedInstanceState) Loading src/com/android/customization/picker/color/ui/viewmodel/ColorPickerViewModel.kt +62 −53 Original line number Diff line number Diff line Loading @@ -93,7 +93,8 @@ private constructor( /** The list of all color options mapped by their color type */ private val allColorOptions: Flow<Map<ColorType, List<OptionItemViewModel<ColorOptionIconViewModel>>>> = interactor.colorOptions.map { colorOptions -> interactor.colorOptions .map { colorOptions -> colorOptions .map { colorOptionEntry -> colorOptionEntry.key to Loading @@ -107,12 +108,15 @@ private constructor( val isSelectedFlow: StateFlow<Boolean> = interactor.activeColorOption .map { it?.colorOption?.isEquivalent(colorOptionModel.colorOption) it?.colorOption?.isEquivalent( colorOptionModel.colorOption ) ?: colorOptionModel.isSelected } .stateIn(viewModelScope) OptionItemViewModel<ColorOptionIconViewModel>( key = MutableStateFlow(colorOptionModel.key) as StateFlow<String>, key = MutableStateFlow(colorOptionModel.key) as StateFlow<String>, payload = ColorOptionIconViewModel( lightThemeColor0 = lightThemeColors[0], Loading Loading @@ -147,6 +151,11 @@ private constructor( } .toMap() } .shareIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(), replay = 1, ) /** The list of all available color options for the selected Color Type. */ val colorOptions: Flow<List<OptionItemViewModel<ColorOptionIconViewModel>>> = Loading @@ -159,7 +168,7 @@ private constructor( } .shareIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(), started = SharingStarted.Eagerly, replay = 1, ) Loading Loading
src/com/android/customization/picker/color/data/repository/ColorPickerRepositoryImpl.kt +23 −4 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ */ package com.android.customization.picker.color.data.repository import android.app.WallpaperColors import android.util.Log import com.android.customization.model.CustomizationManager import com.android.customization.model.color.ColorCustomizationManager Loading @@ -25,6 +24,7 @@ import com.android.customization.model.color.ColorOptionImpl import com.android.customization.picker.color.shared.model.ColorOptionModel import com.android.customization.picker.color.shared.model.ColorType import com.android.systemui.monet.Style import com.android.wallpaper.model.WallpaperColorsModel import com.android.wallpaper.model.WallpaperColorsViewModel import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.StateFlow Loading @@ -39,9 +39,9 @@ class ColorPickerRepositoryImpl( private val colorManager: ColorCustomizationManager, ) : ColorPickerRepository { private val homeWallpaperColors: StateFlow<WallpaperColors?> = private val homeWallpaperColors: StateFlow<WallpaperColorsModel?> = wallpaperColorsViewModel.homeWallpaperColors private val lockWallpaperColors: StateFlow<WallpaperColors?> = private val lockWallpaperColors: StateFlow<WallpaperColorsModel?> = wallpaperColorsViewModel.lockWallpaperColors override val colorOptions: Flow<Map<ColorType, List<ColorOptionModel>>> = Loading @@ -50,7 +50,26 @@ class ColorPickerRepositoryImpl( } .map { (homeColors, lockColors) -> suspendCancellableCoroutine { continuation -> colorManager.setWallpaperColors(homeColors, lockColors) if ( homeColors is WallpaperColorsModel.Loading || lockColors is WallpaperColorsModel.Loading ) { continuation.resumeWith( Result.success( mapOf( ColorType.WALLPAPER_COLOR to listOf(), ColorType.PRESET_COLOR to listOf() ) ) ) return@suspendCancellableCoroutine } val homeColorsLoaded = homeColors as WallpaperColorsModel.Loaded val lockColorsLoaded = lockColors as WallpaperColorsModel.Loaded colorManager.setWallpaperColors( homeColorsLoaded.colors, lockColorsLoaded.colors ) colorManager.fetchRevampedUIOptions( object : CustomizationManager.OptionsFetchedListener<ColorOption?> { override fun onOptionsLoaded(options: MutableList<ColorOption?>?) { Loading
src/com/android/customization/picker/color/ui/fragment/ColorPickerFragment.kt +57 −1 Original line number Diff line number Diff line Loading @@ -15,6 +15,7 @@ */ package com.android.customization.picker.color.ui.fragment import android.app.WallpaperManager import android.os.Bundle import android.view.LayoutInflater import android.view.View Loading @@ -23,10 +24,13 @@ import android.widget.FrameLayout import androidx.cardview.widget.CardView import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.get import androidx.lifecycle.lifecycleScope import com.android.customization.model.mode.DarkModeSectionController import com.android.customization.module.ThemePickerInjector import com.android.customization.picker.color.ui.binder.ColorPickerBinder import com.android.wallpaper.R import com.android.wallpaper.model.WallpaperColorsModel import com.android.wallpaper.model.WallpaperColorsViewModel import com.android.wallpaper.module.CustomizationSections import com.android.wallpaper.module.InjectorProvider import com.android.wallpaper.picker.AppbarFragment Loading @@ -34,8 +38,11 @@ import com.android.wallpaper.picker.customization.ui.binder.ScreenPreviewBinder import com.android.wallpaper.picker.customization.ui.viewmodel.ScreenPreviewViewModel import com.android.wallpaper.util.DisplayUtils import com.android.wallpaper.util.PreviewUtils import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.launch import kotlinx.coroutines.suspendCancellableCoroutine import kotlinx.coroutines.withContext @OptIn(ExperimentalCoroutinesApi::class) class ColorPickerFragment : AppbarFragment() { Loading Loading @@ -66,6 +73,7 @@ class ColorPickerFragment : AppbarFragment() { val wallpaperInfoFactory = injector.getCurrentWallpaperInfoFactory(requireContext()) val displayUtils: DisplayUtils = injector.getDisplayUtils(requireContext()) val wcViewModel = injector.getWallpaperColorsViewModel() val wallpaperManager = WallpaperManager.getInstance(requireContext()) binding = ColorPickerBinder.bind( Loading Loading @@ -102,6 +110,18 @@ class ColorPickerFragment : AppbarFragment() { suspendCancellableCoroutine { continuation -> wallpaperInfoFactory.createCurrentWallpaperInfos( { homeWallpaper, lockWallpaper, _ -> lifecycleScope.launch { if ( wcViewModel.lockWallpaperColors.value is WallpaperColorsModel.Loading ) { loadInitialColors( wallpaperManager, wcViewModel, CustomizationSections.Screen.LOCK_SCREEN ) } } continuation.resume(lockWallpaper ?: homeWallpaper, null) }, forceReload, Loading Loading @@ -137,6 +157,18 @@ class ColorPickerFragment : AppbarFragment() { suspendCancellableCoroutine { continuation -> wallpaperInfoFactory.createCurrentWallpaperInfos( { homeWallpaper, lockWallpaper, _ -> lifecycleScope.launch { if ( wcViewModel.homeWallpaperColors.value is WallpaperColorsModel.Loading ) { loadInitialColors( wallpaperManager, wcViewModel, CustomizationSections.Screen.HOME_SCREEN ) } } continuation.resume(homeWallpaper ?: lockWallpaper, null) }, forceReload, Loading @@ -144,7 +176,7 @@ class ColorPickerFragment : AppbarFragment() { } }, onWallpaperColorChanged = { colors -> wcViewModel.setLockWallpaperColors(colors) wcViewModel.setHomeWallpaperColors(colors) }, wallpaperInteractor = injector.getWallpaperInteractor(requireContext()), screen = CustomizationSections.Screen.HOME_SCREEN, Loading @@ -168,6 +200,30 @@ class ColorPickerFragment : AppbarFragment() { return view } private suspend fun loadInitialColors( wallpaperManager: WallpaperManager, colorViewModel: WallpaperColorsViewModel, screen: CustomizationSections.Screen, ) { withContext(Dispatchers.IO) { val colors = wallpaperManager.getWallpaperColors( if (screen == CustomizationSections.Screen.LOCK_SCREEN) { WallpaperManager.FLAG_LOCK } else { WallpaperManager.FLAG_SYSTEM } ) withContext(Dispatchers.Main) { if (screen == CustomizationSections.Screen.LOCK_SCREEN) { colorViewModel.setLockWallpaperColors(colors) } else { colorViewModel.setHomeWallpaperColors(colors) } } } } override fun onSaveInstanceState(savedInstanceState: Bundle) { super.onSaveInstanceState(savedInstanceState) binding?.saveInstanceState(savedInstanceState) Loading
src/com/android/customization/picker/color/ui/viewmodel/ColorPickerViewModel.kt +62 −53 Original line number Diff line number Diff line Loading @@ -93,7 +93,8 @@ private constructor( /** The list of all color options mapped by their color type */ private val allColorOptions: Flow<Map<ColorType, List<OptionItemViewModel<ColorOptionIconViewModel>>>> = interactor.colorOptions.map { colorOptions -> interactor.colorOptions .map { colorOptions -> colorOptions .map { colorOptionEntry -> colorOptionEntry.key to Loading @@ -107,12 +108,15 @@ private constructor( val isSelectedFlow: StateFlow<Boolean> = interactor.activeColorOption .map { it?.colorOption?.isEquivalent(colorOptionModel.colorOption) it?.colorOption?.isEquivalent( colorOptionModel.colorOption ) ?: colorOptionModel.isSelected } .stateIn(viewModelScope) OptionItemViewModel<ColorOptionIconViewModel>( key = MutableStateFlow(colorOptionModel.key) as StateFlow<String>, key = MutableStateFlow(colorOptionModel.key) as StateFlow<String>, payload = ColorOptionIconViewModel( lightThemeColor0 = lightThemeColors[0], Loading Loading @@ -147,6 +151,11 @@ private constructor( } .toMap() } .shareIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(), replay = 1, ) /** The list of all available color options for the selected Color Type. */ val colorOptions: Flow<List<OptionItemViewModel<ColorOptionIconViewModel>>> = Loading @@ -159,7 +168,7 @@ private constructor( } .shareIn( scope = viewModelScope, started = SharingStarted.WhileSubscribed(), started = SharingStarted.Eagerly, replay = 1, ) Loading