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

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

Issue 2378433002: Disable "Pair" button when selected item is disabled/removed for chooser on Android (Closed)
Patch Set: address comments Created 4 years, 3 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 d93e107d842d9a3df9b1288538dbc1e9eab095a6..ec0bfdf1052e41d26e6b9c724de06e3e4d01eb2e 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/ItemChooserDialog.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/ItemChooserDialog.java
@@ -202,6 +202,17 @@ public class ItemChooserDialog {
public void remove(ItemChooserRow item) {
ItemChooserRow oldItem = mKeyToItemMap.remove(item.mKey);
if (oldItem == null) return;
+ int oldItemPosition = getPosition(oldItem);
+ // If the removed item is the item that is currently selected, deselect it
+ // and disable the confirm button. Otherwise if the removed item is before
+ // the currently selected item, the currently selected item's index needs
+ // to be adjusted by one.
+ if (oldItemPosition == mSelectedItem) {
+ mSelectedItem = ListView.INVALID_POSITION;
+ mConfirmButton.setEnabled(false);
+ } else if (oldItemPosition < mSelectedItem) {
+ --mSelectedItem;
+ }
removeFromDescriptionsMap(oldItem.mDescription);
super.remove(oldItem);
}
@@ -221,6 +232,7 @@ public class ItemChooserDialog {
* selected.
*/
public String getSelectedItemKey() {
+ if (mSelectedItem == ListView.INVALID_POSITION) return "";
ItemChooserRow row = getItem(mSelectedItem);
if (row == null) return "";
return row.mKey;
@@ -241,7 +253,7 @@ public class ItemChooserDialog {
}
/**
- * Sets whether the itam is enabled. Disabled items are grayed out.
+ * Sets whether the item 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.
*/
@@ -251,6 +263,14 @@ public class ItemChooserDialog {
} else {
mDisabledEntries.add(id);
}
+
+ if (mSelectedItem != ListView.INVALID_POSITION) {
+ ItemChooserRow selectedRow = getItem(mSelectedItem);
+ if (id.equals(selectedRow.mKey)) {
+ mConfirmButton.setEnabled(enabled);
+ }
+ }
+
notifyDataSetChanged();
}
@@ -399,6 +419,7 @@ public class ItemChooserDialog {
});
mItemAdapter = new ItemAdapter(mActivity, R.layout.item_chooser_dialog_row);
+ mItemAdapter.setNotifyOnChange(true);
mListView.setAdapter(mItemAdapter);
mListView.setEmptyView(mEmptyMessage);
mListView.setOnItemClickListener(mItemAdapter);
« 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