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

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

Snap for 9667109 from ea57f7b5 to tm-qpr3-release

Change-Id: I40176c43c6dd31ca205b2b4a4708285e49f6efcb
parents 6a2f1680 ea57f7b5
Loading
Loading
Loading
Loading
+69 −54
Original line number Diff line number Diff line
@@ -14,8 +14,12 @@
     limitations under the License.
-->
<!-- Content description is set programmatically on the parent FrameLayout -->
<FrameLayout
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
    <FrameLayout
        android:id="@+id/icon_container"
        android:layout_width="@dimen/option_tile_width"
        android:layout_height="@dimen/option_tile_width"
@@ -76,3 +80,14 @@
            android:src="@drawable/color_chip_seed_filled3"
            android:importantForAccessibility="no" />
    </FrameLayout>

    <TextView
        android:id="@+id/option_title"
        android:layout_width="@dimen/option_tile_width"
        android:layout_height="wrap_content"
        android:layout_marginTop="@dimen/option_bottom_margin"
        android:textColor="@color/text_color_primary"
        android:visibility="gone"
        android:gravity="center" />
</LinearLayout>
+4 −1
Original line number Diff line number Diff line
@@ -67,5 +67,8 @@ interface CustomizationInjector : Injector {

    fun getClockViewFactory(activity: Activity): ClockViewFactory

    fun getClockSettingsViewModelFactory(context: Context): ClockSettingsViewModel.Factory
    fun getClockSettingsViewModelFactory(
        context: Context,
        wallpaperColorsViewModel: WallpaperColorsViewModel,
    ): ClockSettingsViewModel.Factory
}
+5 −0
Original line number Diff line number Diff line
@@ -418,11 +418,16 @@ open class ThemePickerInjector : WallpaperPicker2Injector(), CustomizationInject

    override fun getClockSettingsViewModelFactory(
        context: Context,
        wallpaperColorsViewModel: WallpaperColorsViewModel,
    ): ClockSettingsViewModel.Factory {
        return clockSettingsViewModelFactory
            ?: ClockSettingsViewModel.Factory(
                    context,
                    getClockPickerInteractor(context),
                    getColorPickerInteractor(
                        context,
                        wallpaperColorsViewModel,
                    ),
                )
                .also { clockSettingsViewModelFactory = it }
    }
