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

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

Issue 2256893003: bluetooth: Update the item's description on android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address tedchoc's feedback Created 4 years, 4 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/javatests/src/org/chromium/chrome/browser/ItemChooserDialogTest.java » ('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 1596fb5149c4b98062b878c172d7f8a99bb001f4..d93e107d842d9a3df9b1288538dbc1e9eab095a6 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ItemChooserDialog.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ItemChooserDialog.java
@@ -162,35 +162,48 @@ public class ItemChooserDialog {
R.color.default_text_color);
}
+ @Override
+ public boolean isEmpty() {
+ boolean isEmpty = super.isEmpty();
+ if (isEmpty) {
+ assert mKeyToItemMap.isEmpty();
+ assert mDisabledEntries.isEmpty();
+ assert mItemDescriptionMap.isEmpty();
+ } else {
+ assert !mKeyToItemMap.isEmpty();
+ assert !mItemDescriptionMap.isEmpty();
+ }
+ return isEmpty;
+ }
+
public void addOrUpdate(ItemChooserRow item) {
- if (mKeyToItemMap.containsKey(item.mKey)) {
- // TODO(ortuno): Update description.
- // https://crbug.com/634366
+ ItemChooserRow oldItem = mKeyToItemMap.get(item.mKey);
+ if (oldItem != null) {
+ if (oldItem.equals(item)) {
+ // No need to update anything.
+ return;
+ }
+ if (!oldItem.mDescription.equals(item.mDescription)) {
+ removeFromDescriptionsMap(oldItem.mDescription);
+ oldItem.mDescription = item.mDescription;
+ addToDescriptionsMap(oldItem.mDescription);
+ }
+ notifyDataSetChanged();
return;
}
ItemChooserRow result = mKeyToItemMap.put(item.mKey, item);
assert result == null;
- String description = item.mDescription;
- int count = mItemDescriptionMap.containsKey(description)
- ? mItemDescriptionMap.get(description) : 0;
- mItemDescriptionMap.put(description, count + 1);
+ addToDescriptionsMap(item.mDescription);
add(item);
}
@Override
public void remove(ItemChooserRow item) {
- mKeyToItemMap.remove(item.mKey);
- 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);
+ ItemChooserRow oldItem = mKeyToItemMap.remove(item.mKey);
+ if (oldItem == null) return;
+ removeFromDescriptionsMap(oldItem.mDescription);
+ super.remove(oldItem);
}
@Override
@@ -291,6 +304,25 @@ public class ItemChooserDialog {
mConfirmButton.setEnabled(true);
mItemAdapter.notifyDataSetChanged();
}
+
+ private void addToDescriptionsMap(String description) {
+ int count = mItemDescriptionMap.containsKey(description)
+ ? mItemDescriptionMap.get(description)
+ : 0;
+ mItemDescriptionMap.put(description, count + 1);
+ }
+
+ private void removeFromDescriptionsMap(String description) {
+ if (!mItemDescriptionMap.containsKey(description)) {
+ return;
+ }
+ int count = mItemDescriptionMap.get(description);
+ if (count == 1) {
+ mItemDescriptionMap.remove(description);
+ } else {
+ mItemDescriptionMap.put(description, count - 1);
+ }
+ }
}
private Activity mActivity;
« no previous file with comments | « no previous file | chrome/android/javatests/src/org/chromium/chrome/browser/ItemChooserDialogTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698