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

Commit b70f0f91 authored by Catherine Liang's avatar Catherine Liang Committed by Android (Google) Code Review
Browse files

Merge "Wallpaper Quick Switcher Reload (2/3)" into tm-qpr-dev

parents 068d5c3c 8a2d5239
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -27,8 +27,10 @@ import com.android.customization.model.grid.ui.viewmodel.GridScreenViewModel
import com.android.customization.module.ThemePickerInjector
import com.android.wallpaper.R
import com.android.wallpaper.module.CurrentWallpaperInfoFactory
import com.android.wallpaper.module.CustomizationSections
import com.android.wallpaper.module.InjectorProvider
import com.android.wallpaper.picker.AppbarFragment
import com.android.wallpaper.picker.customization.domain.interactor.WallpaperInteractor
import com.android.wallpaper.picker.customization.ui.binder.ScreenPreviewBinder
import com.android.wallpaper.picker.customization.ui.viewmodel.ScreenPreviewViewModel
import com.android.wallpaper.util.PreviewUtils
@@ -55,7 +57,12 @@ class GridFragment2 : AppbarFragment() {
        val injector = InjectorProvider.getInjector() as ThemePickerInjector

        val wallpaperInfoFactory = injector.getCurrentWallpaperInfoFactory(requireContext())
        var screenPreviewBinding = bindScreenPreview(view, wallpaperInfoFactory)
        var screenPreviewBinding =
            bindScreenPreview(
                view,
                wallpaperInfoFactory,
                injector.getWallpaperInteractor(requireContext())
            )

        val viewModelFactory = injector.getGridScreenViewModelFactory(requireContext())
        GridScreenBinder.bind(
@@ -69,7 +76,12 @@ class GridFragment2 : AppbarFragment() {
            backgroundDispatcher = Dispatchers.IO,
            onOptionsChanged = {
                screenPreviewBinding.destroy()
                screenPreviewBinding = bindScreenPreview(view, wallpaperInfoFactory)
                screenPreviewBinding =
                    bindScreenPreview(
                        view,
                        wallpaperInfoFactory,
                        injector.getWallpaperInteractor(requireContext())
                    )
            }
        )

@@ -83,6 +95,7 @@ class GridFragment2 : AppbarFragment() {
    private fun bindScreenPreview(
        view: View,
        wallpaperInfoFactory: CurrentWallpaperInfoFactory,
        wallpaperInteractor: WallpaperInteractor,
    ): ScreenPreviewBinder.Binding {
        return ScreenPreviewBinder.bind(
            activity = requireActivity(),
@@ -108,9 +121,12 @@ class GridFragment2 : AppbarFragment() {
                            )
                        }
                    },
                    wallpaperInteractor = wallpaperInteractor,
                ),
            lifecycleOwner = this,
            offsetToStart = false,
            screen = CustomizationSections.Screen.HOME_SCREEN,
            onPreviewDirty = { activity?.recreate() },
        )
    }
}
+7 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import com.android.wallpaper.model.WallpaperPreviewNavigator;
import com.android.wallpaper.model.WallpaperSectionController;
import com.android.wallpaper.module.CurrentWallpaperInfoFactory;
import com.android.wallpaper.module.CustomizationSections;
import com.android.wallpaper.picker.customization.domain.interactor.WallpaperInteractor;
import com.android.wallpaper.picker.customization.ui.section.ConnectedSectionController;
import com.android.wallpaper.picker.customization.ui.section.ScreenPreviewSectionController;
import com.android.wallpaper.picker.customization.ui.section.WallpaperQuickSwitchSectionController;
@@ -97,7 +98,8 @@ public final class DefaultCustomizationSections implements CustomizationSections
            @Nullable Bundle savedInstanceState,
            CurrentWallpaperInfoFactory wallpaperInfoFactory,
            DisplayUtils displayUtils,
            WallpaperQuickSwitchViewModel wallpaperQuickSwitchViewModel) {
            WallpaperQuickSwitchViewModel wallpaperQuickSwitchViewModel,
            WallpaperInteractor wallpaperInteractor) {
        List<CustomizationSectionController<?>> sectionControllers = new ArrayList<>();

        // Wallpaper section.
@@ -112,7 +114,8 @@ public final class DefaultCustomizationSections implements CustomizationSections
                        displayUtils,
                        mClockCarouselViewModel,
                        mClockViewFactory,
                        sectionNavigationController)
                        sectionNavigationController,
                        wallpaperInteractor)
                        : new ScreenPreviewSectionController(
                                activity,
                                lifecycleOwner,
@@ -120,7 +123,8 @@ public final class DefaultCustomizationSections implements CustomizationSections
                                wallpaperInfoFactory,
                                wallpaperColorsViewModel,
                                displayUtils,
                                sectionNavigationController));
                                sectionNavigationController,
                                wallpaperInteractor));

        sectionControllers.add(
                new ConnectedSectionController(
+39 −1
Original line number Diff line number Diff line
@@ -21,10 +21,13 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.text.TextUtils
import androidx.activity.ComponentActivity
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.ViewModelProvider
import com.android.customization.model.color.ColorCustomizationManager
import com.android.customization.model.color.ColorOptionsProvider
import com.android.customization.model.grid.GridOptionsManager
import com.android.customization.model.grid.data.repository.GridRepositoryImpl
import com.android.customization.model.grid.domain.interactor.GridInteractor
@@ -72,6 +75,9 @@ import com.android.wallpaper.picker.CustomizationPickerActivity
import com.android.wallpaper.picker.ImagePreviewFragment
import com.android.wallpaper.picker.LivePreviewFragment
import com.android.wallpaper.picker.PreviewFragment
import com.android.wallpaper.picker.customization.data.content.WallpaperClientImpl
import com.android.wallpaper.picker.customization.data.repository.WallpaperRepository
import com.android.wallpaper.picker.customization.domain.interactor.WallpaperInteractor
import com.android.wallpaper.picker.undo.domain.interactor.SnapshotRestorer
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
@@ -82,6 +88,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
    private var customizationSections: CustomizationSections? = null
    private var userEventLogger: UserEventLogger? = null
    private var prefs: WallpaperPreferences? = null
    private var wallpaperInteractor: WallpaperInteractor? = null
    private var keyguardQuickAffordancePickerInteractor: KeyguardQuickAffordancePickerInteractor? =
        null
    private var keyguardQuickAffordancePickerViewModelFactory:
@@ -102,6 +109,7 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
    private var colorPickerInteractor: ColorPickerInteractor? = null
    private var colorPickerViewModelFactory: ColorPickerViewModel.Factory? = null
    private var colorPickerSnapshotRestorer: ColorPickerSnapshotRestorer? = null
    private var colorCustomizationManager: ColorCustomizationManager? = null
    private var darkModeSnapshotRestorer: DarkModeSnapshotRestorer? = null
    private var themedIconSnapshotRestorer: ThemedIconSnapshotRestorer? = null
    private var themedIconInteractor: ThemedIconInteractor? = null
@@ -209,6 +217,25 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
        return ThemeManager(provider, activity, overlayManagerCompat, logger)
    }

    override fun getWallpaperInteractor(context: Context): WallpaperInteractor {
        return wallpaperInteractor
            ?: WallpaperInteractor(
                    repository =
                        WallpaperRepository(
                            scope = GlobalScope,
                            client = WallpaperClientImpl(context = context),
                            backgroundDispatcher = Dispatchers.IO,
                        ),
                    shouldHandleReload = {
                        TextUtils.equals(
                            getColorCustomizationManager(context).currentColorSource,
                            ColorOptionsProvider.COLOR_SOURCE_PRESET
                        )
                    }
                )
                .also { wallpaperInteractor = it }
    }

    override fun getKeyguardQuickAffordancePickerInteractor(
        context: Context
    ): KeyguardQuickAffordancePickerInteractor {
@@ -352,7 +379,11 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
    ): ColorPickerInteractor {
        return colorPickerInteractor
            ?: ColorPickerInteractor(
                    repository = ColorPickerRepositoryImpl(context, wallpaperColorsViewModel),
                    repository =
                        ColorPickerRepositoryImpl(
                            wallpaperColorsViewModel,
                            getColorCustomizationManager(context)
                        ),
                    snapshotRestorer = {
                        getColorPickerSnapshotRestorer(context, wallpaperColorsViewModel)
                    }
@@ -383,6 +414,13 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject
                .also { colorPickerSnapshotRestorer = it }
    }

    private fun getColorCustomizationManager(context: Context): ColorCustomizationManager {
        return colorCustomizationManager
            ?: ColorCustomizationManager.getInstance(context, OverlayManagerCompat(context)).also {
                colorCustomizationManager = it
            }
    }

    fun getDarkModeSnapshotRestorer(
        context: Context,
    ): DarkModeSnapshotRestorer {
+3 −0
Original line number Diff line number Diff line
@@ -34,4 +34,7 @@ interface ColorPickerRepository {

    /** Returns the current selected color option based on system settings */
    fun getCurrentColorOption(): ColorOptionModel

    /** Returns the current selected color source based on system settings */
    fun getCurrentColorSource(): String?
}
+5 −5
Original line number Diff line number Diff line
@@ -17,14 +17,12 @@
package com.android.customization.picker.color.data.repository

import android.app.WallpaperColors
import android.content.Context
import android.util.Log
import com.android.customization.model.CustomizationManager
import com.android.customization.model.color.ColorBundle
import com.android.customization.model.color.ColorCustomizationManager
import com.android.customization.model.color.ColorOption
import com.android.customization.model.color.ColorSeedOption
import com.android.customization.model.theme.OverlayManagerCompat
import com.android.customization.picker.color.shared.model.ColorOptionModel
import com.android.customization.picker.color.shared.model.ColorType
import com.android.systemui.monet.Style
@@ -38,16 +36,14 @@ import kotlinx.coroutines.suspendCancellableCoroutine
// TODO (b/262924623): refactor to remove dependency on ColorCustomizationManager & ColorOption
// TODO (b/268203200): Create test for ColorPickerRepositoryImpl
class ColorPickerRepositoryImpl(
    context: Context,
    wallpaperColorsViewModel: WallpaperColorsViewModel,
    private val colorManager: ColorCustomizationManager,
) : ColorPickerRepository {

    private val homeWallpaperColors: StateFlow<WallpaperColors?> =
        wallpaperColorsViewModel.homeWallpaperColors
    private val lockWallpaperColors: StateFlow<WallpaperColors?> =
        wallpaperColorsViewModel.lockWallpaperColors
    private val colorManager: ColorCustomizationManager =
        ColorCustomizationManager.getInstance(context, OverlayManagerCompat(context))

    override val colorOptions: Flow<Map<ColorType, List<ColorOptionModel>>> =
        combine(homeWallpaperColors, lockWallpaperColors) { homeColors, lockColors ->
@@ -132,6 +128,10 @@ class ColorPickerRepositoryImpl(
        )
    }

    override fun getCurrentColorSource(): String? {
        return colorManager.currentColorSource
    }

    private fun ColorOption.toModel(): ColorOptionModel {
        return ColorOptionModel(
            key = "${this.style}::${this.serializedPackages}",
Loading