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

Commit d14062c3 authored by Michał Brzeziński's avatar Michał Brzeziński Committed by Automerger Merge Worker
Browse files

Merge "Refreshing visibility of QS elements whenever configuration changes"...

Merge "Refreshing visibility of QS elements whenever configuration changes" into sc-v2-dev am: 2907230d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15674796

Change-Id: I5c61e6fa2932e9714dc4460f9530bc4f4551433c
parents 9cfb402b 2907230d
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -213,5 +213,13 @@ class FooterActionsController @Inject constructor(
        mView.setKeyguardShowing()
    }

    fun refreshVisibility(shouldBeVisible: Boolean) {
        if (shouldBeVisible) {
            showFooter()
        } else {
            hideFooter()
        }
    }

    private fun isTunerEnabled() = tunerService.isTunerEnabled
}
 No newline at end of file
+2 −2
Original line number Diff line number Diff line
@@ -84,15 +84,15 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
                public void onConfigurationChange(Configuration newConfig) {
                    mShouldUseSplitNotificationShade =
                            Utils.shouldUseSplitNotificationShade(getResources());
                    onConfigurationChanged();
                    if (newConfig.orientation != mLastOrientation) {
                        mLastOrientation = newConfig.orientation;
                        onScreenRotated();
                        switchTileLayout(false);
                    }
                }
            };

    protected void onScreenRotated() { }
    protected void onConfigurationChanged() { }

    private final Function1<Boolean, Unit> mMediaHostVisibilityListener = (visible) -> {
        if (mMediaVisibilityChangedListener != null) {
+3 −11
Original line number Diff line number Diff line
@@ -81,7 +81,7 @@ public class QuickQSPanelController extends QSPanelControllerBase<QuickQSPanel>
        mMediaHost.init(MediaHierarchyManager.LOCATION_QQS);
        mBrightnessController.init(mShouldUseSplitNotificationShade);
        mFooterActionsController.init();
        refreshFooterVisibility();
        mFooterActionsController.refreshVisibility(mShouldUseSplitNotificationShade);
    }

    @Override
@@ -109,14 +109,6 @@ public class QuickQSPanelController extends QSPanelControllerBase<QuickQSPanel>
        return mView.isListening();
    }

    private void refreshFooterVisibility() {
        if (mShouldUseSplitNotificationShade) {
            mFooterActionsController.showFooter();
        } else {
            mFooterActionsController.hideFooter();
        }
    }

    private void setMaxTiles(int parseNumTiles) {
        mView.setMaxTiles(parseNumTiles);
        setTiles();
@@ -129,9 +121,9 @@ public class QuickQSPanelController extends QSPanelControllerBase<QuickQSPanel>
    }

    @Override
    protected void onScreenRotated() {
    protected void onConfigurationChanged() {
        mBrightnessController.refreshVisibility(mShouldUseSplitNotificationShade);
        refreshFooterVisibility();
        mFooterActionsController.refreshVisibility(mShouldUseSplitNotificationShade);
    }

    @Override
+18 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.qs

import android.content.res.Configuration
import android.test.suitebuilder.annotation.SmallTest
import android.testing.AndroidTestingRunner
import com.android.internal.logging.MetricsLogger
@@ -27,12 +28,13 @@ import com.android.systemui.plugins.qs.QSTile
import com.android.systemui.plugins.qs.QSTileView
import com.android.systemui.qs.customize.QSCustomizerController
import com.android.systemui.qs.logging.QSLogger
import com.android.systemui.flags.FeatureFlags
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentCaptor
import org.mockito.ArgumentMatchers.anyBoolean
import org.mockito.Captor
import org.mockito.Mock
import org.mockito.Mockito.`when`
import org.mockito.Mockito.any
@@ -65,11 +67,11 @@ class QuickQSPanelControllerTest : SysuiTestCase() {
    @Mock
    private lateinit var tileView: QSTileView
    @Mock
    private lateinit var featureFlags: FeatureFlags
    @Mock
    private lateinit var quickQsBrightnessController: QuickQSBrightnessController
    @Mock
    private lateinit var footerActionsController: FooterActionsController
    @Captor
    private lateinit var captor: ArgumentCaptor<QSPanel.OnConfigurationChangedListener>

    private lateinit var controller: QuickQSPanelController

@@ -78,6 +80,7 @@ class QuickQSPanelControllerTest : SysuiTestCase() {
        MockitoAnnotations.initMocks(this)

        `when`(quickQSPanel.tileLayout).thenReturn(tileLayout)
        `when`(quickQSPanel.isAttachedToWindow).thenReturn(true)
        `when`(quickQSPanel.dumpableTag).thenReturn("")
        `when`(quickQSPanel.resources).thenReturn(mContext.resources)
        `when`(qsTileHost.createTileView(any(), any(), anyBoolean())).thenReturn(tileView)
@@ -123,4 +126,16 @@ class QuickQSPanelControllerTest : SysuiTestCase() {

        verify(quickQSPanel, times(limit)).addTile(any())
    }

    @Test
    fun testBrightnessAndFooterVisibilityRefreshedWhenConfigurationChanged() {
        // times(2) because both controller and base controller are registering their listeners
        verify(quickQSPanel, times(2)).addOnConfigurationChangedListener(captor.capture())

        captor.allValues.forEach { it.onConfigurationChange(Configuration.EMPTY) }

        verify(quickQsBrightnessController).refreshVisibility(anyBoolean())
        // times(2) because footer visibility is also refreshed on controller init
        verify(footerActionsController, times(2)).refreshVisibility(anyBoolean())
    }
}