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

Commit 2243ac74 authored by Jason Monk's avatar Jason Monk Committed by The Android Automerger
Browse files

QS Edit: Try to simplify drag logic

 - Don't forcibly move around items during dragging, instead let the
ItemTouchHelper handle where things can and cannot be dragged.
 - Try to trigger notify calls only when needed.
 - Tiles will sit in the first slot after being removed until the
   edit panel is closed.

Change-Id: I4780e64bc39292ed85e961ac089c69834245dfb4
Fixes: 28067638
parent d8602c88
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -233,6 +233,7 @@ public class QSCustomizer extends LinearLayout implements OnMenuItemClickListene
                setVisibility(View.GONE);
                setVisibility(View.GONE);
            }
            }
            mNotifQsContainer.setCustomizerAnimating(false);
            mNotifQsContainer.setCustomizerAnimating(false);
            mRecyclerView.setAdapter(mTileAdapter);
        }
        }


        @Override
        @Override
+25 −37
Original line number Original line Diff line number Diff line
@@ -112,6 +112,9 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
    }
    }


    public void setTileSpecs(List<String> currentSpecs) {
    public void setTileSpecs(List<String> currentSpecs) {
        if (currentSpecs.equals(mCurrentSpecs)) {
            return;
        }
        mCurrentSpecs = currentSpecs;
        mCurrentSpecs = currentSpecs;
        recalcSpecs();
        recalcSpecs();
    }
    }
@@ -257,7 +260,7 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
        }
        }
        holder.mTileView.onStateChanged(info.state);
        holder.mTileView.onStateChanged(info.state);
        holder.mTileView.setAppLabel(info.appLabel);
        holder.mTileView.setAppLabel(info.appLabel);
        holder.mTileView.setShowAppLabel(mTileDividerIndex > -1 && position > mTileDividerIndex);
        holder.mTileView.setShowAppLabel(position > mEditIndex && !info.isSystem);


        if (mAccessibilityManager.isTouchExplorationEnabled()) {
        if (mAccessibilityManager.isTouchExplorationEnabled()) {
            final boolean selectable = !mAccessibilityMoving || position < mEditIndex;
            final boolean selectable = !mAccessibilityMoving || position < mEditIndex;
@@ -292,13 +295,11 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
        mTiles.remove(mEditIndex--);
        mTiles.remove(mEditIndex--);
        notifyItemRemoved(mEditIndex - 1);
        notifyItemRemoved(mEditIndex - 1);
        move(mAccessibilityFromIndex, position, v);
        move(mAccessibilityFromIndex, position, v);
        updateDividerLocations();
        notifyDataSetChanged();
        notifyDataSetChanged();
        saveSpecs(mHost);
    }
    }


    private void showAccessibilityDialog(final int position, final View v) {
    private void showAccessibilityDialog(final int position, final View v) {
        TileInfo info = mTiles.get(position);
        final TileInfo info = mTiles.get(position);
        CharSequence[] options = new CharSequence[] {
        CharSequence[] options = new CharSequence[] {
                mContext.getString(R.string.accessibility_qs_edit_move_tile, info.state.label),
                mContext.getString(R.string.accessibility_qs_edit_move_tile, info.state.label),
                mContext.getString(R.string.accessibility_qs_edit_remove_tile, info.state.label),
                mContext.getString(R.string.accessibility_qs_edit_remove_tile, info.state.label),
@@ -310,7 +311,9 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
                        if (which == 0) {
                        if (which == 0) {
                            startAccessibleDrag(position);
                            startAccessibleDrag(position);
                        } else {
                        } else {
                            move(position, mEditIndex, v);
                            move(position, info.isSystem ? mEditIndex : mTileDividerIndex, v);
                            notifyItemChanged(mTileDividerIndex);
                            notifyDataSetChanged();
                        }
                        }
                    }
                    }
                }).setNegativeButton(android.R.string.cancel, null)
                }).setNegativeButton(android.R.string.cancel, null)
