Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 48903cce authored by Beverly's avatar Beverly
Browse files

Add edit and delete buttons to zen rules

Test: atest ZenModeScheduleRuleSettingsTest ZenModeEventRuleSettingsTest
Test: manual
Bug: 111475013
Fixes: 120787343
Fixes: 120758763
Change-Id: If81ce2972e6887fb2a85d4b7262e81b26162e19c
parent f80e5b56
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -7123,6 +7123,9 @@
    <!--  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>
    <!--  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>
    <!--  Do not disturb: Title for the zen mode automatic rules page in settings. [CHAR LIMIT=30] -->
    <string name="zen_mode_automation_settings_page_title">Schedules</string>
@@ -7893,7 +7896,7 @@
        <item quantity="other"><xliff:g id="num_people" example="3">%d</xliff:g> others</item>
    </plurals>
    <!-- [CHAR LIMIT=20] Zen mode settings: Messages option -->
    <!-- [CHAR LIMIT=40] Zen mode settings: Messages option -->
    <string name="zen_mode_messages">Allow text messages</string>
    <!-- Do not disturb settings, messages, events and reminders footer [CHAR LIMIT=NONE]-->
+6 −1
Original line number Diff line number Diff line
@@ -17,12 +17,17 @@

<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    android:key="zen_mode_event_rule_settings"
    android:title="@string/zen_mode_automatic_rule_settings_page_title">

    <com.android.settingslib.widget.LayoutPreference
        android:key="pref_app_header"
        android:layout="@layout/settings_entity_header" />
        android:layout="@layout/settings_entity_header"
        settings:allowDividerBelow="true" />

    <com.android.settingslib.widget.ActionButtonsPreference
        android:key="zen_action_buttons" />

    <com.android.settingslib.widget.LayoutPreference
        android:key="zen_automatic_rule_switch"
+6 −1
Original line number Diff line number Diff line
@@ -17,12 +17,17 @@

<PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:settings="http://schemas.android.com/apk/res-auto"
    android:key="zen_mode_schedule_rule_settings"
    android:title="@string/zen_mode_automatic_rule_settings_page_title">

    <com.android.settingslib.widget.LayoutPreference
        android:key="pref_app_header"
        android:layout="@layout/settings_entity_header" />
        android:layout="@layout/settings_entity_header"
        settings:allowDividerBelow="true"/>

    <com.android.settingslib.widget.ActionButtonsPreference
        android:key="zen_action_buttons"/>

    <com.android.settingslib.widget.LayoutPreference
        android:key="zen_automatic_rule_switch"
+0 −24
Original line number Diff line number Diff line
@@ -76,14 +76,6 @@ public class ZenAutomaticRuleHeaderPreferenceController extends AbstractZenModeP
                mController = EntityHeaderController
                        .newInstance(mFragment.getActivity(), mFragment,
                                pref.findViewById(R.id.entity_header));

                mController.setEditListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ZenRuleNameDialog.show(mFragment, mRule.getName(), null,
                                new RuleNameChangeListener());
                    }
                });
            }

            pref = mController.setIcon(getIcon())
@@ -123,20 +115,4 @@ public class ZenAutomaticRuleHeaderPreferenceController extends AbstractZenModeP
        mRule = rule;
        mId = id;
    }

    public class RuleNameChangeListener implements ZenRuleNameDialog.PositiveClickListener {
        public RuleNameChangeListener() {}

        @Override
        public void onOk(String ruleName, Fragment parent) {
            if (TextUtils.equals(ruleName, mRule.getName())) {
                return;
            }
            mMetricsFeatureProvider.action(mContext,
                    MetricsProto.MetricsEvent.ACTION_ZEN_MODE_RULE_NAME_CHANGE_OK);
            mRule.setName(ruleName);
            mRule.setModified(true);
            mBackend.updateZenRule(mId, mRule);
        }
    }
}
+12 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.AlertDialog;
import android.app.AutomaticZenRule;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.provider.SearchIndexableResource;
import android.service.notification.ConditionProviderService;
import android.view.Menu;
@@ -44,11 +45,22 @@ import java.util.Map;

@SearchIndexable
public class ZenModeAutomationSettings extends ZenModeSettingsBase {
    public static final String DELETE = "DELETE_RULE";
    protected final ManagedServiceSettings.Config CONFIG = getConditionProviderConfig();
    private CharSequence[] mDeleteDialogRuleNames;
    private String[] mDeleteDialogRuleIds;
    private boolean[] mDeleteDialogChecked;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        Bundle bundle = getArguments();
        if (bundle != null && bundle.containsKey(DELETE)) {
            mBackend.removeZenRule(bundle.getString(DELETE));
            bundle.remove(DELETE);
        }
    }

    @Override
    protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
        ZenServiceListing serviceListing = new ZenServiceListing(getContext(), CONFIG);
Loading