Refreshing visibility of QS elements whenever configuration changes

Previously visibility was refreshed only when rotation happened but we want to handle other cases as well, e.g. switching screens.
Also unifying refreshVisibility methods for both footer and brightness slider.

Fixes: 195922194
Test: manual
Change-Id: I05a8ac29df117a0d7b2e6df22ccd62cea80bb12b
This commit is contained in:
Michal Brzezinski
2021-08-25 12:43:22 +01:00
parent 0a49cc54ba
commit 53ab72bbab
4 changed files with 31 additions and 16 deletions

View File

@@ -213,5 +213,13 @@ class FooterActionsController @Inject constructor(
mView.setKeyguardShowing()
}
fun refreshVisibility(shouldBeVisible: Boolean) {
if (shouldBeVisible) {
showFooter()
} else {
hideFooter()
}
}
private fun isTunerEnabled() = tunerService.isTunerEnabled
}

View File

@@ -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) {

View File

@@ -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

View File

@@ -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())
}
}