More callback events added to AlarmVH. Toast message confirmation when upcoming alarm is dismissed.

This commit is contained in:
Phillip Hsu
2016-06-08 01:54:06 -07:00
parent ffb6f40fd0
commit e2449bb11e
3 changed files with 56 additions and 1 deletions
@@ -21,6 +21,7 @@ import static android.app.PendingIntent.FLAG_NO_CREATE;
import static android.app.PendingIntent.getActivity;
import static com.philliphsu.clock2.util.DateFormatUtils.formatTime;
import static com.philliphsu.clock2.util.Preconditions.checkNotNull;
import static java.util.concurrent.TimeUnit.HOURS;
/**
* Created by Phillip Hsu on 6/3/2016.
@@ -50,7 +51,7 @@ public final class AlarmUtils {
// device is asleep. Otherwise, it will not go off until the device is turned back on.
long ringAt = alarm.isSnoozed() ? alarm.snoozingUntil() : alarm.ringsAt();
// If snoozed, upcoming note posted immediately.
am.set(AlarmManager.RTC_WAKEUP, ringAt - hoursBeforeUpcoming(context) * 3600000,
am.set(AlarmManager.RTC_WAKEUP, ringAt - HOURS.toMillis(hoursBeforeUpcoming(context)),
notifyUpcomingAlarmIntent(context, alarm, false));
am.setExact(AlarmManager.RTC_WAKEUP, ringAt, alarmIntent(context, alarm, false));
@@ -91,6 +92,12 @@ public final class AlarmUtils {
save(c);
}
if (a.ringsIn() <= HOURS.toMillis(hoursBeforeUpcoming(c))) {
String time = formatTime(c, a.ringsAt());
String text = c.getString(R.string.upcoming_alarm_dismissed, time);
Toast.makeText(c, text, Toast.LENGTH_LONG).show();
}
// If service is not running, nothing happens
// TODO: Since RingtoneService is a bound service, will this destroy the service after returning?
// Note that if a stopped service still has ServiceConnection objects bound to it with the