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

Commit e19b8743 authored by Matías Hernández's avatar Matías Hernández Committed by Android (Google) Code Review
Browse files

Merge changes from topic "fix-weird-animation" into main

* changes:
  Fix jiggle when opening custom manual modes
  Allow turning off currently active modes
parents dc8b74e3 e8306014
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -51,8 +51,7 @@
        <Preference
            android:key="zen_add_automatic_trigger"
            android:title="@string/zen_mode_select_schedule"
            android:icon="@drawable/ic_add_24dp"
            settings:isPreferenceVisible="false" />
            android:icon="@drawable/ic_add_24dp" />
    </PreferenceCategory>

    <PreferenceCategory
+7 −3
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.settings.notification.modes;

import static com.google.common.base.Preconditions.checkNotNull;

import android.annotation.NonNull;
import android.content.Context;
import android.provider.Settings;
@@ -36,8 +38,8 @@ class ZenModeButtonPreferenceController extends AbstractZenModePreferenceControl
    private static final String TAG = "ZenModeButtonPrefController";

    private Button mZenButton;
    private Fragment mParent;
    private ManualDurationHelper mDurationHelper;
    private final Fragment mParent;
    private final ManualDurationHelper mDurationHelper;

    ZenModeButtonPreferenceController(Context context, String key, Fragment parent,
            ZenModesBackend backend) {
@@ -48,7 +50,8 @@ class ZenModeButtonPreferenceController extends AbstractZenModePreferenceControl

    @Override
    public boolean isAvailable(ZenMode zenMode) {
        return zenMode.getRule().isManualInvocationAllowed() && zenMode.getRule().isEnabled();
        return zenMode.isEnabled()
                && (zenMode.isActive() || zenMode.getRule().isManualInvocationAllowed());
    }

    @Override
@@ -57,6 +60,7 @@ class ZenModeButtonPreferenceController extends AbstractZenModePreferenceControl
            mZenButton = ((LayoutPreference) preference).findViewById(R.id.activate_mode);
        }
        mZenButton.setOnClickListener(v -> {
            checkNotNull(mBackend, "Backend not available!");
            if (zenMode.isActive()) {
                mBackend.deactivateMode(zenMode);
            } else {
+7 −2
Original line number Diff line number Diff line
@@ -65,8 +65,13 @@ public class ZenModeFragment extends ZenModeFragmentBase {
                new ZenModePreferenceCategoryController(context, "modes_additional_actions"));
        prefControllers.add(new ZenModeDisplayLinkPreferenceController(
                context, "mode_display_settings", mBackend, mHelperBackend));
        prefControllers.add(new ZenModeSetTriggerLinkPreferenceController(context,
                "zen_automatic_trigger_category", this, mBackend));
        prefControllers.add(new ZenModeTriggerCategoryPreferenceController(context,
                "zen_automatic_trigger_category"));
        prefControllers.add(new ZenModeTriggerUpdatePreferenceController(context,
                "zen_automatic_trigger_settings", mBackend));
        prefControllers.add(
                new ZenModeTriggerAddPreferenceController(context, "zen_add_automatic_trigger",
                        this, mBackend));
        prefControllers.add(new InterruptionFilterPreferenceController(
                context, "allow_filtering", mBackend));
        prefControllers.add(new ManualDurationPreferenceController(
+63 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.notification.modes;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;

import com.android.settings.dashboard.DashboardFragment;
import com.android.settingslib.notification.modes.ZenMode;
import com.android.settingslib.notification.modes.ZenModesBackend;

class ZenModeTriggerAddPreferenceController extends AbstractZenModePreferenceController {

    private final DashboardFragment mFragment;

    ZenModeTriggerAddPreferenceController(@NonNull Context context,
            @NonNull String key, DashboardFragment fragment, ZenModesBackend backend) {
        super(context, key, backend);
        mFragment = fragment;
    }

    @Override
    public boolean isAvailable(@NonNull ZenMode zenMode) {
        return zenMode.isCustomManual();
    }

    @Override
    void updateState(Preference preference, @NonNull ZenMode zenMode) {
        if (!isAvailable(zenMode)) {
            return;
        }

        preference.setOnPreferenceClickListener(unused -> {
            ZenModeScheduleChooserDialog.show(mFragment, mOnScheduleOptionListener);
            return true;
        });
    }

    @VisibleForTesting
    final ZenModeScheduleChooserDialog.OnScheduleOptionListener mOnScheduleOptionListener =
            conditionId -> saveMode(mode -> {
                mode.setCustomModeConditionId(mContext, conditionId);
                return mode;
                // TODO: b/342156843 - Maybe jump to the corresponding schedule editing screen?
            });
}
+44 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settings.notification.modes;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.preference.Preference;

import com.android.settingslib.notification.modes.ZenMode;

/**
 * Preference controller for the "Turn on automatically" category
 */
class ZenModeTriggerCategoryPreferenceController extends AbstractZenModePreferenceController {

    ZenModeTriggerCategoryPreferenceController(Context context, String key) {
        super(context, key);
    }

    @Override
    public boolean isAvailable(@NonNull ZenMode zenMode) {
        return !zenMode.isManualDnd();
    }

    @Override
    public void updateState(Preference preference, @NonNull ZenMode zenMode) {
        // Nothing to update here (except visibility via isAvailable()).
    }
}
Loading