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

Commit 1f2a23d5 authored by George Lin's avatar George Lin Committed by Automerger Merge Worker
Browse files

Merge "Show and hide smartspace (1/3)" into udc-dev am: 8278c862

parents 2333a526 8278c862
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -21,12 +21,17 @@ import android.provider.Settings
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.keyguard.shared.model.SettingsClockSize
import com.android.systemui.plugins.ClockId
import com.android.systemui.shared.clocks.ClockRegistry
import com.android.systemui.util.settings.SecureSettings
import com.android.systemui.util.settings.SettingsProxyExt.observerFlow
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.withContext

@@ -35,6 +40,7 @@ class KeyguardClockRepository
@Inject
constructor(
    private val secureSettings: SecureSettings,
    private val clockRegistry: ClockRegistry,
    @Background private val backgroundDispatcher: CoroutineDispatcher,
) {

@@ -47,6 +53,24 @@ constructor(
            .onStart { emit(Unit) } // Forces an initial update.
            .map { getClockSize() }

    val currentClockId: Flow<ClockId> =
        callbackFlow {
                fun send() {
                    trySend(clockRegistry.currentClockId)
                }

                val listener =
                    object : ClockRegistry.ClockChangeListener {
                        override fun onCurrentClockChanged() {
                            send()
                        }
                    }
                clockRegistry.registerClockChangeListener(listener)
                send()
                awaitClose { clockRegistry.unregisterClockChangeListener(listener) }
            }
            .mapNotNull { it }

    private suspend fun getClockSize(): SettingsClockSize {
        return withContext(backgroundDispatcher) {
            if (
+3 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ package com.android.systemui.keyguard.domain.interactor
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.keyguard.data.repository.KeyguardClockRepository
import com.android.systemui.keyguard.shared.model.SettingsClockSize
import com.android.systemui.plugins.ClockId
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow

@@ -31,4 +32,6 @@ constructor(
    repository: KeyguardClockRepository,
) {
    val selectedClockSize: Flow<SettingsClockSize> = repository.selectedClockSize

    val currentClockId: Flow<ClockId> = repository.currentClockId
}
+5 −2
Original line number Diff line number Diff line
@@ -18,10 +18,12 @@
package com.android.systemui.keyguard.ui.binder

import android.view.View
import androidx.core.view.isInvisible
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewSmartspaceViewModel
import com.android.systemui.lifecycle.repeatWhenAttached
import kotlinx.coroutines.launch

/** Binder for the small clock view, large clock view and smartspace. */
object KeyguardPreviewSmartspaceViewBinder {
@@ -31,10 +33,11 @@ object KeyguardPreviewSmartspaceViewBinder {
        smartspace: View,
        viewModel: KeyguardPreviewSmartspaceViewModel,
    ) {

        smartspace.repeatWhenAttached {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
                viewModel.smartSpaceTopPadding.collect { smartspace.setTopPadding(it) }
                launch { viewModel.smartspaceTopPadding.collect { smartspace.setTopPadding(it) } }

                launch { viewModel.shouldHideSmartspace.collect { smartspace.isInvisible = it } }
            }
        }
    }
+1 −4
Original line number Diff line number Diff line
@@ -240,7 +240,7 @@ constructor(
        smartSpaceView?.let {
            it.setPaddingRelative(startPadding, topPadding, endPadding, 0)
            it.isClickable = false

            it.isInvisible = true
            parentView.addView(
                it,
                FrameLayout.LayoutParams(
@@ -399,9 +399,6 @@ constructor(

        updateLargeClock(clock)
        updateSmallClock(clock)

        // Hide smart space if the clock has weather display; otherwise show it
        hideSmartspace(clock.largeClock.config.hasCustomWeatherDataDisplay)
    }

    private fun updateLargeClock(clock: ClockController) {
+18 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor
import com.android.systemui.keyguard.shared.model.SettingsClockSize
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.map

/** View model for the smartspace. */
@@ -34,7 +35,7 @@ constructor(
    interactor: KeyguardClockInteractor,
) {

    val smartSpaceTopPadding: Flow<Int> =
    val smartspaceTopPadding: Flow<Int> =
        interactor.selectedClockSize.map {
            when (it) {
                SettingsClockSize.DYNAMIC -> getLargeClockSmartspaceTopPadding(context.resources)
@@ -42,6 +43,22 @@ constructor(
            }
        }

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

    companion object {
        fun getLargeClockSmartspaceTopPadding(resources: Resources): Int {
            return with(resources) {