Skip to content

Commit

Permalink
Finalized ActionModeHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
davideas committed May 1, 2016
1 parent 09b3ceb commit b1d29dd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -336,6 +338,7 @@ public void onSaveInstanceState(Bundle outState) {
*/
public void onRestoreInstanceState(Bundle savedInstanceState) {
mSelectedPositions = savedInstanceState.getIntegerArrayList(TAG);
Log.d(TAG, "restore selection " + mSelectedPositions);
}

/*---------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
}
Expand Down

0 comments on commit b1d29dd

Please sign in to comment.