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

Commit 0975cc13 authored by Darrell Shi's avatar Darrell Shi Committed by Android (Google) Code Review
Browse files

Merge "Do not show tutorial indicator in wallpaper preview" into main

parents 3e82d6eb a576a4c8
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -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
+3 −20
Original line number Diff line number Diff line
@@ -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
        }
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -120,6 +120,7 @@ constructor(
                ConstraintSet.PARENT_ID,
                ConstraintSet.BOTTOM
            )
            setVisibility(tutorialIndicatorId, View.GONE)
        }
    }

+16 −3
Original line number Diff line number Diff line
@@ -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()
+17 −0
Original line number Diff line number Diff line
@@ -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) {