Fix bug where deleting a recurring alarm was rescheduling it
This commit is contained in:
parent
fd556db351
commit
41c4d27a09
@ -43,7 +43,7 @@ public class UpcomingAlarmReceiver extends BroadcastReceiver {
|
||||
nm.cancel(TAG, (int) id);
|
||||
} else {
|
||||
if (ACTION_DISMISS_NOW.equals(intent.getAction())) {
|
||||
new AlarmController(context, null).cancelAlarm(alarm, false);
|
||||
new AlarmController(context, null).cancelAlarm(alarm, false, true);
|
||||
} else {
|
||||
// Prepare notification
|
||||
// http://stackoverflow.com/a/15803726/5055032
|
||||
|
||||
@ -39,7 +39,7 @@ public final class AsyncAlarmsTableUpdateHandler extends AsyncDatabaseTableUpdat
|
||||
|
||||
@Override
|
||||
protected void onPostAsyncDelete(Integer result, final Alarm alarm) {
|
||||
mAlarmController.cancelAlarm(alarm, false);
|
||||
mAlarmController.cancelAlarm(alarm, false, false);
|
||||
if (mSnackbarAnchor != null) {
|
||||
// TODO: Consider adding delay to allow the alarm item animation
|
||||
// to finish first before we show the snackbar. Inbox app does this.
|
||||
|
||||
@ -91,8 +91,11 @@ public final class AlarmController {
|
||||
|
||||
/**
|
||||
* Cancel the alarm. This does NOT check if you previously scheduled the alarm.
|
||||
* @param rescheduleIfRecurring True if the alarm should be rescheduled after cancelling.
|
||||
* This param will only be considered if the alarm has recurrence
|
||||
* and is enabled.
|
||||
*/
|
||||
public void cancelAlarm(Alarm alarm, boolean showSnackbar) {
|
||||
public void cancelAlarm(Alarm alarm, boolean showSnackbar, boolean rescheduleIfRecurring) {
|
||||
// TODO: Consider doing this in a new thread.
|
||||
Log.d(TAG, "Cancelling alarm " + alarm);
|
||||
AlarmManager am = (AlarmManager) mAppContext.getSystemService(Context.ALARM_SERVICE);
|
||||
@ -130,7 +133,7 @@ public final class AlarmController {
|
||||
|
||||
if (!alarm.hasRecurrence()) {
|
||||
alarm.setEnabled(false);
|
||||
} else if (alarm.isEnabled()) {
|
||||
} else if (alarm.isEnabled() && rescheduleIfRecurring) {
|
||||
if (alarm.ringsWithinHours(hoursToNotifyInAdvance)) {
|
||||
// Still upcoming today, so wait until the normal ring time
|
||||
// passes before rescheduling the alarm.
|
||||
|
||||
@ -157,7 +157,7 @@ public abstract class BaseAlarmViewHolder extends BaseViewHolder<Alarm> {
|
||||
} else {
|
||||
// Dismisses the current upcoming alarm and handles scheduling the next alarm for us.
|
||||
// Since changes are saved to the database, this prompts a UI refresh.
|
||||
mAlarmController.cancelAlarm(alarm, true);
|
||||
mAlarmController.cancelAlarm(alarm, true, true);
|
||||
}
|
||||
// TOneverDO: AlarmUtils.cancelAlarm() otherwise it will be called twice
|
||||
/*
|
||||
@ -209,7 +209,7 @@ public abstract class BaseAlarmViewHolder extends BaseViewHolder<Alarm> {
|
||||
// TODO: On 21+, upcoming notification doesn't post immediately
|
||||
persistUpdatedAlarm(alarm, true);
|
||||
} else {
|
||||
mAlarmController.cancelAlarm(alarm, true);
|
||||
mAlarmController.cancelAlarm(alarm, true, false);
|
||||
// cancelAlarm() already calls save() for you.
|
||||
}
|
||||
mSwitch.setPressed(false); // clear the pressed focus, esp. if setPressed(true) was called manually
|
||||
|
||||
@ -104,7 +104,7 @@ public class AlarmActivity extends RingtoneActivity<Alarm> {
|
||||
@Override
|
||||
protected void onRightButtonClick() {
|
||||
// TODO do we really need to cancel the intent and alarm?
|
||||
mAlarmController.cancelAlarm(getRingingObject(), false);
|
||||
mAlarmController.cancelAlarm(getRingingObject(), false, true);
|
||||
stopAndFinish();
|
||||
}
|
||||
|
||||
|
||||
@ -29,7 +29,7 @@ public class AlarmRingtoneService extends RingtoneService<Alarm> {
|
||||
if (ACTION_SNOOZE.equals(intent.getAction())) {
|
||||
mAlarmController.snoozeAlarm(getRingingObject());
|
||||
} else if (ACTION_DISMISS.equals(intent.getAction())) {
|
||||
mAlarmController.cancelAlarm(getRingingObject(), false); // TODO do we really need to cancel the intent and alarm?
|
||||
mAlarmController.cancelAlarm(getRingingObject(), false, true); // TODO do we really need to cancel the intent and alarm?
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@ -49,7 +49,7 @@ public class AlarmRingtoneService extends RingtoneService<Alarm> {
|
||||
@Override
|
||||
protected void onAutoSilenced() {
|
||||
// TODO do we really need to cancel the alarm and intent?
|
||||
mAlarmController.cancelAlarm(getRingingObject(), false);
|
||||
mAlarmController.cancelAlarm(getRingingObject(), false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
Reference in New Issue
Block a user