diff --git a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/SelectableAdapter.java b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/SelectableAdapter.java index bd92ab93..ff674bef 100644 --- a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/SelectableAdapter.java +++ b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/SelectableAdapter.java @@ -144,6 +144,8 @@ public void onDetachedFromRecyclerView(RecyclerView recyclerView) { * @param mode one of {@link #MODE_IDLE}, {@link #MODE_SINGLE}, {@link #MODE_MULTI} */ public void setMode(@Mode int mode) { + if (mMode == MODE_SINGLE && mode == MODE_IDLE) + clearSelection(); this.mMode = mode; mLastItemInActionMode = (mode == MODE_IDLE); } @@ -336,6 +338,7 @@ public void onSaveInstanceState(Bundle outState) { */ public void onRestoreInstanceState(Bundle savedInstanceState) { mSelectedPositions = savedInstanceState.getIntegerArrayList(TAG); + Log.d(TAG, "restore selection " + mSelectedPositions); } /*---------------*/ diff --git a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/ActionModeHelper.java b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/ActionModeHelper.java index 225c3734..28c9a212 100644 --- a/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/ActionModeHelper.java +++ b/flexible-adapter/src/main/java/eu/davidea/flexibleadapter/helpers/ActionModeHelper.java @@ -88,7 +88,7 @@ public ActionMode getActionMode() { * and continue */ public boolean onClick(int position) { - if (mActionMode != null && position != RecyclerView.NO_POSITION) { + if (position != RecyclerView.NO_POSITION) { toggleSelection(position); return true; } @@ -121,9 +121,11 @@ public ActionMode onLongClick(AppCompatActivity activity, int position) { * @param position position of the item to toggle the selection state */ public void toggleSelection(int position) { - if (position >= 0) + if (position >= 0 && (mAdapter.getMode() == SelectableAdapter.MODE_SINGLE || + mAdapter.getMode() == SelectableAdapter.MODE_MULTI)) { mAdapter.toggleSelection(position); - + } + //If MODE_SINGLE is active then ActionMode can be null if (mActionMode == null) return; int count = mAdapter.getSelectedItemCount(); @@ -156,7 +158,8 @@ public void updateContextTitle(int count) { * @param activity the current Activity */ public void restoreSelection(AppCompatActivity activity) { - if (mAdapter.getSelectedItemCount() > 0) { + if ((defaultMode == SelectableAdapter.MODE_IDLE && mAdapter.getSelectedItemCount() > 0) || + (defaultMode == SelectableAdapter.MODE_SINGLE && mAdapter.getSelectedItemCount() > 1)) { onLongClick(activity, -1); } }