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

Commit 29fdcd56 authored by Evan Laird's avatar Evan Laird Committed by android-build-merger
Browse files

Merge "Use view order when iterating icons in a slot" into pi-dev am: 29d9832d

am: 90a41bde

Change-Id: I691a48ae2b17a8a992fd38b51f76fcaf46fc8ddf
parents 2411ef8e 90a41bde
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -88,7 +88,7 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
        List<Slot> allSlots = getSlots();
        for (int i = 0; i < allSlots.size(); i++) {
            Slot slot = allSlots.get(i);
            List<StatusBarIconHolder> holders = slot.getHolderList();
            List<StatusBarIconHolder> holders = slot.getHolderListInViewOrder();
            boolean blocked = mIconBlacklist.contains(slot.getName());

            for (StatusBarIconHolder holder : holders) {
@@ -121,7 +121,7 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
        // Remove all the icons.
        for (int i = currentSlots.size() - 1; i >= 0; i--) {
            Slot s = currentSlots.get(i);
            slotsToReAdd.put(s, s.getHolderList());
            slotsToReAdd.put(s, s.getHolderListInViewOrder());
            removeAllIconsForSlot(s.getName());
        }

@@ -281,7 +281,7 @@ public class StatusBarIconControllerImpl extends StatusBarIconList implements Tu
        mIconLogger.onIconHidden(slotName);

        int slotIndex = getSlotIndex(slotName);
        List<StatusBarIconHolder> iconsToRemove = slot.getHolderList();
        List<StatusBarIconHolder> iconsToRemove = slot.getHolderListInViewOrder();
        for (StatusBarIconHolder holder : iconsToRemove) {
            int viewIndex = getViewIndex(slotIndex, holder.getTag());
            slot.removeForTag(holder.getTag());
+14 −6
Original line number Diff line number Diff line
@@ -211,7 +211,7 @@ public class StatusBarIconList {
        }

        /**
         * View index is backwards from regular index
         * View index is inverted from regular index, because they are laid out back-to-front
         * @param tag the tag of the holder being viewed
         * @return (1 + mSubSlots.size() - indexOfTag)
         */
@@ -228,14 +228,22 @@ public class StatusBarIconList {
            return subSlots - getIndexForTag(tag) - 1;
        }

        public List<StatusBarIconHolder> getHolderList() {
        /**
         * Build a list of the {@link StatusBarIconHolder}s in the same order they appear in their
         * view group. This provides a safe list that can be iterated and inserted into its group.
         *
         * @return all holders contained here, in view order
         */
        public List<StatusBarIconHolder> getHolderListInViewOrder() {
            ArrayList<StatusBarIconHolder> holders = new ArrayList<>();
            if (mHolder != null) {
                holders.add(mHolder);
            if (mSubSlots != null) {
                for (int i = mSubSlots.size() - 1; i >= 0; i--) {
                    holders.add(mSubSlots.get(i));
                }
            }

            if (mSubSlots != null) {
                holders.addAll(mSubSlots);
            if (mHolder != null) {
                holders.add(mHolder);
            }

            return holders;
+10 −9
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ public class StatusBarIconListTest extends SysuiTestCase {
     */

    @Test
    public void testSlot_OrderIsPreserved() {
    public void testSlot_ViewOrder() {
        Slot testSlot = new Slot("test_name", null);

        // no tag bc it defaults to 0
@@ -144,17 +144,18 @@ public class StatusBarIconListTest extends SysuiTestCase {
        int sb3Tag = 2;
        when(sbHolder3.getTag()).thenReturn(sb3Tag);

        // Add 3 icons in the same slot, and verify that the list we get is equal to what we gave
        testSlot.addHolder(sbHolder1);
        testSlot.addHolder(sbHolder2);
        testSlot.addHolder(sbHolder3);

        // View order is reverse of the order added
        ArrayList<StatusBarIconHolder> expected = new ArrayList<>();
        expected.add(sbHolder1);
        expected.add(sbHolder2);
        expected.add(sbHolder3);
        expected.add(sbHolder2);
        expected.add(sbHolder1);


        // Add 3 icons in the same slot, and verify that the list we get is equal to what we gave
        for (StatusBarIconHolder holder : expected) {
            testSlot.addHolder(holder);
        }
        assertTrue(listsEqual(expected, testSlot.getHolderList()));
        assertTrue(listsEqual(expected, testSlot.getHolderListInViewOrder()));
    }

    private boolean listsEqual(List<StatusBarIconHolder> list1, List<StatusBarIconHolder> list2) {