Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2815)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/widget/selection/SelectionDelegate.java

Issue 2789363003: Implement single-selection mode for SelectionDelegate. (Closed)
Patch Set: Address feedback from Theresa Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/android/java_sources.gni » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/java/src/org/chromium/chrome/browser/widget/selection/SelectionDelegate.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/widget/selection/SelectionDelegate.java b/chrome/android/java/src/org/chromium/chrome/browser/widget/selection/SelectionDelegate.java
index d718fc7c2822c9714275a5fb6025701ed60e5838..03f0b031f5be7f12da1a7da1bd469ebb72abe8d4 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/widget/selection/SelectionDelegate.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/widget/selection/SelectionDelegate.java
@@ -16,6 +16,8 @@ import java.util.Set;
* @param <E> The type of the selectable items this delegate interacts with.
*/
public class SelectionDelegate<E> {
+ // True if the SelectionDelegate should only support a single item being selected at a time.
+ private boolean mIsSingleSelection;
/**
* Observer interface to be notified of selection changes.
@@ -26,20 +28,31 @@ public class SelectionDelegate<E> {
* @param selectedItems The list of currently selected items. An empty list indicates there
* is no selection.
*/
- public void onSelectionStateChange(List<E> selectedItems);
+ void onSelectionStateChange(List<E> selectedItems);
}
private Set<E> mSelectedItems = new HashSet<>();
private ObserverList<SelectionObserver<E>> mObservers = new ObserverList<>();
/**
+ * Sets the mode of this SelectionDelegate to single-selection.
+ */
+ public void setSingleSelectionMode() {
+ mIsSingleSelection = true;
+ }
+
+ /**
* Toggles the selected state for the given item.
* @param item The item to toggle.
* @return Whether the item is selected.
*/
public boolean toggleSelectionForItem(E item) {
- if (mSelectedItems.contains(item)) mSelectedItems.remove(item);
- else mSelectedItems.add(item);
+ if (mSelectedItems.contains(item)) {
+ mSelectedItems.remove(item);
+ } else {
+ if (mIsSingleSelection) mSelectedItems.clear();
+ mSelectedItems.add(item);
+ }
notifyObservers();
@@ -99,5 +112,4 @@ public class SelectionDelegate<E> {
observer.onSelectionStateChange(selectedItems);
}
}
-
}
« no previous file with comments | « no previous file | chrome/android/java_sources.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698