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

Commit 1be98220 authored by Olivier St-Onge's avatar Olivier St-Onge
Browse files

Avoid recreating tiles when reducing the amount of QS tiles visible

When going from unfolded to folded, the tiles are the same but we reduce
the amount shown. We can avoid recreating these tiles by simply cleaning
up the extra ones. This fixes the tiles flashing when folding the
device.

Test: manually with foldable
Fixes: 297360184
Flag: None
Change-Id: Ief41a6f9df3835e21991585d932a1c98ac7a44a8
parent daa367eb
Loading
Loading
Loading
Loading
+15 −4
Original line number Diff line number Diff line
@@ -43,6 +43,9 @@ import com.android.systemui.statusbar.policy.SplitShadeStateController;
import com.android.systemui.util.ViewController;
import com.android.systemui.util.animation.DisappearParameters;

import kotlin.Unit;
import kotlin.jvm.functions.Function1;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
@@ -50,9 +53,6 @@ import java.util.Objects;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import kotlin.Unit;
import kotlin.jvm.functions.Function1;

/**
 * Controller for QSPanel views.
 *
@@ -232,7 +232,7 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
            mQsTileRevealController.updateRevealedTiles(tiles);
        }
        boolean shouldChange = false;
        if (tiles.size() == mRecords.size()) {
        if (tiles.size() <= mRecords.size()) {
            int i = 0;
            for (QSTile tile : tiles) {
                if (tile != mRecords.get(i).tile) {
@@ -241,6 +241,17 @@ public abstract class QSPanelControllerBase<T extends QSPanel> extends ViewContr
                }
                i++;
            }

            // If the first tiles are the same as the new ones, remove any extras.
            if (!shouldChange) {
                while (i < mRecords.size()) {
                    QSPanelControllerBase.TileRecord record = mRecords.get(i);
                    mView.removeTile(record);
                    record.tile.removeCallback(record.callback);
                    i++;
                }
                mCachedSpecs = getTilesSpecs();
            }
        } else {
            shouldChange = true;
        }
+4 −4
Original line number Diff line number Diff line
@@ -391,7 +391,7 @@ public class QSPanelControllerBaseTest extends SysuiTestCase {
    }

    @Test
    public void setTiles_differentTiles_allTilesRemovedAndNewTilesAdded() {
    public void setTiles_differentTiles_extraTileRemoved() {
        when(mQSHost.getTiles()).thenReturn(List.of(mQSTile, mOtherTile));
        mController.setTiles();

@@ -400,8 +400,8 @@ public class QSPanelControllerBaseTest extends SysuiTestCase {
        when(mQSHost.getTiles()).thenReturn(List.of(mQSTile));
        mController.setTiles();

        verify(mQSPanel, times(2)).removeTile(any());
        verify(mQSPanel).addTile(any());
        verify(mQSPanel, times(1)).removeTile(any());
        verify(mQSPanel, never()).addTile(any());
    }

    @Test
@@ -418,7 +418,7 @@ public class QSPanelControllerBaseTest extends SysuiTestCase {
    }

    @Test
    public void setTiles_sameTilesDifferentOrder_removesAndReadds() {
    public void setTiles_sameTilesDifferentOrder_removesAndReads() {
        when(mQSHost.getTiles()).thenReturn(List.of(mQSTile, mOtherTile));
        mController.setTiles();