Files
packages_apps_Settings/src/com/android/settings/notification/modes/ZenModeExitAtAlarmPreferenceController.java
Matías Hernández 13bb8e714d Hide ZenMode.getRule() - Settings
Bug: 393321037
Test: atest com.android.settings.notification.modes
Flag: EXEMPT Unflaggable refactoring
Change-Id: Ia9b43146f687ebee29eee0328a92e59c0c6d574a
2025-02-18 14:27:58 +01:00

64 lines
2.3 KiB
Java

/*
* 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 static com.google.common.base.Preconditions.checkNotNull;
import android.content.Context;
import android.service.notification.ZenModeConfig;
import androidx.annotation.NonNull;
import androidx.preference.Preference;
import androidx.preference.TwoStatePreference;
import com.android.settingslib.notification.modes.ZenMode;
import com.android.settingslib.notification.modes.ZenModeSchedules;
import com.android.settingslib.notification.modes.ZenModesBackend;
/**
* Preference controller controlling whether a time schedule-based mode ends at the next alarm.
*/
class ZenModeExitAtAlarmPreferenceController extends
AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
private ZenModeConfig.ScheduleInfo mSchedule;
ZenModeExitAtAlarmPreferenceController(Context context,
String key, ZenModesBackend backend) {
super(context, key, backend);
}
@Override
public void updateState(Preference preference, @NonNull ZenMode zenMode) {
mSchedule = checkNotNull(ZenModeSchedules.getTimeSchedule(zenMode));
((TwoStatePreference) preference).setChecked(mSchedule.exitAtAlarm);
}
@Override
public boolean onPreferenceChange(@NonNull Preference preference, Object newValue) {
final boolean exitAtAlarm = (Boolean) newValue;
if (mSchedule.exitAtAlarm != exitAtAlarm) {
mSchedule.exitAtAlarm = exitAtAlarm;
return saveMode(mode -> {
mode.setCustomModeConditionId(mContext,
ZenModeConfig.toScheduleConditionId(mSchedule));
return mode;
});
}
return false;
}
}