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

Commit 16866668 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 10331563 from 5a76e0ea to udc-release

Change-Id: Id0493dfc91d32421bcb766726edfe6fc4b43ec45
parents bf2bb8fa 5a76e0ea
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -145,6 +145,7 @@ public final class DefaultCustomizationSections implements CustomizationSections
                                        activity,
                                        mColorPickerViewModelFactory)
                                        .get(ColorPickerViewModel.class),
                                wallpaperColorsViewModel,
                                lifecycleOwner),
                        // Wallpaper quick switch section.
                        new WallpaperQuickSwitchSectionController(
+2 −1
Original line number Diff line number Diff line
@@ -439,7 +439,8 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
                    repository =
                        ColorPickerRepositoryImpl(
                            wallpaperColorsViewModel,
                            getColorCustomizationManager(appContext)
                            getColorCustomizationManager(appContext),
                            WallpaperManager.getInstance(appContext),
                        ),
                    snapshotRestorer = {
                        getColorPickerSnapshotRestorer(appContext, wallpaperColorsViewModel)
+3 −0
Original line number Diff line number Diff line
@@ -37,4 +37,7 @@ interface ColorPickerRepository {

    /** Returns the current selected color source based on system settings */
    fun getCurrentColorSource(): String?

    /** Retrieves and stores the wallpaper colors for generating wallpaper color options */
    suspend fun loadInitialColors()
}
+39 −5
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@
 */
package com.android.customization.picker.color.data.repository

import android.app.WallpaperColors
import android.app.WallpaperManager
import android.util.Log
import com.android.customization.model.CustomizationManager
import com.android.customization.model.color.ColorCustomizationManager
@@ -25,23 +25,27 @@ 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.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlinx.coroutines.withContext

// TODO (b/262924623): refactor to remove dependency on ColorCustomizationManager & ColorOption
// TODO (b/268203200): Create test for ColorPickerRepositoryImpl
class ColorPickerRepositoryImpl(
    wallpaperColorsViewModel: WallpaperColorsViewModel,
    private val wallpaperColorsViewModel: WallpaperColorsViewModel,
    private val colorManager: ColorCustomizationManager,
    private val wallpaperManager: WallpaperManager,
) : 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>>> =
@@ -50,7 +54,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?>?) {
@@ -132,6 +155,17 @@ class ColorPickerRepositoryImpl(
        return colorManager.currentColorSource
    }

    override suspend fun loadInitialColors() {
        withContext(Dispatchers.IO) {
            val lockColors = wallpaperManager.getWallpaperColors(WallpaperManager.FLAG_LOCK)
            val homeColors = wallpaperManager.getWallpaperColors(WallpaperManager.FLAG_SYSTEM)
            withContext(Dispatchers.Main) {
                wallpaperColorsViewModel.setLockWallpaperColors(lockColors)
                wallpaperColorsViewModel.setHomeWallpaperColors(homeColors)
            }
        }
    }

    private fun ColorOptionImpl.toModel(): ColorOptionModel {
        return ColorOptionModel(
            key = "${this.type}::${this.style}::${this.serializedPackages}",
+2 −0
Original line number Diff line number Diff line
@@ -166,6 +166,8 @@ class FakeColorPickerRepository(private val context: Context) : ColorPickerRepos
            else -> null
        }

    override suspend fun loadInitialColors() {}

    private fun ColorOptionModel.testEquals(other: Any?): Boolean {
        if (other == null) {
            return false
Loading