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

Commit 94305338 authored by George Lin's avatar George Lin
Browse files

Make preview smartspace corresponds to the selected clock (3/3)

Test: Manually tested
Bug: 376091754
Flag: com.android.systemui.shared.new_customization_picker_ui
Change-Id: I4708415e43ddfe2246e458dd0df068a32a7c1c11
parent c61e6d8b
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -23,12 +23,16 @@ object KeyguardPreviewConstants {
    const val MESSAGE_ID_PREVIEW_QUICK_AFFORDANCE_SELECTED = 1988
    const val MESSAGE_ID_SLOT_SELECTED = 1337
    const val MESSAGE_ID_START_CUSTOMIZING_QUICK_AFFORDANCES = 214
    const val MESSAGE_ID_PREVIEW_CLOCK_SIZE = 1119

    const val KEY_HIDE_SMART_SPACE = "hide_smart_space"
    const val KEY_HIGHLIGHT_QUICK_AFFORDANCES = "highlight_quick_affordances"
    const val KEY_INITIALLY_SELECTED_SLOT_ID = "initially_selected_slot_id"
    const val KEY_QUICK_AFFORDANCE_ID = "quick_affordance_id"
    const val KEY_SLOT_ID = "slot_id"
    const val KEY_CLOCK_SIZE = "clock_size"

    const val KEYGUARD_QUICK_AFFORDANCE_ID_NONE = "none"
    const val CLOCK_SIZE_DYNAMIC = "clock_size_dynamic"
    const val CLOCK_SIZE_SMALL = "clock_size_small"
}
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ object KeyguardPreviewSmartspaceViewBinder {
        smartspace.repeatWhenAttached {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
                launch("$TAG#viewModel.selectedClockSize") {
                    viewModel.selectedClockSize.collect {
                    viewModel.previewingClockSize.collect {
                        val topPadding =
                            when (it) {
                                ClockSizeSetting.DYNAMIC ->
+5 −0
Original line number Diff line number Diff line
@@ -66,6 +66,7 @@ import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.keyguard.KeyguardBottomAreaRefactor
import com.android.systemui.keyguard.MigrateClocksToBlueprint
import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor
import com.android.systemui.keyguard.shared.model.ClockSizeSetting
import com.android.systemui.keyguard.ui.binder.KeyguardPreviewClockViewBinder
import com.android.systemui.keyguard.ui.binder.KeyguardPreviewSmartspaceViewBinder
import com.android.systemui.keyguard.ui.binder.KeyguardQuickAffordanceViewBinder
@@ -312,6 +313,10 @@ constructor(
        )
    }

    fun onClockSizeSelected(clockSize: ClockSizeSetting) {
        smartspaceViewModel.setOverrideClockSize(clockSize)
    }

    fun destroy() {
        isDestroyed = true
        lockscreenSmartspaceController.disconnect()
+20 −12
Original line number Diff line number Diff line
@@ -25,18 +25,24 @@ import android.os.Messenger
import android.util.ArrayMap
import android.util.Log
import androidx.annotation.VisibleForTesting
import com.android.app.tracing.coroutines.launchTraced as launch
import com.android.app.tracing.coroutines.runBlockingTraced as runBlocking
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.keyguard.shared.model.ClockSizeSetting
import com.android.systemui.shared.keyguard.shared.model.KeyguardQuickAffordanceSlots.SLOT_ID_BOTTOM_START
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.CLOCK_SIZE_DYNAMIC
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.CLOCK_SIZE_SMALL
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.KEY_CLOCK_SIZE
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.KEY_HIDE_SMART_SPACE
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.KEY_INITIALLY_SELECTED_SLOT_ID
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.KEY_QUICK_AFFORDANCE_ID
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.KEY_SLOT_ID
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.MESSAGE_ID_DEFAULT_PREVIEW
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.MESSAGE_ID_HIDE_SMART_SPACE
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.MESSAGE_ID_PREVIEW_CLOCK_SIZE
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.MESSAGE_ID_PREVIEW_QUICK_AFFORDANCE_SELECTED
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.MESSAGE_ID_SLOT_SELECTED
import com.android.systemui.shared.quickaffordance.shared.model.KeyguardPreviewConstants.MESSAGE_ID_START_CUSTOMIZING_QUICK_AFFORDANCES
@@ -44,7 +50,6 @@ import com.android.systemui.util.kotlin.logD
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import com.android.app.tracing.coroutines.launchTraced as launch

@SysUISingleton
class KeyguardRemotePreviewManager
@@ -86,17 +91,8 @@ constructor(
            renderer.render()
            renderer.hostToken?.linkToDeath(observer, 0)
            val result = Bundle()
            result.putParcelable(
                KEY_PREVIEW_SURFACE_PACKAGE,
                renderer.surfacePackage,
            )
            val messenger =
                Messenger(
                    Handler(
                        backgroundHandler.looper,
                        observer,
                    )
                )
            result.putParcelable(KEY_PREVIEW_SURFACE_PACKAGE, renderer.surfacePackage)
            val messenger = Messenger(Handler(backgroundHandler.looper, observer))
            // NOTE: The process on the other side can retain messenger indefinitely.
            // (e.g. GC might not trigger and cleanup the reference)
            val msg = Message.obtain()
@@ -191,6 +187,18 @@ class PreviewLifecycleObserver(
            MESSAGE_ID_HIDE_SMART_SPACE -> {
                checkNotNull(renderer).hideSmartspace(message.data.getBoolean(KEY_HIDE_SMART_SPACE))
            }
            MESSAGE_ID_PREVIEW_CLOCK_SIZE -> {
                message.data
                    .getString(KEY_CLOCK_SIZE)
                    ?.let {
                        when (it) {
                            CLOCK_SIZE_DYNAMIC -> ClockSizeSetting.DYNAMIC
                            CLOCK_SIZE_SMALL -> ClockSizeSetting.SMALL
                            else -> null
                        }
                    }
                    ?.let { checkNotNull(renderer).onClockSizeSelected(it) }
            }
            else -> checkNotNull(onDestroy).invoke(this)
        }

+15 −6
Original line number Diff line number Diff line
@@ -25,7 +25,7 @@ import com.android.systemui.plugins.clocks.DefaultClockFaceLayout.Companion.getS
import com.android.systemui.statusbar.ui.SystemBarUtilsProxy
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map

@@ -38,21 +38,30 @@ constructor(
    val clockViewModel: KeyguardClockViewModel,
    private val systemBarUtils: SystemBarUtilsProxy,
) {

    val selectedClockSize: StateFlow<ClockSizeSetting> = interactor.selectedClockSize
    // overrideClockSize will override the clock size that is currently set to the system.
    private val overrideClockSize: MutableStateFlow<ClockSizeSetting?> = MutableStateFlow(null)
    val previewingClockSize =
        combine(overrideClockSize, interactor.selectedClockSize) {
            overrideClockSize,
            selectedClockSize ->
            overrideClockSize ?: selectedClockSize
        }

    val shouldHideSmartspace: Flow<Boolean> =
        combine(interactor.selectedClockSize, interactor.currentClockId, ::Pair).map {
            (size, currentClockId) ->
        combine(previewingClockSize, interactor.currentClockId, ::Pair).map { (size, clockId) ->
            when (size) {
                // TODO (b/284122375) This is temporary. We should use clockController
                //      .largeClock.config.hasCustomWeatherDataDisplay instead, but
                //      ClockRegistry.createCurrentClock is not reliable.
                ClockSizeSetting.DYNAMIC -> currentClockId == "DIGITAL_CLOCK_WEATHER"
                ClockSizeSetting.DYNAMIC -> clockId == "DIGITAL_CLOCK_WEATHER"
                ClockSizeSetting.SMALL -> false
            }
        }

    fun setOverrideClockSize(clockSize: ClockSizeSetting) {
        overrideClockSize.value = clockSize
    }

    fun getSmartspaceStartPadding(context: Context): Int {
        return KeyguardSmartspaceViewModel.getSmartspaceStartMargin(context)
    }