Merge "QS Edit: Try to simplify drag logic" into nyc-dev
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user