diff options
5 files changed, 46 insertions, 25 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractor.kt b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractor.kt index 4e5be9b8aa5e..309c84e4e955 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalTutorialInteractor.kt @@ -27,12 +27,15 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.Job import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.filterNotNull import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch /** Encapsulates business-logic related to communal tutorial state. */ @@ -48,7 +51,7 @@ constructor( communalInteractor: CommunalInteractor, ) { /** An observable for whether the tutorial is available. */ - val isTutorialAvailable: Flow<Boolean> = + val isTutorialAvailable: StateFlow<Boolean> = combine( communalInteractor.isCommunalAvailable, keyguardInteractor.isKeyguardVisible, @@ -58,7 +61,11 @@ constructor( isKeyguardVisible && tutorialSettingState != Settings.Secure.HUB_MODE_TUTORIAL_COMPLETED } - .distinctUntilChanged() + .stateIn( + scope = scope, + started = SharingStarted.WhileSubscribed(), + initialValue = false, + ) /** * A flow of the new tutorial state after transitioning. The new state will be calculated based diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/binder/CommunalTutorialIndicatorViewBinder.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/binder/CommunalTutorialIndicatorViewBinder.kt index 4dfc371aaeef..0120b5c87f0a 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/ui/binder/CommunalTutorialIndicatorViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/ui/binder/CommunalTutorialIndicatorViewBinder.kt @@ -18,7 +18,6 @@ package com.android.systemui.communal.ui.binder import android.widget.TextView -import androidx.core.view.isGone import androidx.core.view.isVisible import androidx.lifecycle.Lifecycle import androidx.lifecycle.repeatOnLifecycle @@ -32,16 +31,14 @@ object CommunalTutorialIndicatorViewBinder { fun bind( view: TextView, viewModel: CommunalTutorialIndicatorViewModel, + isPreviewMode: Boolean = false, ): DisposableHandle { val disposableHandle = view.repeatWhenAttached { repeatOnLifecycle(Lifecycle.State.STARTED) { launch { - viewModel.showIndicator.collect { isVisible -> - updateView( - view = view, - isIndicatorVisible = isVisible, - ) + viewModel.showIndicator(isPreviewMode).collect { showIndicator -> + view.isVisible = showIndicator } } @@ -51,18 +48,4 @@ object CommunalTutorialIndicatorViewBinder { return disposableHandle } - - private fun updateView( - isIndicatorVisible: Boolean, - view: TextView, - ) { - if (!isIndicatorVisible) { - view.isGone = true - return - } - - if (!view.isVisible) { - view.isVisible = true - } - } } diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/view/layout/sections/CommunalTutorialIndicatorSection.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/view/layout/sections/CommunalTutorialIndicatorSection.kt index 027cc96350f5..2d9dd50b6d11 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/ui/view/layout/sections/CommunalTutorialIndicatorSection.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/ui/view/layout/sections/CommunalTutorialIndicatorSection.kt @@ -120,6 +120,7 @@ constructor( ConstraintSet.PARENT_ID, ConstraintSet.BOTTOM ) + setVisibility(tutorialIndicatorId, View.GONE) } } diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalTutorialIndicatorViewModel.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalTutorialIndicatorViewModel.kt index 274e61a7499f..63a497213255 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalTutorialIndicatorViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalTutorialIndicatorViewModel.kt @@ -20,17 +20,30 @@ import com.android.systemui.communal.domain.interactor.CommunalTutorialInteracto import com.android.systemui.keyguard.domain.interactor.KeyguardBottomAreaInteractor import javax.inject.Inject import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.distinctUntilChanged /** View model for communal tutorial indicator on keyguard */ class CommunalTutorialIndicatorViewModel @Inject constructor( - communalTutorialInteractor: CommunalTutorialInteractor, + private val communalTutorialInteractor: CommunalTutorialInteractor, bottomAreaInteractor: KeyguardBottomAreaInteractor, ) { - /** An observable for whether the tutorial indicator view should be visible. */ - val showIndicator: Flow<Boolean> = communalTutorialInteractor.isTutorialAvailable + /** + * An observable for whether the tutorial indicator view should be visible. + * + * @param isPreviewMode Whether for preview keyguard mode in wallpaper settings. + */ + fun showIndicator(isPreviewMode: Boolean): StateFlow<Boolean> { + return if (isPreviewMode) { + MutableStateFlow(false).asStateFlow() + } else { + communalTutorialInteractor.isTutorialAvailable + } + } /** An observable for the alpha level for the tutorial indicator. */ val alpha: Flow<Float> = bottomAreaInteractor.alpha.distinctUntilChanged() diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt index eb3afb7c9eec..841bad4c15cc 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/preview/KeyguardPreviewRenderer.kt @@ -39,6 +39,7 @@ import android.view.View import android.view.ViewGroup import android.view.WindowManager import android.widget.FrameLayout +import android.widget.TextView import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.view.isInvisible import com.android.keyguard.ClockEventController @@ -48,6 +49,8 @@ import com.android.systemui.animation.view.LaunchableImageView import com.android.systemui.biometrics.domain.interactor.UdfpsOverlayInteractor import com.android.systemui.broadcast.BroadcastDispatcher import com.android.systemui.common.ui.ConfigurationState +import com.android.systemui.communal.ui.binder.CommunalTutorialIndicatorViewBinder +import com.android.systemui.communal.ui.viewmodel.CommunalTutorialIndicatorViewModel import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.dagger.qualifiers.Background import com.android.systemui.dagger.qualifiers.Main @@ -133,6 +136,7 @@ constructor( private val screenOffAnimationController: ScreenOffAnimationController, private val shadeInteractor: ShadeInteractor, private val secureSettings: SecureSettings, + private val communalTutorialViewModel: CommunalTutorialIndicatorViewModel, ) { val hostToken: IBinder? = bundle.getBinder(KEY_HOST_TOKEN) private val width: Int = bundle.getInt(KEY_VIEW_WIDTH) @@ -408,6 +412,8 @@ constructor( smartSpaceView?.let { KeyguardPreviewSmartspaceViewBinder.bind(it, smartspaceViewModel) } + + setupCommunalTutorialIndicator(keyguardRootView) } ) } @@ -601,6 +607,17 @@ constructor( } } + private fun setupCommunalTutorialIndicator(keyguardRootView: ConstraintLayout) { + keyguardRootView.findViewById<TextView>(R.id.communal_tutorial_indicator)?.let { + indicatorView -> + CommunalTutorialIndicatorViewBinder.bind( + indicatorView, + communalTutorialViewModel, + isPreviewMode = true, + ) + } + } + private suspend fun fetchThemeStyleFromSetting(): Style { val overlayPackageJson = withContext(backgroundDispatcher) { |