@@ -334,40 +337,12 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
    }
    }


    private boolean move(int from, int to, View v) {
    private boolean move(int from, int to, View v) {
        if (to >= mEditIndex) {
        if (to == from) {
            if (from < mEditIndex) {
            return true;
                // Removing a tile.
                // Sort tiles into system/non-system groups.
                TileInfo tile = mTiles.get(from);
                if (tile.isSystem) {
                    if (to > mTileDividerIndex) {
                        to = mTileDividerIndex;
                    }
                } else {
                    if (mTileDividerIndex == mTiles.size() - 1) {
                        notifyItemChanged(mTileDividerIndex);
                    }
                    if (to <= mTileDividerIndex) {
                        to = mTileDividerIndex;
                    }
                }
            } else {
                if (to > mEditIndex) {
                    // Don't allow tiles to be dragged around when they aren't added.
                    to = from;
                }
                // Allow the case where to == mEditIndex to fall through and swap which
                // side the tile is currently on.
                // This lets the the cases where all tiles are on one side of the line
                // work.
            }
        }
        }
        CharSequence fromLabel = mTiles.get(from).state.label;
        CharSequence fromLabel = mTiles.get(from).state.label;
        move(from, to, mTiles);
        move(from, to, mTiles);
        updateDividerLocations();
        updateDividerLocations();
        if (to == from) {
            return true;
        }
        CharSequence announcement;
        CharSequence announcement;
        if (to >= mEditIndex) {
        if (to >= mEditIndex) {
            MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_QS_EDIT_REMOVE_SPEC,
            MetricsLogger.action(mContext, MetricsProto.MetricsEvent.ACTION_QS_EDIT_REMOVE_SPEC,
@@ -427,7 +402,6 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
    private <T> void move(int from, int to, List<T> list) {
    private <T> void move(int from, int to, List<T> list) {
        list.add(to, list.remove(from));
        list.add(to, list.remove(from));
        notifyItemMoved(from, to);
        notifyItemMoved(from, to);
        notifyItemChanged(to);
    }
    }


    public class Holder extends ViewHolder {
    public class Holder extends ViewHolder {
@@ -499,7 +473,7 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
            for (int i = 0; i < childCount; i++) {
            for (int i = 0; i < childCount; i++) {
                final View child = parent.getChildAt(i);
                final View child = parent.getChildAt(i);
                final ViewHolder holder = parent.getChildViewHolder(child);
                final ViewHolder holder = parent.getChildViewHolder(child);
                if (holder.getAdapterPosition() < mEditIndex) {
                if (holder.getAdapterPosition() < mEditIndex && !(child instanceof TextView)) {
                    continue;
                    continue;
                }
                }


@@ -530,7 +504,15 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
        @Override
        @Override
        public void onSelectedChanged(ViewHolder viewHolder, int actionState) {
        public void onSelectedChanged(ViewHolder viewHolder, int actionState) {
            super.onSelectedChanged(viewHolder, actionState);
            super.onSelectedChanged(viewHolder, actionState);
            if (actionState != ItemTouchHelper.ACTION_STATE_DRAG) {
                viewHolder = null;
            }
            if (viewHolder == mCurrentDrag) return;
            if (mCurrentDrag != null) {
            if (mCurrentDrag != null) {
                int position = mCurrentDrag.getAdapterPosition();
                TileInfo info = mTiles.get(position);
                mCurrentDrag.mTileView.setShowAppLabel(
                        position > mEditIndex && !info.isSystem);
                mCurrentDrag.stopDrag();
                mCurrentDrag.stopDrag();
                mCurrentDrag = null;
                mCurrentDrag = null;
            }
            }
@@ -546,6 +528,12 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
            });
            });
        }
        }


        @Override
        public boolean canDropOver(RecyclerView recyclerView, ViewHolder current,
                ViewHolder target) {
            return target.getAdapterPosition() <= mEditIndex + 1;
        }

        @Override
        @Override
        public int getMovementFlags(RecyclerView recyclerView, ViewHolder viewHolder) {
        public int getMovementFlags(RecyclerView recyclerView, ViewHolder viewHolder) {
            if (viewHolder.getItemViewType() == TYPE_EDIT) {
            if (viewHolder.getItemViewType() == TYPE_EDIT) {