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

View File

@ -78,13 +78,16 @@ public final class AlarmController {
// to handle that yourself by using a wakelock, etc.. // 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 // 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. // device is asleep. Otherwise, it will not go off until the device is turned back on.
long ringAt = alarm.isSnoozed() ? alarm.snoozingUntil() : alarm.ringsAt(); final 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));
am.setExact(AlarmManager.RTC_WAKEUP, ringAt, alarmIntent(alarm, false)); 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) { if (showSnackbar) {
String message = mAppContext.getString(R.string.alarm_set_for, String message = mAppContext.getString(R.string.alarm_set_for,
DurationUtils.toString(mAppContext, alarm.ringsIn(), false /*abbreviate?*/)); DurationUtils.toString(mAppContext, alarm.ringsIn(), false /*abbreviate?*/));
@ -120,12 +123,12 @@ public final class AlarmController {
// Does nothing if it's not posted. // Does nothing if it's not posted.
removeUpcomingAlarmNotification(alarm); removeUpcomingAlarmNotification(alarm);
int hoursToNotifyInAdvance = AlarmPreferences.hoursBeforeUpcoming(mAppContext); final int hoursToNotifyInAdvance = AlarmPreferences.hoursBeforeUpcoming(mAppContext);
// TOneverDO: Place block after making value changes to the alarm. // 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; // TODO: Consider showing the snackbar for non-upcoming alarms too;
// then, we can remove these checks. // then, we can remove these checks.
&& alarm.ringsWithinHours(hoursToNotifyInAdvance) || alarm.isSnoozed()) { && alarm.ringsWithinHours(hoursToNotifyInAdvance)) || alarm.isSnoozed()) {
long time = alarm.isSnoozed() ? alarm.snoozingUntil() : alarm.ringsAt(); long time = alarm.isSnoozed() ? alarm.snoozingUntil() : alarm.ringsAt();
String msg = mAppContext.getString(R.string.upcoming_alarm_dismissed, String msg = mAppContext.getString(R.string.upcoming_alarm_dismissed,
formatTime(mAppContext, time)); formatTime(mAppContext, time));

View File

@ -275,8 +275,8 @@ public abstract class BaseAlarmViewHolder extends BaseViewHolder<Alarm> {
} }
private void bindDismissButton(Alarm alarm) { private void bindDismissButton(Alarm alarm) {
int hoursBeforeUpcoming = AlarmPreferences.hoursBeforeUpcoming(getContext()); final int hoursBeforeUpcoming = AlarmPreferences.hoursBeforeUpcoming(getContext());
boolean upcoming = alarm.ringsWithinHours(hoursBeforeUpcoming); boolean upcoming = hoursBeforeUpcoming > 0 && alarm.ringsWithinHours(hoursBeforeUpcoming);
boolean snoozed = alarm.isSnoozed(); boolean snoozed = alarm.isSnoozed();
boolean visible = alarm.isEnabled() && (upcoming || snoozed); boolean visible = alarm.isEnabled() && (upcoming || snoozed);
String buttonText = snoozed String buttonText = snoozed

View File

@ -50,6 +50,7 @@
<string name="key_notify_me_of_upcoming_alarms">key_notify_me_of_upcoming_alarms</string> <string name="key_notify_me_of_upcoming_alarms">key_notify_me_of_upcoming_alarms</string>
<string name="title_notify_me_of_upcoming_alarms">Notify me of upcoming alarms</string> <string name="title_notify_me_of_upcoming_alarms">Notify me of upcoming alarms</string>
<string-array name="entries_notify_me_of_upcoming_alarms"> <string-array name="entries_notify_me_of_upcoming_alarms">
<item>Never</item>
<item>1 hour before</item> <item>1 hour before</item>
<item>2 hours before</item> <item>2 hours before</item>
<item>3 hours before</item> <item>3 hours before</item>
@ -60,6 +61,7 @@
<item>8 hours before</item> <item>8 hours before</item>
</string-array> </string-array>
<string-array name="values_notify_me_of_upcoming_alarms"> <string-array name="values_notify_me_of_upcoming_alarms">
<item>0</item>
<item>1</item> <item>1</item>
<item>2</item> <item>2</item>
<item>3</item> <item>3</item>