Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be6a8cb
commit 2f0533f
Showing
7 changed files
with
216 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
app/src/main/java/com/nononsenseapps/notepad/ui/list/SelectedItemHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,58 @@ | ||
package com.nononsenseapps.notepad.ui.list; | ||
|
||
import android.support.v7.app.AppCompatActivity; | ||
import android.support.v7.view.ActionMode; | ||
|
||
import java.util.Set; | ||
import java.util.TreeSet; | ||
|
||
public class SelectedItemHandler { | ||
private final TreeSet<Long> selected = new TreeSet<>(); | ||
private final AppCompatActivity activity; | ||
private final ActionMode.Callback actionModeCallback; | ||
private ActionMode actionMode = null; | ||
|
||
public SelectedItemHandler(AppCompatActivity activity, ActionMode.Callback actionModeCallback) { | ||
this.activity = activity; | ||
this.actionModeCallback = actionModeCallback; | ||
} | ||
|
||
public boolean isItemSelected(long id) { | ||
return selected.contains(id); | ||
} | ||
|
||
public void toggleSelection(long id) { | ||
if (actionMode == null) { | ||
actionMode = activity.startSupportActionMode(actionModeCallback); | ||
} | ||
|
||
if (selected.contains(id)) { | ||
selected.remove(id); | ||
} else { | ||
selected.add(id); | ||
} | ||
|
||
if (selected.isEmpty()) { | ||
actionMode.finish(); | ||
} else { | ||
actionMode.setTitle(String.valueOf(selected.size())); | ||
actionMode.invalidate(); | ||
} | ||
} | ||
|
||
public Set<Long> getSelected() { | ||
return selected; | ||
} | ||
|
||
public void clear() { | ||
selected.clear(); | ||
if (actionMode != null) { | ||
actionMode.finish(); | ||
actionMode = null; | ||
} | ||
} | ||
|
||
public boolean isActiveSelectionMode() { | ||
return actionMode != null; | ||
} | ||
} |
Oops, something went wrong.