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

Commit 19f8fd04 authored by George Lin's avatar George Lin
Browse files

Fix smartspace missing on main screen preview (2/3)

1. Fix missing smartspace
2. Make the clock transition smoother

Test: Manually tested.
Bug: 415825642
Flag: com.android.systemui.shared.new_customization_picker_ui
Change-Id: I9c2f39b9a3d4763b186cd24d3ba8d71396c260cf
parent 89b12b91
Loading
Loading
Loading
Loading
+24 −12
Original line number Diff line number Diff line
@@ -58,6 +58,7 @@ import com.android.wallpaper.picker.customization.ui.binder.ColorUpdateBinder
import com.android.wallpaper.picker.customization.ui.binder.CustomizationOptionsBinder
import com.android.wallpaper.picker.customization.ui.binder.DefaultCustomizationOptionsBinder
import com.android.wallpaper.picker.customization.ui.util.CustomizationOptionUtil.CustomizationOption
import com.android.wallpaper.picker.customization.ui.util.ViewAlphaAnimator.animateToAlpha
import com.android.wallpaper.picker.customization.ui.viewmodel.ColorUpdateViewModel
import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationOptionsData
import com.android.wallpaper.picker.customization.ui.viewmodel.CustomizationOptionsViewModel
@@ -553,6 +554,9 @@ constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationO
        }
    }

    // Track the current show clock flag. If it turns from false to true, animate fade-in.
    private var isClockCurrentlyShown: Boolean? = null

    override fun bindClockPreview(
        context: Context,
        clockHostView: View,
@@ -573,13 +577,14 @@ constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationO
                    combine(
                            clockPickerViewModel.previewingClock,
                            clockPickerViewModel.previewingClockSize,
                        ) { clock, size ->
                            clock to size
                        }
                        .collect { (clock, size) ->
                            clockPickerViewModel.showClockControllerView,
                            ::Triple,
                        )
                        .collect { (clock, size, showClock) ->
                            clockHostView.removeAllViews()
                            // For new customization picker, we should get views from clocklayout
                            if (Flags.newCustomizationPickerUi()) {
                                if (showClock) {
                                    clockViewFactory.getController(clock.clockId)?.run {
                                        val cs = ConstraintSet()
                                        clockHostView.addClockViews(this, size, cs)
@@ -589,6 +594,13 @@ constructor(private val defaultCustomizationOptionsBinder: DefaultCustomizationO
                                        cs.applyTo(clockHostView)
                                    }
                                    clockViewFactory.updateTimeFormat(clock.clockId)
                                }
                                val shouldFadeIn = (isClockCurrentlyShown == false) && showClock
                                if (shouldFadeIn) {
                                    clockHostView.alpha = 0F
                                    clockHostView.animateToAlpha(1F)
                                }
                                isClockCurrentlyShown = showClock
                            } else {
                                val clockView =
                                    when (size) {
+28 −0
Original line number Diff line number Diff line
@@ -149,6 +149,34 @@ constructor(
            overridingClock != null && overridingClock.clockId != selectedClock.clockId
        }

    // Represents show and hide of the clock view provided by the picker side.
    private val _showPickerClockControllerView: MutableStateFlow<Boolean> = MutableStateFlow(false)
    val showClockControllerView: Flow<Boolean> = _showPickerClockControllerView.asStateFlow()

    /**
     * Set show or hide to [_showPickerClockControllerView]. We should set show when transition to
     * the secondary clock customization screen ends, and hide when we just start the transition
     * back to the primary screen. See also [setShowKeyguardPreviewRendererSmartspace].
     */
    fun setShowPickerClockControllerView(show: Boolean) {
        _showPickerClockControllerView.value = show
    }

    // Represents show and hide of the clock view and the smartspace at the keygard renderer side.
    private val _showKeyguardPreviewRendererSmartspace: MutableStateFlow<Boolean> =
        MutableStateFlow(false)
    val showKeyguardPreviewRendererSmartspace: Flow<Boolean> =
        _showKeyguardPreviewRendererSmartspace.asStateFlow()

    /**
     * Set show or hide to [_showKeyguardPreviewRendererSmartspace]. We should set show when
     * transition back to the primary screen ends, and hide when we just start the transition to the
     * secondary screen of clock customization. See also [setShowPickerClockControllerView].
     */
    fun setShowKeyguardPreviewRendererSmartspace(show: Boolean) {
        _showKeyguardPreviewRendererSmartspace.value = show
    }

    private suspend fun getIsShadeLayoutWide() = clockPickerInteractor.getIsShadeLayoutWide()

    private suspend fun getUdfpsLocation() = clockPickerInteractor.getUdfpsLocation()
+26 −2
Original line number Diff line number Diff line
@@ -96,10 +96,14 @@ constructor(

    override fun handleBackPressed(): Boolean {
        if (applyButtonState.value == APPLY_BUTTON_ENABLED) {
            defaultCustomizationOptionsViewModel.showDiscardChangesDialogViewModel()
            defaultCustomizationOptionsViewModel.showDiscardChangesDialogViewModel(
                // Hide the picker's clock when we start the transition back to the primary screen.
                onDiscard = { clockPickerViewModel.setShowPickerClockControllerView(false) }
            )
            return true
        }

        // Hide the picker's clock when we start the transition back to the primary screen.
        clockPickerViewModel.setShowPickerClockControllerView(false)
        return defaultCustomizationOptionsViewModel.handleBackPressed()
    }

@@ -110,10 +114,25 @@ constructor(
        gridPickerViewModel.resetPreview()
        appIconPickerViewModel.resetPreview()
        clockPickerViewModel.resetPreview()
        // resetPreview happens when transition back to the primary screen ends. Show the keyguard
        // preview renderer's smartspace and the clock.
        clockPickerViewModel.setShowKeyguardPreviewRendererSmartspace(true)
        colorPickerViewModel2.resetPreview()
        darkModeViewModel.resetPreview()
    }

    override fun onTransitionToSecondaryScreenComplete() {
        defaultCustomizationOptionsViewModel.onTransitionToSecondaryScreenComplete()
        if (
            selectedOption.value ==
                ThemePickerCustomizationOptionUtil.ThemePickerLockCustomizationOption.CLOCK
        ) {
            // Show the picker's clock when we complete the transition to land on the secondary
            // clock customization screen.
            clockPickerViewModel.setShowPickerClockControllerView(true)
        }
    }

    val onCustomizeClockClicked: Flow<(() -> Unit)?> =
        selectedOption.map {
            if (it == null) {
@@ -121,6 +140,11 @@ constructor(
                    defaultCustomizationOptionsViewModel.selectOption(
                        ThemePickerCustomizationOptionUtil.ThemePickerLockCustomizationOption.CLOCK
                    )
                    // When we are about to transition to the clock customization screen, hide the
                    // keyguard preview renderer's smartspace as well as the clock. Because, we will
                    // show the picker's clock controller view clock when the transition ends.
                    // Please also see clockPickerViewModel.setShowPickerClockControllerView().
                    clockPickerViewModel.setShowKeyguardPreviewRendererSmartspace(false)
                }
            } else {
                null
+8 −16
Original line number Diff line number Diff line
@@ -148,28 +148,20 @@ constructor(

                        launch {
                            combine(
                                    viewModel.clockPickerViewModel.previewingClock,
                                    viewModel.clockPickerViewModel.previewingClockSize,
                                    viewModel.clockPickerViewModel
                                        .showKeyguardPreviewRendererSmartspace,
                                    ::Pair,
                                )
                                .collect { (previewingClock, previewingClockSize) ->
                                    val hideSmartspace =
                                        clockViewFactory
                                            .getController(previewingClock.clockId)
                                            ?.let {
                                                when (previewingClockSize) {
                                                    ClockSize.DYNAMIC ->
                                                        it.largeClock.config
                                                            .hasCustomWeatherDataDisplay
                                                    ClockSize.SMALL ->
                                                        it.smallClock.config
                                                            .hasCustomWeatherDataDisplay
                                                }
                                            } ?: false
                                .collect {
                                    (previewingClockSize, showKeyguardPreviewRendererSmartspace) ->
                                    workspaceCallback.sendMessage(
                                        MESSAGE_ID_HIDE_SMART_SPACE,
                                        Bundle().apply {
                                            putBoolean(KEY_HIDE_SMART_SPACE, hideSmartspace)
                                            putBoolean(
                                                KEY_HIDE_SMART_SPACE,
                                                !showKeyguardPreviewRendererSmartspace,
                                            )
                                        },
                                    )