mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
Add dialog to categories save button
This commit is contained in:
parent
7d896a5e23
commit
61bf77b695
1 changed files with 31 additions and 2 deletions
|
|
@ -510,17 +510,46 @@ public class CategorizationFragment extends Fragment {
|
|||
switch(menuItem.getItemId()) {
|
||||
case R.id.menu_save_categories:
|
||||
ArrayList<String> selectedCategories = new ArrayList<String>();
|
||||
int numberSelected = 0;
|
||||
|
||||
for(CategoryItem item: categoriesAdapter.getItems()) {
|
||||
if(item.selected) {
|
||||
selectedCategories.add(item.name);
|
||||
numberSelected++;
|
||||
}
|
||||
}
|
||||
onCategoriesSaveHandler.onCategoriesSave(selectedCategories);
|
||||
return true;
|
||||
|
||||
//If no categories selected, display warning to user
|
||||
if (numberSelected == 0) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
||||
|
||||
builder.setMessage("Are you sure you want to proceed without selecting categories? Images without categories are rarely usable.")
|
||||
.setTitle("No Categories Selected");
|
||||
builder.setPositiveButton("No", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
//Exit menuItem
|
||||
return;
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton("Yes", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
//Proceed
|
||||
}
|
||||
});
|
||||
|
||||
AlertDialog dialog = builder.create();
|
||||
dialog.show();
|
||||
} else {
|
||||
|
||||
onCategoriesSaveHandler.onCategoriesSave(selectedCategories);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return super.onOptionsItemSelected(menuItem);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onAttach(Activity activity) {
|
||||
super.onAttach(activity);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue