Show and hide smartspace (1/3)
Instead of setting from WPPG, we organically listen to the onCurrentClockChanged() to update the smartspace visibility. Test: tested that the smartspace shows correctly Bug: 274927017 Change-Id: I115e89f7ace1c5a08e5d3c57e47857f7f4369066
This commit is contained in:
@@ -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 (
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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 } }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user