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

Commit 345fc0cf authored by Alejandro Nijamkin's avatar Alejandro Nijamkin Committed by Android (Google) Code Review
Browse files

Merge "Simplifies view-binder." into tm-qpr-dev

parents 1f1e8052 c5b079b7
Loading
Loading
Loading
Loading
+15 −28
Original line number Diff line number Diff line
@@ -95,32 +95,20 @@ object KeyguardBottomAreaViewBinder {
        view.repeatWhenAttached {
            repeatOnLifecycle(Lifecycle.State.STARTED) {
                launch {
                    combine(viewModel.startButton, viewModel.animateButtonReveal) {
                            buttonModel,
                            animateReveal ->
                            Pair(buttonModel, animateReveal)
                        }
                        .collect { (buttonModel, animateReveal) ->
                    viewModel.startButton.collect { buttonModel ->
                        updateButton(
                            view = startButton,
                            viewModel = buttonModel,
                                animateReveal = animateReveal,
                            falsingManager = falsingManager,
                        )
                    }
                }

                launch {
                    combine(viewModel.endButton, viewModel.animateButtonReveal) {
                            buttonModel,
                            animateReveal ->
                            Pair(buttonModel, animateReveal)
                        }
                        .collect { (buttonModel, animateReveal) ->
                    viewModel.endButton.collect { buttonModel ->
                        updateButton(
                            view = endButton,
                            viewModel = buttonModel,
                                animateReveal = animateReveal,
                            falsingManager = falsingManager,
                        )
                    }
@@ -226,7 +214,6 @@ object KeyguardBottomAreaViewBinder {
    private fun updateButton(
        view: ImageView,
        viewModel: KeyguardQuickAffordanceViewModel,
        animateReveal: Boolean,
        falsingManager: FalsingManager,
    ) {
        if (!viewModel.isVisible) {
@@ -236,7 +223,7 @@ object KeyguardBottomAreaViewBinder {

        if (!view.isVisible) {
            view.isVisible = true
            if (animateReveal) {
            if (viewModel.animateReveal) {
                view.alpha = 0f
                view.translationY = view.height / 2f
                view
+11 −11
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ class KeyguardBottomAreaViewModel
constructor(
    private val keyguardInteractor: KeyguardInteractor,
    private val quickAffordanceInteractor: KeyguardQuickAffordanceInteractor,
    bottomAreaInteractor: KeyguardBottomAreaInteractor,
    private val bottomAreaInteractor: KeyguardBottomAreaInteractor,
    private val burnInHelperWrapper: BurnInHelperWrapper,
) {
    /** An observable for the view-model of the "start button" quick affordance. */
@@ -43,12 +43,6 @@ constructor(
    /** An observable for the view-model of the "end button" quick affordance. */
    val endButton: Flow<KeyguardQuickAffordanceViewModel> =
        button(KeyguardQuickAffordancePosition.BOTTOM_END)
    /**
     * An observable for whether the next time a quick action button becomes visible, it should
     * animate.
     */
    val animateButtonReveal: Flow<Boolean> =
        bottomAreaInteractor.animateDozingTransitions.distinctUntilChanged()
    /** An observable for whether the overlay container should be visible. */
    val isOverlayContainerVisible: Flow<Boolean> =
        keyguardInteractor.isDozing.map { !it }.distinctUntilChanged()
@@ -80,18 +74,24 @@ constructor(
    private fun button(
        position: KeyguardQuickAffordancePosition
    ): Flow<KeyguardQuickAffordanceViewModel> {
        return quickAffordanceInteractor
            .quickAffordance(position)
            .map { model -> model.toViewModel() }
        return combine(
                quickAffordanceInteractor.quickAffordance(position),
                bottomAreaInteractor.animateDozingTransitions.distinctUntilChanged(),
            ) { model, animateReveal ->
                model.toViewModel(animateReveal)
            }
            .distinctUntilChanged()
    }

    private fun KeyguardQuickAffordanceModel.toViewModel(): KeyguardQuickAffordanceViewModel {
    private fun KeyguardQuickAffordanceModel.toViewModel(
        animateReveal: Boolean,
    ): KeyguardQuickAffordanceViewModel {
        return when (this) {
            is KeyguardQuickAffordanceModel.Visible ->
                KeyguardQuickAffordanceViewModel(
                    configKey = configKey,
                    isVisible = true,
                    animateReveal = animateReveal,
                    icon = icon,
                    contentDescriptionResourceId = contentDescriptionResourceId,
                    onClicked = { parameters ->
+2 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ import kotlin.reflect.KClass
data class KeyguardQuickAffordanceViewModel(
    val configKey: KClass<out KeyguardQuickAffordanceConfig>? = null,
    val isVisible: Boolean = false,
    /** Whether to animate the transition of the quick affordance from invisible to visible. */
    val animateReveal: Boolean = false,
    val icon: ContainedDrawable = ContainedDrawable.WithResource(0),
    @StringRes val contentDescriptionResourceId: Int = 0,
    val onClicked: (OnClickedParameters) -> Unit = {},
+18 −1
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import kotlin.reflect.KClass
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.test.runBlockingTest
import kotlinx.coroutines.yield
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
@@ -196,11 +197,27 @@ class KeyguardBottomAreaViewModelTest : SysuiTestCase() {

    @Test
    fun animateButtonReveal() = runBlockingTest {
        repository.setKeyguardShowing(true)
        val testConfig =
            TestConfig(
                isVisible = true,
                icon = mock(),
                canShowWhileLocked = false,
                intent = Intent("action"),
            )

        setUpQuickAffordanceModel(
            position = KeyguardQuickAffordancePosition.BOTTOM_START,
            testConfig = testConfig,
        )

        val values = mutableListOf<Boolean>()
        val job = underTest.animateButtonReveal.onEach(values::add).launchIn(this)
        val job = underTest.startButton.onEach { values.add(it.animateReveal) }.launchIn(this)

        repository.setAnimateDozingTransitions(true)
        yield()
        repository.setAnimateDozingTransitions(false)
        yield()

        assertThat(values).isEqualTo(listOf(false, true, false))
        job.cancel()