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

Commit b6a127f9 authored by Fabian Kozynski's avatar Fabian Kozynski
Browse files

Fix TB bugs in QSCustomizer TileAdapter

* When saving the specs on exit, make sure that TileAdapter is left in a
good state. This meanse removing the placeholder if it exists and
setting it to ACTION_NONE
* Update mTileDividerIndex when adding and removing a place holder. It
doesn't need to be updated manually after a completed add, move or
remove operation as we call #updateDividerLocations in #move
* When adding a tile in the position before last, it gets added one
position before that. This happen because of the fix for off by one that
is not needed anymore.

Fixes: 129059015
Fixes: 129001337
Test: manual using TB. Adding, removing and moving tiles, in particular
to positions near the end.
Change-Id: I010d118b15c1cad3c0ab0544b515eb9c5b53b2ce
parent 6f59ef8a
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -113,6 +113,7 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta

    public void saveSpecs(QSTileHost host) {
        List<String> newSpecs = new ArrayList<>();
        clearAccessibilityState();
        for (int i = 1; i < mTiles.size() && mTiles.get(i) != null; i++) {
            newSpecs.add(mTiles.get(i).spec);
        }
@@ -120,6 +121,17 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
        mCurrentSpecs = newSpecs;
    }

    private void clearAccessibilityState() {
        if (mAccessibilityAction == ACTION_ADD) {
            // Remove blank tile from last spot
            mTiles.remove(--mEditIndex);
            // Update the tile divider position
            mTileDividerIndex--;
            notifyDataSetChanged();
        }
        mAccessibilityAction = ACTION_NONE;
    }

    public void resetTileSpecs(QSTileHost host, List<String> specs) {
        // Notify the host so the tiles get removed callbacks.
        host.changeTiles(mCurrentSpecs, specs);
@@ -333,8 +345,6 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
            // Remove the placeholder.
            mTiles.remove(mEditIndex--);
            notifyItemRemoved(mEditIndex);
            // Don't remove items when the last position is selected.
            if (position == mEditIndex - 1) position--;
        }
        mAccessibilityAction = ACTION_NONE;
        move(mAccessibilityFromIndex, position, v);
@@ -372,6 +382,8 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
        mAccessibilityAction = ACTION_ADD;
        // Add placeholder for last slot.
        mTiles.add(mEditIndex++, null);
        // Update the tile divider position
        mTileDividerIndex++;
        mNeedsFocus = true;
        notifyDataSetChanged();
    }