Hide "Remove" menu & the drag handle when there's just one locale

When there's just one locale, showing the "Remove" menu and the
drag handle is confusing to the user since nothing can happen if
they try to use them: the drag simply won't happen, and if they
go through the delete process, we give them an error.

Bug: 26730336
Change-Id: Ie219dd9b3d653272b325d7af01aba205a58cd472
This commit is contained in:
Mihai Nita
2016-03-08 10:53:24 -08:00
parent 0f20f969b8
commit 7751358ab6
2 changed files with 13 additions and 2 deletions

View File

@@ -153,7 +153,7 @@ class LocaleDragAndDropAdapter
dragCell.setMiniLabel(mNumberFormatter.format(i + 1)); dragCell.setMiniLabel(mNumberFormatter.format(i + 1));
dragCell.setShowCheckbox(mRemoveMode); dragCell.setShowCheckbox(mRemoveMode);
dragCell.setShowMiniLabel(!mRemoveMode); dragCell.setShowMiniLabel(!mRemoveMode);
dragCell.setShowHandle(!mRemoveMode); dragCell.setShowHandle(!mRemoveMode && mDragEnabled);
dragCell.setChecked(false); dragCell.setChecked(false);
dragCell.setTag(feedItem); dragCell.setTag(feedItem);
dragCell.getCheckbox() dragCell.getCheckbox()

View File

@@ -67,7 +67,7 @@ public class LocaleListEditor extends SettingsPreferenceFragment
setHasOptionsMenu(true); setHasOptionsMenu(true);
LocaleStore.fillCache(this.getContext()); LocaleStore.fillCache(this.getContext());
List<LocaleStore.LocaleInfo> feedsList = getUserLocaleList(this.getContext()); final List<LocaleStore.LocaleInfo> feedsList = getUserLocaleList(this.getContext());
mAdapter = new LocaleDragAndDropAdapter(this.getContext(), feedsList); mAdapter = new LocaleDragAndDropAdapter(this.getContext(), feedsList);
} }
@@ -144,6 +144,7 @@ public class LocaleListEditor extends SettingsPreferenceFragment
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
mAdapter.removeChecked(); mAdapter.removeChecked();
setRemoveMode(!mRemoveMode); setRemoveMode(!mRemoveMode);
updateVisibilityOfRemoveMenu();
} }
}) })
.create() .create()
@@ -158,6 +159,7 @@ public class LocaleListEditor extends SettingsPreferenceFragment
menuItem.setIcon(R.drawable.ic_delete); menuItem.setIcon(R.drawable.ic_delete);
super.onCreateOptionsMenu(menu, inflater); super.onCreateOptionsMenu(menu, inflater);
mMenu = menu; mMenu = menu;
updateVisibilityOfRemoveMenu();
} }
private static List<LocaleStore.LocaleInfo> getUserLocaleList(Context context) { private static List<LocaleStore.LocaleInfo> getUserLocaleList(Context context) {
@@ -201,6 +203,15 @@ public class LocaleListEditor extends SettingsPreferenceFragment
@Override @Override
public void onLocaleSelected(LocaleStore.LocaleInfo locale) { public void onLocaleSelected(LocaleStore.LocaleInfo locale) {
mAdapter.addLocale(locale); mAdapter.addLocale(locale);
updateVisibilityOfRemoveMenu();
} }
// Hide the "Remove" menu if there is only one locale in the list, show it otherwise
// This is called when the menu is first created, and then one add / remove locale
private void updateVisibilityOfRemoveMenu() {
final MenuItem menuItemRemove = mMenu.findItem(MENU_ID_REMOVE);
if (menuItemRemove != null) {
menuItemRemove.setVisible(mAdapter.getItemCount() > 1);
}
}
} }