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

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

Restrict accessible move when tiles cannot be removed

When there were the minimum number of tiles in QSCustomize clicking on a
current tile while on TB would enter ADD MODE, that allowed to move the
tile out.

This CL makes sure that in that case we enter MOVE MODE so the tile
cannot be removed.

Also, makes sure that the tile is focused when entering move mode

Fixes: 140363294
Test: manual with and without TB with 6 and more tiles
Change-Id: I3a27ca1bc54971f6a72b7d69abe6bdb73ca7c56a
parent a620de30
Loading
Loading
Loading
Loading
+24 −14
Original line number Diff line number Diff line
@@ -277,20 +277,7 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
                    selectPosition(holder.getAdapterPosition(), v);
                }
            });
            if (mNeedsFocus) {
                // Wait for this to get laid out then set its focus.
                // Ensure that tile gets laid out so we get the callback.
                holder.mTileView.requestLayout();
                holder.mTileView.addOnLayoutChangeListener(new OnLayoutChangeListener() {
                    @Override
                    public void onLayoutChange(View v, int left, int top, int right, int bottom,
                            int oldLeft, int oldTop, int oldRight, int oldBottom) {
                        holder.mTileView.removeOnLayoutChangeListener(this);
                        holder.mTileView.requestFocus();
                    }
                });
                mNeedsFocus = false;
            }
            focusOnHolder(holder);
            return;
        }

@@ -330,16 +317,38 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
                        } else {
                            if (position < mEditIndex && canRemoveTiles()) {
                                showAccessibilityDialog(position, v);
                            } else if (position < mEditIndex && !canRemoveTiles()) {
                                startAccessibleMove(position);
                            } else {
                                startAccessibleAdd(position);
                            }
                        }
                    }
                });
                if (position == mAccessibilityFromIndex) {
                    focusOnHolder(holder);
                }
            }
        }
    }

    private void focusOnHolder(Holder holder) {
        if (mNeedsFocus) {
            // Wait for this to get laid out then set its focus.
            // Ensure that tile gets laid out so we get the callback.
            holder.mTileView.requestLayout();
            holder.mTileView.addOnLayoutChangeListener(new OnLayoutChangeListener() {
                @Override
                public void onLayoutChange(View v, int left, int top, int right, int bottom,
                        int oldLeft, int oldTop, int oldRight, int oldBottom) {
                    holder.mTileView.removeOnLayoutChangeListener(this);
                    holder.mTileView.requestFocus();
                }
            });
            mNeedsFocus = false;
        }
    }

    private boolean canRemoveTiles() {
        return mCurrentSpecs.size() > mMinNumTiles;
    }
@@ -396,6 +405,7 @@ public class TileAdapter extends RecyclerView.Adapter<Holder> implements TileSta
        mAccessibilityFromIndex = position;
        mAccessibilityFromLabel = mTiles.get(position).state.label;
        mAccessibilityAction = ACTION_MOVE;
        mNeedsFocus = true;
        notifyDataSetChanged();
    }