Merge "Add "delete mode" option on mode configuration page" into main
This commit is contained in:
@@ -7967,9 +7967,15 @@
|
|||||||
<!-- Do not disturb: Title for dialog that allows users to delete DND rules/schedules[CHAR LIMIT=40] -->
|
<!-- Do not disturb: Title for dialog that allows users to delete DND rules/schedules[CHAR LIMIT=40] -->
|
||||||
<string name="zen_mode_delete_automatic_rules">Delete schedules</string>
|
<string name="zen_mode_delete_automatic_rules">Delete schedules</string>
|
||||||
|
|
||||||
<!-- Do not disturb: Delete text button presented in a dialog to confirm the user would like to delete the selected DND rules. [CHAR LIMIT=30] -->
|
<!-- Do not disturb: Delete text button presented in a dialog to confirm the user would like to delete the selected DND rules. [CHAR LIMIT=30] -->
|
||||||
<string name="zen_mode_schedule_delete">Delete</string>
|
<string name="zen_mode_schedule_delete">Delete</string>
|
||||||
|
|
||||||
|
<!-- Do not disturb: Menu option for deleting a mode on its configuration page [CHAR LIMIT=40] -->
|
||||||
|
<string name="zen_mode_menu_delete_mode">Delete mode</string>
|
||||||
|
|
||||||
|
<!-- Do not disturb: Confirmation dialog asking the user whether they would like to delete the named mode [CHAR LIMIT: 40] -->
|
||||||
|
<string name="zen_mode_delete_mode_confirmation">Delete \"<xliff:g id="mode" example="My Schedule">%1$s</xliff:g>\" mode?</string>
|
||||||
|
|
||||||
<!-- Do not disturb: Edit label for button that allows user to edit the dnd schedule name. [CHAR LIMIT=30] -->
|
<!-- Do not disturb: Edit label for button that allows user to edit the dnd schedule name. [CHAR LIMIT=30] -->
|
||||||
<string name="zen_mode_rule_name_edit">Edit</string>
|
<string name="zen_mode_rule_name_edit">Edit</string>
|
||||||
|
|
||||||
|
@@ -16,10 +16,14 @@
|
|||||||
|
|
||||||
package com.android.settings.notification.modes;
|
package com.android.settings.notification.modes;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.app.AutomaticZenRule;
|
import android.app.AutomaticZenRule;
|
||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settingslib.applications.ApplicationsState;
|
import com.android.settingslib.applications.ApplicationsState;
|
||||||
@@ -31,6 +35,9 @@ import java.util.List;
|
|||||||
|
|
||||||
public class ZenModeFragment extends ZenModeFragmentBase {
|
public class ZenModeFragment extends ZenModeFragmentBase {
|
||||||
|
|
||||||
|
// for mode deletion menu
|
||||||
|
private static final int DELETE_MODE = 1;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getPreferenceScreenResId() {
|
protected int getPreferenceScreenResId() {
|
||||||
return R.xml.modes_rule_settings;
|
return R.xml.modes_rule_settings;
|
||||||
@@ -77,4 +84,43 @@ public class ZenModeFragment extends ZenModeFragmentBase {
|
|||||||
// TODO: b/332937635 - make this the correct metrics category
|
// TODO: b/332937635 - make this the correct metrics category
|
||||||
return SettingsEnums.NOTIFICATION_ZEN_MODE_AUTOMATION;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@ import android.app.AutomaticZenRule;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -114,6 +115,18 @@ abstract class ZenModeFragmentBase extends ZenModesFragmentBase {
|
|||||||
updateControllers();
|
updateControllers();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean onOptionsItemSelected(MenuItem item) {
|
||||||
|
if (mZenMode != null) {
|
||||||
|
return onOptionsItemSelected(item, mZenMode);
|
||||||
|
}
|
||||||
|
return super.onOptionsItemSelected(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean onOptionsItemSelected(MenuItem item, @NonNull ZenMode zenMode) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private void updateControllers() {
|
private void updateControllers() {
|
||||||
if (getPreferenceControllers() == null || mZenMode == null) {
|
if (getPreferenceControllers() == null || mZenMode == null) {
|
||||||
return;
|
return;
|
||||||
|
Reference in New Issue
Block a user