Merge "Show and hide smartspace (1/3)" into udc-dev am: 8278c862d3
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/23412556 Change-Id: Ie86b9f476c84374ea87d0c31ff06259609d56c06 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -21,12 +21,17 @@ import android.provider.Settings
|
|||||||
import com.android.systemui.dagger.SysUISingleton
|
import com.android.systemui.dagger.SysUISingleton
|
||||||
import com.android.systemui.dagger.qualifiers.Background
|
import com.android.systemui.dagger.qualifiers.Background
|
||||||
import com.android.systemui.keyguard.shared.model.SettingsClockSize
|
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.SecureSettings
|
||||||
import com.android.systemui.util.settings.SettingsProxyExt.observerFlow
|
import com.android.systemui.util.settings.SettingsProxyExt.observerFlow
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.CoroutineDispatcher
|
import kotlinx.coroutines.CoroutineDispatcher
|
||||||
|
import kotlinx.coroutines.channels.awaitClose
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.callbackFlow
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
import kotlinx.coroutines.flow.mapNotNull
|
||||||
import kotlinx.coroutines.flow.onStart
|
import kotlinx.coroutines.flow.onStart
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
@@ -35,6 +40,7 @@ class KeyguardClockRepository
|
|||||||
@Inject
|
@Inject
|
||||||
constructor(
|
constructor(
|
||||||
private val secureSettings: SecureSettings,
|
private val secureSettings: SecureSettings,
|
||||||
|
private val clockRegistry: ClockRegistry,
|
||||||
@Background private val backgroundDispatcher: CoroutineDispatcher,
|
@Background private val backgroundDispatcher: CoroutineDispatcher,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
@@ -47,6 +53,24 @@ constructor(
|
|||||||
.onStart { emit(Unit) } // Forces an initial update.
|
.onStart { emit(Unit) } // Forces an initial update.
|
||||||
.map { getClockSize() }
|
.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 {
|
private suspend fun getClockSize(): SettingsClockSize {
|
||||||
return withContext(backgroundDispatcher) {
|
return withContext(backgroundDispatcher) {
|
||||||
if (
|
if (
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ package com.android.systemui.keyguard.domain.interactor
|
|||||||
import com.android.systemui.dagger.SysUISingleton
|
import com.android.systemui.dagger.SysUISingleton
|
||||||
import com.android.systemui.keyguard.data.repository.KeyguardClockRepository
|
import com.android.systemui.keyguard.data.repository.KeyguardClockRepository
|
||||||
import com.android.systemui.keyguard.shared.model.SettingsClockSize
|
import com.android.systemui.keyguard.shared.model.SettingsClockSize
|
||||||
|
import com.android.systemui.plugins.ClockId
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
|
||||||
@@ -31,4 +32,6 @@ constructor(
|
|||||||
repository: KeyguardClockRepository,
|
repository: KeyguardClockRepository,
|
||||||
) {
|
) {
|
||||||
val selectedClockSize: Flow<SettingsClockSize> = repository.selectedClockSize
|
val selectedClockSize: Flow<SettingsClockSize> = repository.selectedClockSize
|
||||||
|
|
||||||
|
val currentClockId: Flow<ClockId> = repository.currentClockId
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,10 +18,12 @@
|
|||||||
package com.android.systemui.keyguard.ui.binder
|
package com.android.systemui.keyguard.ui.binder
|
||||||
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import androidx.core.view.isInvisible
|
||||||
import androidx.lifecycle.Lifecycle
|
import androidx.lifecycle.Lifecycle
|
||||||
import androidx.lifecycle.repeatOnLifecycle
|
import androidx.lifecycle.repeatOnLifecycle
|
||||||
import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewSmartspaceViewModel
|
import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewSmartspaceViewModel
|
||||||
import com.android.systemui.lifecycle.repeatWhenAttached
|
import com.android.systemui.lifecycle.repeatWhenAttached
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
/** Binder for the small clock view, large clock view and smartspace. */
|
/** Binder for the small clock view, large clock view and smartspace. */
|
||||||
object KeyguardPreviewSmartspaceViewBinder {
|
object KeyguardPreviewSmartspaceViewBinder {
|
||||||
@@ -31,10 +33,11 @@ object KeyguardPreviewSmartspaceViewBinder {
|
|||||||
smartspace: View,
|
smartspace: View,
|
||||||
viewModel: KeyguardPreviewSmartspaceViewModel,
|
viewModel: KeyguardPreviewSmartspaceViewModel,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
smartspace.repeatWhenAttached {
|
smartspace.repeatWhenAttached {
|
||||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
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 {
|
smartSpaceView?.let {
|
||||||
it.setPaddingRelative(startPadding, topPadding, endPadding, 0)
|
it.setPaddingRelative(startPadding, topPadding, endPadding, 0)
|
||||||
it.isClickable = false
|
it.isClickable = false
|
||||||
|
it.isInvisible = true
|
||||||
parentView.addView(
|
parentView.addView(
|
||||||
it,
|
it,
|
||||||
FrameLayout.LayoutParams(
|
FrameLayout.LayoutParams(
|
||||||
@@ -399,9 +399,6 @@ constructor(
|
|||||||
|
|
||||||
updateLargeClock(clock)
|
updateLargeClock(clock)
|
||||||
updateSmallClock(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) {
|
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 com.android.systemui.keyguard.shared.model.SettingsClockSize
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlinx.coroutines.flow.Flow
|
import kotlinx.coroutines.flow.Flow
|
||||||
|
import kotlinx.coroutines.flow.combine
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
|
|
||||||
/** View model for the smartspace. */
|
/** View model for the smartspace. */
|
||||||
@@ -34,7 +35,7 @@ constructor(
|
|||||||
interactor: KeyguardClockInteractor,
|
interactor: KeyguardClockInteractor,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
val smartSpaceTopPadding: Flow<Int> =
|
val smartspaceTopPadding: Flow<Int> =
|
||||||
interactor.selectedClockSize.map {
|
interactor.selectedClockSize.map {
|
||||||
when (it) {
|
when (it) {
|
||||||
SettingsClockSize.DYNAMIC -> getLargeClockSmartspaceTopPadding(context.resources)
|
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 {
|
companion object {
|
||||||
fun getLargeClockSmartspaceTopPadding(resources: Resources): Int {
|
fun getLargeClockSmartspaceTopPadding(resources: Resources): Int {
|
||||||
return with(resources) {
|
return with(resources) {
|
||||||
|
|||||||
Reference in New Issue
Block a user