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

Commit 03c08f55 authored by Catherine Liang's avatar Catherine Liang Committed by Automerger Merge Worker
Browse files

Merge "Integrate Color Picker into Preview Loading Animation (2/3)" into...

Merge "Integrate Color Picker into Preview Loading Animation (2/3)" into udc-qpr-dev am: 13023b16 am: 1b323bdc

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/ThemePicker/+/23906171



Change-Id: I8007e0f1855278da42210ccb50d20a7357b1e453
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 99210867 1b323bdc
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import com.android.customization.model.themedicon.domain.interactor.ThemedIconIn
import com.android.customization.model.themedicon.domain.interactor.ThemedIconSnapshotRestorer;
import com.android.customization.picker.clock.ui.view.ClockViewFactory;
import com.android.customization.picker.clock.ui.viewmodel.ClockCarouselViewModel;
import com.android.customization.picker.color.domain.interactor.ColorPickerInteractor;
import com.android.customization.picker.color.ui.section.ColorSectionController2;
import com.android.customization.picker.color.ui.viewmodel.ColorPickerViewModel;
import com.android.customization.picker.notifications.ui.section.NotificationSectionController;
@@ -61,6 +62,7 @@ public final class DefaultCustomizationSections implements CustomizationSections
    private final DarkModeSnapshotRestorer mDarkModeSnapshotRestorer;
    private final ThemedIconSnapshotRestorer mThemedIconSnapshotRestorer;
    private final ThemedIconInteractor mThemedIconInteractor;
    private final ColorPickerInteractor mColorPickerInteractor;

    public DefaultCustomizationSections(
            ColorPickerViewModel.Factory colorPickerViewModelFactory,
@@ -73,7 +75,8 @@ public final class DefaultCustomizationSections implements CustomizationSections
            ClockViewFactory clockViewFactory,
            DarkModeSnapshotRestorer darkModeSnapshotRestorer,
            ThemedIconSnapshotRestorer themedIconSnapshotRestorer,
            ThemedIconInteractor themedIconInteractor) {
            ThemedIconInteractor themedIconInteractor,
            ColorPickerInteractor colorPickerInteractor) {
        mColorPickerViewModelFactory = colorPickerViewModelFactory;
        mKeyguardQuickAffordancePickerInteractor = keyguardQuickAffordancePickerInteractor;
        mKeyguardQuickAffordancePickerViewModelFactory =
@@ -85,6 +88,7 @@ public final class DefaultCustomizationSections implements CustomizationSections
        mDarkModeSnapshotRestorer = darkModeSnapshotRestorer;
        mThemedIconSnapshotRestorer = themedIconSnapshotRestorer;
        mThemedIconInteractor = themedIconInteractor;
        mColorPickerInteractor = colorPickerInteractor;
    }

    @Override
@@ -121,6 +125,7 @@ public final class DefaultCustomizationSections implements CustomizationSections
                        sectionNavigationController,
                        wallpaperInteractor,
                        mThemedIconInteractor,
                        mColorPickerInteractor,
                        wallpaperManager,
                        isTwoPaneAndSmallWidth,
                        customizationPickerViewModel)
@@ -134,6 +139,7 @@ public final class DefaultCustomizationSections implements CustomizationSections
                                wallpaperPreviewNavigator,
                                wallpaperInteractor,
                                mThemedIconInteractor,
                                mColorPickerInteractor,
                                wallpaperManager,
                                isTwoPaneAndSmallWidth,
                                customizationPickerViewModel));
+1 −0
Original line number Diff line number Diff line
@@ -156,6 +156,7 @@ internal constructor(
                    getDarkModeSnapshotRestorer(activity),
                    getThemedIconSnapshotRestorer(activity),
                    getThemedIconInteractor(),
                    getColorPickerInteractor(activity, getWallpaperColorsViewModel()),
                )
                .also { customizationSections = it }
    }
+3 −0
Original line number Diff line number Diff line
@@ -19,12 +19,15 @@ package com.android.customization.picker.color.data.repository
import com.android.customization.picker.color.shared.model.ColorOptionModel
import com.android.customization.picker.color.shared.model.ColorType
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow

/**
 * Abstracts access to application state related to functionality for selecting, picking, or setting
 * system color.
 */
interface ColorPickerRepository {
    /** Whether the system color is in the process of being updated */
    val isApplyingSystemColor: StateFlow<Boolean>

    /** List of wallpaper and preset color options on the device, categorized by Color Type */
    val colorOptions: Flow<Map<ColorType, List<ColorOptionModel>>>
+17 −2
Original line number Diff line number Diff line
@@ -27,7 +27,9 @@ 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.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.suspendCancellableCoroutine
@@ -43,9 +45,17 @@ class ColorPickerRepositoryImpl(
        wallpaperColorsViewModel.homeWallpaperColors
    private val lockWallpaperColors: StateFlow<WallpaperColorsModel?> =
        wallpaperColorsViewModel.lockWallpaperColors
    private var selectedColorOption: MutableStateFlow<ColorOptionModel> =
        MutableStateFlow(getCurrentColorOption())

    private val _isApplyingSystemColor = MutableStateFlow(false)
    override val isApplyingSystemColor = _isApplyingSystemColor.asStateFlow()

    override val colorOptions: Flow<Map<ColorType, List<ColorOptionModel>>> =
        combine(homeWallpaperColors, lockWallpaperColors) { homeColors, lockColors ->
        combine(homeWallpaperColors, lockWallpaperColors, selectedColorOption) {
                homeColors,
                lockColors,
                _ ->
                homeColors to lockColors
            }
            .map { (homeColors, lockColors) ->
@@ -109,17 +119,21 @@ class ColorPickerRepositoryImpl(
                }
            }

    override suspend fun select(colorOptionModel: ColorOptionModel) =
    override suspend fun select(colorOptionModel: ColorOptionModel) {
        _isApplyingSystemColor.value = true
        suspendCancellableCoroutine { continuation ->
            colorManager.apply(
                colorOptionModel.colorOption,
                object : CustomizationManager.Callback {
                    override fun onSuccess() {
                        _isApplyingSystemColor.value = false
                        selectedColorOption.value = colorOptionModel
                        continuation.resumeWith(Result.success(Unit))
                    }

                    override fun onError(throwable: Throwable?) {
                        Log.w(TAG, "Apply theme with error", throwable)
                        _isApplyingSystemColor.value = false
                        continuation.resumeWith(
                            Result.failure(throwable ?: Throwable("Error loading theme bundles"))
                        )
@@ -127,6 +141,7 @@ class ColorPickerRepositoryImpl(
                }
            )
        }
    }

    override fun getCurrentColorOption(): ColorOptionModel {
        val overlays = colorManager.currentOverlays
+3 −0
Original line number Diff line number Diff line
@@ -29,6 +29,9 @@ import kotlinx.coroutines.flow.asStateFlow

class FakeColorPickerRepository(private val context: Context) : ColorPickerRepository {

    private val _isApplyingSystemColor = MutableStateFlow(false)
    override val isApplyingSystemColor = _isApplyingSystemColor.asStateFlow()

    private lateinit var selectedColorOption: ColorOptionModel

    private val _colorOptions =
Loading