Add "delete mode" option on mode configuration page
Flag: android.app.modes_ui Bug: 346575126 Test: manual Change-Id: I0d085eb54ef5fa07f312bdddf0219855bf1c2ef4
This commit is contained in:
@@ -16,10 +16,14 @@
|
||||
|
||||
package com.android.settings.notification.modes;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Application;
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.settings.SettingsEnums;
|
||||
import android.content.Context;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
@@ -30,6 +34,9 @@ import java.util.List;
|
||||
|
||||
public class ZenModeFragment extends ZenModeFragmentBase {
|
||||
|
||||
// for mode deletion menu
|
||||
private static final int DELETE_MODE = 1;
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.modes_rule_settings;
|
||||
@@ -76,4 +83,43 @@ public class ZenModeFragment extends ZenModeFragmentBase {
|
||||
// TODO: b/332937635 - make this the correct metrics category
|
||||
return SettingsEnums.NOTIFICATION_ZEN_MODE_AUTOMATION;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
menu.add(Menu.NONE, DELETE_MODE, Menu.NONE, R.string.zen_mode_menu_delete_mode);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onOptionsItemSelected(MenuItem item, ZenMode zenMode) {
|
||||
switch (item.getItemId()) {
|
||||
case DELETE_MODE:
|
||||
new AlertDialog.Builder(mContext)
|
||||
.setTitle(mContext.getString(R.string.zen_mode_delete_mode_confirmation,
|
||||
zenMode.getRule().getName()))
|
||||
.setPositiveButton(R.string.zen_mode_schedule_delete,
|
||||
(dialog, which) -> {
|
||||
// start finishing before calling removeMode() so that we don't
|
||||
// try to update this activity with a nonexistent mode when the
|
||||
// zen mode config is updated
|
||||
finish();
|
||||
mBackend.removeMode(zenMode);
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.show();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateZenModeState() {
|
||||
// Because this fragment may be asked to finish by the delete menu but not be done doing
|
||||
// so yet, ignore any attempts to update info in that case.
|
||||
if (getActivity() != null && getActivity().isFinishing()) {
|
||||
return;
|
||||
}
|
||||
super.updateZenModeState();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user