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; |
} |