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

Commit c32d5e85 authored by Fabián Kozynski's avatar Fabián Kozynski
Browse files

Reset to page 0 if we stop listening

We will stop listening if always composed and not in the expanded QS, or
if we are in edit mode.

If we are not always composed, we will create a new PagerState the next
time we compose.

Test: manual, close shade in second page and reopen
Test: manual, go to second page, open edit mode and close
Test: atest QSFragmentComposeViewModelTest
Fixes: 401028991
Flag: com.android.systemui.qs_ui_refactor_compose_fragment
Flag: com.android.systemui.always_compose_qs_ui_fragment

Change-Id: I507ab4346b88ec921d94a436f0200724e9bf77c2
parent ae8da20d
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -46,12 +46,14 @@ import com.android.systemui.statusbar.disableflags.shared.model.DisableFlagsMode
import com.android.systemui.statusbar.sysuiStatusBarStateController
import com.android.systemui.util.animation.DisappearParameters
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.TestScope
import kotlinx.coroutines.test.runCurrent
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.whenever

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@RunWith(AndroidJUnit4::class)
@RunWithLooper
@@ -457,6 +459,20 @@ class QSFragmentComposeViewModelTest : AbstractQSFragmentComposeViewModelTest()
            }
        }

    @Test
    fun isEditing() =
        with(kosmos) {
            testScope.testWithinLifecycle {
                underTest.containerViewModel.editModeViewModel.startEditing()
                runCurrent()
                assertThat(underTest.isEditing).isTrue()

                underTest.containerViewModel.editModeViewModel.stopEditing()
                runCurrent()
                assertThat(underTest.isEditing).isFalse()
            }
        }

    private fun TestScope.setMediaState(state: MediaState) {
        with(kosmos) {
            val activeMedia = state == ACTIVE_MEDIA
+5 −3
Original line number Diff line number Diff line
@@ -421,7 +421,7 @@ constructor(
    }

    override fun isCustomizing(): Boolean {
        return viewModel.containerViewModel.editModeViewModel.isEditing.value
        return viewModel.isEditing
    }

    override fun closeCustomizer() {
@@ -657,7 +657,8 @@ constructor(
                                 */
                                !alwaysCompose ||
                                    (viewModel.isQsVisibleAndAnyShadeExpanded &&
                                        viewModel.expansionState.progress < 1f)
                                        viewModel.expansionState.progress < 1f &&
                                        !viewModel.isEditing)
                            },
                        )
                    }
@@ -784,7 +785,8 @@ constructor(
                                             */
                                            !alwaysCompose ||
                                                (viewModel.isQsVisibleAndAnyShadeExpanded &&
                                                    viewModel.expansionState.progress > 0f)
                                                    viewModel.expansionState.progress > 0f &&
                                                    !viewModel.isEditing)
                                        },
                                    )
                                }
+6 −1
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ import com.android.systemui.animation.ShadeInterpolation
import com.android.systemui.classifier.Classifier
import com.android.systemui.classifier.domain.interactor.FalsingInteractor
import com.android.systemui.common.ui.domain.interactor.ConfigurationInteractor
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.deviceentry.domain.interactor.DeviceEntryInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor
import com.android.systemui.keyguard.shared.model.Edge
@@ -307,6 +306,12 @@ constructor(
    val animateTilesExpansion: Boolean
        get() = inFirstPage && !mediaSuddenlyAppearingInLandscape

    val isEditing by
        hydrator.hydratedStateOf(
            traceName = "isEditing",
            source = containerViewModel.editModeViewModel.isEditing,
        )

    private val inFirstPage: Boolean
        get() = inFirstPageViewModel.inFirstPage

+9 −0
Original line number Diff line number Diff line
@@ -85,6 +85,15 @@ constructor(

        val pagerState = rememberPagerState(0) { pages.size }

        LaunchedEffect(listening, pagerState) {
            snapshotFlow { listening() }
                .collect {
                    if (!listening()) {
                        pagerState.scrollToPage(0)
                    }
                }
        }

        // Used to track if this is currently in the first page or not, for animations
        LaunchedEffect(key1 = pagerState) {
            snapshotFlow { pagerState.currentPage == 0 }.collect { viewModel.inFirstPage = it }