Add setting to never notify of upcoming alarms

This commit is contained in:
Phillip Hsu
2016-09-27 04:28:56 -07:00
parent a9589a1742
commit 012c8fb425
3 changed files with 15 additions and 10 deletions
@@ -78,13 +78,16 @@ public final class AlarmController {
// to handle that yourself by using a wakelock, etc..
// We use a WAKEUP alarm to send the upcoming alarm notification so it goes off even if the
// device is asleep. Otherwise, it will not go off until the device is turned back on.
long ringAt = alarm.isSnoozed() ? alarm.snoozingUntil() : alarm.ringsAt();
int hoursToNotifyInAdvance = AlarmPreferences.hoursBeforeUpcoming(mAppContext);
long upcomingAt = ringAt - HOURS.toMillis(hoursToNotifyInAdvance);
// If snoozed, upcoming note posted immediately.
am.set(AlarmManager.RTC_WAKEUP, upcomingAt, notifyUpcomingAlarmIntent(alarm, false));
final long ringAt = alarm.isSnoozed() ? alarm.snoozingUntil() : alarm.ringsAt();
am.setExact(AlarmManager.RTC_WAKEUP, ringAt, alarmIntent(alarm, false));
final int hoursToNotifyInAdvance = AlarmPreferences.hoursBeforeUpcoming(mAppContext);
if (hoursToNotifyInAdvance > 0 || alarm.isSnoozed()) {
// If snoozed, upcoming note posted immediately.
long upcomingAt = ringAt - HOURS.toMillis(hoursToNotifyInAdvance);
am.set(AlarmManager.RTC_WAKEUP, upcomingAt, notifyUpcomingAlarmIntent(alarm, false));
}
if (showSnackbar) {
String message = mAppContext.getString(R.string.alarm_set_for,
DurationUtils.toString(mAppContext, alarm.ringsIn(), false /*abbreviate?*/));
@@ -120,12 +123,12 @@ public final class AlarmController {
// Does nothing if it's not posted.
removeUpcomingAlarmNotification(alarm);
int hoursToNotifyInAdvance = AlarmPreferences.hoursBeforeUpcoming(mAppContext);
final int hoursToNotifyInAdvance = AlarmPreferences.hoursBeforeUpcoming(mAppContext);
// TOneverDO: Place block after making value changes to the alarm.
if (showSnackbar
if ((hoursToNotifyInAdvance > 0 && showSnackbar
// TODO: Consider showing the snackbar for non-upcoming alarms too;
// then, we can remove these checks.
&& alarm.ringsWithinHours(hoursToNotifyInAdvance) || alarm.isSnoozed()) {
&& alarm.ringsWithinHours(hoursToNotifyInAdvance)) || alarm.isSnoozed()) {
long time = alarm.isSnoozed() ? alarm.snoozingUntil() : alarm.ringsAt();
String msg = mAppContext.getString(R.string.upcoming_alarm_dismissed,
formatTime(mAppContext, time));
@@ -275,8 +275,8 @@ public abstract class BaseAlarmViewHolder extends BaseViewHolder<Alarm> {
}
private void bindDismissButton(Alarm alarm) {
int hoursBeforeUpcoming = AlarmPreferences.hoursBeforeUpcoming(getContext());
boolean upcoming = alarm.ringsWithinHours(hoursBeforeUpcoming);
final int hoursBeforeUpcoming = AlarmPreferences.hoursBeforeUpcoming(getContext());
boolean upcoming = hoursBeforeUpcoming > 0 && alarm.ringsWithinHours(hoursBeforeUpcoming);
boolean snoozed = alarm.isSnoozed();
boolean visible = alarm.isEnabled() && (upcoming || snoozed);
String buttonText = snoozed