+4 −1
Original line number Diff line number Diff line
@@ -105,7 +105,10 @@ class ClockSettingsFragment : AppbarFragment() {
            view,
            ViewModelProvider(
                    requireActivity(),
                    injector.getClockSettingsViewModelFactory(context),
                    injector.getClockSettingsViewModelFactory(
                        context,
                        injector.getWallpaperColorsViewModel(),
                    ),
                )
                .get(),
            this@ClockSettingsFragment,
+49 −30
Original line number Diff line number Diff line
@@ -16,13 +16,15 @@
package com.android.customization.picker.clock.ui.viewmodel

import android.content.Context
import android.graphics.Color
import androidx.core.graphics.ColorUtils
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import com.android.customization.model.color.ColorSeedOption
import com.android.customization.picker.clock.domain.interactor.ClockPickerInteractor
import com.android.customization.picker.clock.shared.ClockSize
import com.android.customization.picker.color.domain.interactor.ColorPickerInteractor
import com.android.customization.picker.color.shared.model.ColorType
import com.android.customization.picker.color.ui.viewmodel.ColorOptionViewModel
import com.android.wallpaper.R
import kotlin.math.abs
@@ -34,6 +36,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapLatest
import kotlinx.coroutines.flow.shareIn
@@ -42,7 +45,11 @@ import kotlinx.coroutines.launch

/** View model for the clock settings screen. */
class ClockSettingsViewModel
private constructor(context: Context, private val interactor: ClockPickerInteractor) : ViewModel() {
private constructor(
    context: Context,
    private val clockPickerInteractor: ClockPickerInteractor,
    private val colorPickerInteractor: ColorPickerInteractor,
) : ViewModel() {

    enum class Tab {
        COLOR,
@@ -58,7 +65,7 @@ private constructor(context: Context, private val interactor: ClockPickerInterac
     * level of the system theme color.
     */
    private val saturationLevel: Flow<Float?> =
        interactor.selectedClockColor
        clockPickerInteractor.selectedClockColor
            .map { selectedColor ->
                if (selectedColor == null) {
                    null
@@ -95,38 +102,48 @@ private constructor(context: Context, private val interactor: ClockPickerInterac
        selectedOption?.let { option ->
            ColorUtils.colorToHSL(option.color0, helperColorHsl)
            helperColorHsl[1] = saturation
            interactor.setClockColor(ColorUtils.HSLToColor(helperColorHsl))
            clockPickerInteractor.setClockColor(ColorUtils.HSLToColor(helperColorHsl))
        }
    }

    @OptIn(ExperimentalCoroutinesApi::class)
    val colorOptions: StateFlow<List<ColorOptionViewModel>> =
        interactor.selectedClockColor
            .mapLatest { selectedColor ->
        combine(
                colorPickerInteractor.colorOptions,
                clockPickerInteractor.selectedClockColor,
                ::Pair,
            )
            .mapLatest { (colorOptions, selectedColor) ->
                // Use mapLatest and delay(100) here to prevent too many selectedClockColor update
                // events from ClockRegistry upstream, caused by sliding the saturation level bar.
                delay(COLOR_OPTIONS_EVENT_UPDATE_DELAY_MILLIS)
                buildList {
                    // TODO (b/241966062) Change design of the placeholder for default theme color
                    val defaultThemeColor =
                        colorOptions[ColorType.WALLPAPER_COLOR]?.find { it.isSelected }
                            ?: colorOptions[ColorType.BASIC_COLOR]?.find { it.isSelected }
                    if (defaultThemeColor != null) {
                        val colorSeedOption: ColorSeedOption =
                            defaultThemeColor.colorOption as ColorSeedOption
                        val colors = colorSeedOption.previewInfo.resolveColors(context.resources)
                        add(
                            ColorOptionViewModel(
                            color0 = Color.TRANSPARENT,
                            color1 = Color.TRANSPARENT,
                            color2 = Color.TRANSPARENT,
                            color3 = Color.TRANSPARENT,
                                color0 = colors[0],
                                color1 = colors[1],
                                color2 = colors[2],
                                color3 = colors[3],
                                contentDescription =
                                context.getString(
                                    R.string.content_description_color_option,
                                ),
                                    colorSeedOption.getContentDescription(context).toString(),
                                title = context.getString(R.string.default_theme_title),
                                isSelected = selectedColor == null,
                                onClick =
                                    if (selectedColor == null) {
                                        null
                                    } else {
                                    { interactor.setClockColor(null) }
                                        { clockPickerInteractor.setClockColor(null) }
                                    },
                            )
                        )
                    }

                    if (selectedColor != null) {
                        ColorUtils.colorToHSL(selectedColor, helperColorHsl)
@@ -174,7 +191,7 @@ private constructor(context: Context, private val interactor: ClockPickerInterac
                                    if (isSelected) {
                                        null
                                    } else {
                                        { interactor.setClockColor(colorToSet) }
                                        { clockPickerInteractor.setClockColor(colorToSet) }
                                    },
                            )
                        )
@@ -187,10 +204,10 @@ private constructor(context: Context, private val interactor: ClockPickerInterac
                initialValue = emptyList(),
            )

    val selectedClockSize: Flow<ClockSize> = interactor.selectedClockSize
    val selectedClockSize: Flow<ClockSize> = clockPickerInteractor.selectedClockSize

    fun setClockSize(size: ClockSize) {
        viewModelScope.launch { interactor.setClockSize(size) }
        viewModelScope.launch { clockPickerInteractor.setClockSize(size) }
    }

    private val _selectedTabPosition = MutableStateFlow(Tab.COLOR)
@@ -241,13 +258,15 @@ private constructor(context: Context, private val interactor: ClockPickerInterac

    class Factory(
        private val context: Context,
        private val interactor: ClockPickerInteractor,
        private val clockPickerInteractor: ClockPickerInteractor,
        private val colorPickerInteractor: ColorPickerInteractor,
    ) : ViewModelProvider.Factory {
        override fun <T : ViewModel> create(modelClass: Class<T>): T {
            @Suppress("UNCHECKED_CAST")
            return ClockSettingsViewModel(
                context = context,
                interactor = interactor,
                clockPickerInteractor = clockPickerInteractor,
                colorPickerInteractor = colorPickerInteractor,
            )
                as T
        }
Loading