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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/ItemChooserDialog.java

Issue 2098983002: Distinguish devices with same name in chooser on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 6 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/strings/android_chrome_strings.grd » ('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/ItemChooserDialog.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ItemChooserDialog.java b/chrome/android/java/src/org/chromium/chrome/browser/ItemChooserDialog.java
index 04c717a3dabccea2e552339519830ea81fa48c85..887fc020334118bece7935e91c919796519d2bf0 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ItemChooserDialog.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ItemChooserDialog.java
@@ -33,7 +33,9 @@ import org.chromium.chrome.browser.util.MathUtils;
import org.chromium.ui.base.DeviceFormFactor;
import org.chromium.ui.widget.TextViewWithClickableSpans;
+import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Set;
/**
@@ -119,7 +121,7 @@ public class ItemChooserDialog {
/**
* An adapter for keeping track of which items to show in the dialog.
*/
- private class ItemAdapter extends ArrayAdapter<ItemChooserRow>
+ public class ItemAdapter extends ArrayAdapter<ItemChooserRow>
implements AdapterView.OnItemClickListener {
private final LayoutInflater mInflater;
@@ -136,6 +138,9 @@ public class ItemChooserDialog {
// A set of keys that are marked as disabled in the dialog.
private Set<String> mDisabledEntries = new HashSet<String>();
+ // Item descriptions are counted in a map.
+ private Map<String, Integer> mItemDescriptionMap = new HashMap<>();
+
public ItemAdapter(Context context, int resource) {
super(context, resource);
@@ -148,6 +153,29 @@ public class ItemChooserDialog {
}
@Override
+ public void add(ItemChooserRow item) {
+ String description = item.mDescription;
+ int count = mItemDescriptionMap.containsKey(description)
+ ? mItemDescriptionMap.get(description) : 0;
+ mItemDescriptionMap.put(description, count + 1);
+ super.add(item);
+ }
+
+ @Override
+ public void remove(ItemChooserRow item) {
+ String description = item.mDescription;
+ if (mItemDescriptionMap.containsKey(description)) {
+ int count = mItemDescriptionMap.get(description);
+ if (count == 1) {
+ mItemDescriptionMap.remove(description);
+ } else {
+ mItemDescriptionMap.put(description, count - 1);
+ }
+ }
+ super.remove(item);
+ }
+
+ @Override
public void clear() {
mSelectedItem = ListView.INVALID_POSITION;
mConfirmButton.setEnabled(false);
@@ -165,6 +193,20 @@ public class ItemChooserDialog {
}
/**
+ * Returns the text to be displayed on the chooser for an item. For items with the same
+ * description, their unique keys are appended to distinguish them.
+ * @param position The index of the item.
+ */
+ public String getDisplayText(int position) {
+ ItemChooserRow item = getItem(position);
+ String description = item.mDescription;
+ int counter = mItemDescriptionMap.get(description);
+ return counter == 1 ? description
+ : mActivity.getString(R.string.item_chooser_item_name_with_id, description,
+ item.mKey);
+ }
+
+ /**
* Sets whether the itam is enabled. Disabled items are grayed out.
* @param id The id of the item to affect.
* @param enabled Whether the item should be enabled or not.
@@ -218,8 +260,7 @@ public class ItemChooserDialog {
}
}
- ItemChooserRow item = getItem(position);
- view.setText(item.mDescription);
+ view.setText(getDisplayText(position));
return view;
}
« no previous file with comments | « no previous file | chrome/android/java/strings/android_chrome_strings.grd » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698