Commit 2e85f65b authored by Finnur Thorarinsson's avatar Finnur Thorarinsson Committed by Commit Bot

[Android] Contacts Picker: Disable Done button if all data filtered away.

When all chips are deselected, there's no point in having the Done button
enabled, as no data will be sent to the web page. This is much like when
no selection has been made (the Done button becomes enabled only when
more than one contact has been selected).

Bug: 988273, 860467
Change-Id: I16cdc8506d1c00f24a4cbb431765c734dcf666be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1953086
Commit-Queue: Finnur Thorarinsson <finnur@chromium.org>
Reviewed-by: default avatarBoris Sazonov <bsazonov@chromium.org>
Cr-Commit-Position: refs/heads/master@{#723321}
parent 446dbd73
...@@ -32,7 +32,12 @@ public class ContactsPickerToolbar extends SelectableListToolbar<ContactDetails> ...@@ -32,7 +32,12 @@ public class ContactsPickerToolbar extends SelectableListToolbar<ContactDetails>
} }
// A delegate to notify when the dialog should close. // A delegate to notify when the dialog should close.
ContactsToolbarDelegate mDelegate; private ContactsToolbarDelegate mDelegate;
// Whether any filter chips are selected. Default to true because all filter chips are selected
// by default when opening the dialog.
private boolean mFilterChipsSelected = true;
public ContactsPickerToolbar(Context context, AttributeSet attrs) { public ContactsPickerToolbar(Context context, AttributeSet attrs) {
super(context, attrs); super(context, attrs);
} }
...@@ -51,6 +56,16 @@ public class ContactsPickerToolbar extends SelectableListToolbar<ContactDetails> ...@@ -51,6 +56,16 @@ public class ContactsPickerToolbar extends SelectableListToolbar<ContactDetails>
setNavigationButton(NAVIGATION_BUTTON_BACK); setNavigationButton(NAVIGATION_BUTTON_BACK);
} }
/**
* Sets whether any filter chips are |selected| in the dialog.
*/
public void setFilterChipsSelected(boolean selected) {
mFilterChipsSelected = selected;
updateToolbarUI();
}
// SelectableListToolbar:
@Override @Override
public void onNavigationBack() { public void onNavigationBack() {
if (isSearching()) { if (isSearching()) {
...@@ -72,22 +87,33 @@ public class ContactsPickerToolbar extends SelectableListToolbar<ContactDetails> ...@@ -72,22 +87,33 @@ public class ContactsPickerToolbar extends SelectableListToolbar<ContactDetails>
@Override @Override
public void onSelectionStateChange(List<ContactDetails> selectedItems) { public void onSelectionStateChange(List<ContactDetails> selectedItems) {
super.onSelectionStateChange(selectedItems); super.onSelectionStateChange(selectedItems);
updateToolbarUI();
}
/**
* Update the UI elements of the toolbar, based on whether contacts & filter chips are selected.
*/
private void updateToolbarUI() {
boolean contactsSelected = !mSelectionDelegate.getSelectedItems().isEmpty();
int selectCount = selectedItems.size(); boolean doneEnabled = contactsSelected && mFilterChipsSelected;
ButtonCompat done = findViewById(R.id.done); ButtonCompat done = findViewById(R.id.done);
done.setEnabled(selectCount > 0); done.setEnabled(doneEnabled);
AppCompatImageView search = findViewById(R.id.search); AppCompatImageView search = findViewById(R.id.search);
ImageViewCompat.setImageTintList(search, ImageViewCompat.setImageTintList(search,
useDarkIcons() ? getDarkIconColorStateList() : getLightIconColorStateList()); useDarkIcons() ? getDarkIconColorStateList() : getLightIconColorStateList());
if (selectCount > 0) { if (doneEnabled) {
ApiCompatibilityUtils.setTextAppearance(done, R.style.TextAppearance_Body_Inverse); ApiCompatibilityUtils.setTextAppearance(done, R.style.TextAppearance_Body_Inverse);
} else { } else {
ApiCompatibilityUtils.setTextAppearance( ApiCompatibilityUtils.setTextAppearance(
done, R.style.TextAppearance_BlackDisabledText3); done, R.style.TextAppearance_BlackDisabledText3);
if (contactsSelected) {
showBackArrow(); setNavigationButton(NAVIGATION_BUTTON_SELECTION_BACK);
} else {
showBackArrow();
}
} }
} }
} }
...@@ -169,6 +169,12 @@ public class PickerCategoryView extends OptimizedFrameLayout ...@@ -169,6 +169,12 @@ public class PickerCategoryView extends OptimizedFrameLayout
mToolbar.setNavigationOnClickListener(this); mToolbar.setNavigationOnClickListener(this);
mToolbar.initializeSearchView(this, R.string.contacts_picker_search, 0); mToolbar.initializeSearchView(this, R.string.contacts_picker_search, 0);
mToolbar.setDelegate(delegate); mToolbar.setDelegate(delegate);
mPickerAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
@Override
public void onChanged() {
updateSelectionState();
}
});
mSelectableListLayout.configureWideDisplayStyle(); mSelectableListLayout.configureWideDisplayStyle();
mSearchButton = (ImageView) mToolbar.findViewById(R.id.search); mSearchButton = (ImageView) mToolbar.findViewById(R.id.search);
...@@ -328,6 +334,11 @@ public class PickerCategoryView extends OptimizedFrameLayout ...@@ -328,6 +334,11 @@ public class PickerCategoryView extends OptimizedFrameLayout
return mMultiSelectionAllowed; return mMultiSelectionAllowed;
} }
private void updateSelectionState() {
boolean filterChipsSelected = mTopView == null || mTopView.filterChipsChecked() > 0;
mToolbar.setFilterChipsSelected(filterChipsSelected);
}
/** /**
* Formats the selected contacts before notifying the listeners. * Formats the selected contacts before notifying the listeners.
*/ */
......
...@@ -265,6 +265,30 @@ public class TopView extends RelativeLayout ...@@ -265,6 +265,30 @@ public class TopView extends RelativeLayout
} }
} }
/**
* Returns how many filter chips are checked.
*/
public int filterChipsChecked() {
int checked = 0;
if (mNamesFilterChip.getVisibility() == View.VISIBLE && mNamesFilterChip.isSelected()) {
++checked;
}
if (mAddressFilterChip.getVisibility() == View.VISIBLE && mAddressFilterChip.isSelected()) {
++checked;
}
if (mEmailFilterChip.getVisibility() == View.VISIBLE && mEmailFilterChip.isSelected()) {
++checked;
}
if (mTelephonesFilterChip.getVisibility() == View.VISIBLE
&& mTelephonesFilterChip.isSelected()) {
++checked;
}
if (mIconsFilterChip.getVisibility() == View.VISIBLE && mIconsFilterChip.isSelected()) {
++checked;
}
return checked;
}
/** /**
* Updates the state of the checkbox to reflect whether everything is selected. * Updates the state of the checkbox to reflect whether everything is selected.
* @param allSelected * @param allSelected
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment