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);
|
nm.cancel(TAG, (int) id);
|
||||||
} else {
|
} else {
|
||||||
if (ACTION_DISMISS_NOW.equals(intent.getAction())) {
|
if (ACTION_DISMISS_NOW.equals(intent.getAction())) {
|
||||||
new AlarmController(context, null).cancelAlarm(alarm, false);
|
new AlarmController(context, null).cancelAlarm(alarm, false, true);
|
||||||
} else {
|
} else {
|
||||||
// Prepare notification
|
// Prepare notification
|
||||||
// http://stackoverflow.com/a/15803726/5055032
|
// http://stackoverflow.com/a/15803726/5055032
|
||||||
|
|||||||
@ -39,7 +39,7 @@ public final class AsyncAlarmsTableUpdateHandler extends AsyncDatabaseTableUpdat
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostAsyncDelete(Integer result, final Alarm alarm) {
|
protected void onPostAsyncDelete(Integer result, final Alarm alarm) {
|
||||||
mAlarmController.cancelAlarm(alarm, false);
|
mAlarmController.cancelAlarm(alarm, false, false);
|
||||||
if (mSnackbarAnchor != null) {
|
if (mSnackbarAnchor != null) {
|
||||||
// TODO: Consider adding delay to allow the alarm item animation
|
// TODO: Consider adding delay to allow the alarm item animation
|
||||||
// to finish first before we show the snackbar. Inbox app does this.
|
// 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.
|
* 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.
|
// TODO: Consider doing this in a new thread.
|
||||||
Log.d(TAG, "Cancelling alarm " + alarm);
|
Log.d(TAG, "Cancelling alarm " + alarm);
|
||||||
AlarmManager am = (AlarmManager) mAppContext.getSystemService(Context.ALARM_SERVICE);
|
AlarmManager am = (AlarmManager) mAppContext.getSystemService(Context.ALARM_SERVICE);
|
||||||
@ -130,7 +133,7 @@ public final class AlarmController {
|
|||||||
|
|
||||||
if (!alarm.hasRecurrence()) {
|
if (!alarm.hasRecurrence()) {
|
||||||
alarm.setEnabled(false);
|
alarm.setEnabled(false);
|
||||||
} else if (alarm.isEnabled()) {
|
} else if (alarm.isEnabled() && rescheduleIfRecurring) {
|
||||||
if (alarm.ringsWithinHours(hoursToNotifyInAdvance)) {
|
if (alarm.ringsWithinHours(hoursToNotifyInAdvance)) {
|
||||||
// Still upcoming today, so wait until the normal ring time
|
// Still upcoming today, so wait until the normal ring time
|
||||||
// passes before rescheduling the alarm.
|
// passes before rescheduling the alarm.
|
||||||
|
|||||||
@ -157,7 +157,7 @@ public abstract class BaseAlarmViewHolder extends BaseViewHolder<Alarm> {
|
|||||||
} else {
|
} else {
|
||||||
// Dismisses the current upcoming alarm and handles scheduling the next alarm for us.
|
// 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.
|
// 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
|
// 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
|
// TODO: On 21+, upcoming notification doesn't post immediately
|
||||||
persistUpdatedAlarm(alarm, true);
|
persistUpdatedAlarm(alarm, true);
|
||||||
} else {
|
} else {
|
||||||
mAlarmController.cancelAlarm(alarm, true);
|
mAlarmController.cancelAlarm(alarm, true, false);
|
||||||
// cancelAlarm() already calls save() for you.
|
// cancelAlarm() already calls save() for you.
|
||||||
}
|
}
|
||||||
mSwitch.setPressed(false); // clear the pressed focus, esp. if setPressed(true) was called manually
|
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
|
@Override
|
||||||
protected void onRightButtonClick() {
|
protected void onRightButtonClick() {
|
||||||
// TODO do we really need to cancel the intent and alarm?
|
// TODO do we really need to cancel the intent and alarm?
|
||||||
mAlarmController.cancelAlarm(getRingingObject(), false);
|
mAlarmController.cancelAlarm(getRingingObject(), false, true);
|
||||||
stopAndFinish();
|
stopAndFinish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,7 @@ public class AlarmRingtoneService extends RingtoneService<Alarm> {
|
|||||||
if (ACTION_SNOOZE.equals(intent.getAction())) {
|
if (ACTION_SNOOZE.equals(intent.getAction())) {
|
||||||
mAlarmController.snoozeAlarm(getRingingObject());
|
mAlarmController.snoozeAlarm(getRingingObject());
|
||||||
} else if (ACTION_DISMISS.equals(intent.getAction())) {
|
} 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 {
|
} else {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ public class AlarmRingtoneService extends RingtoneService<Alarm> {
|
|||||||
@Override
|
@Override
|
||||||
protected void onAutoSilenced() {
|
protected void onAutoSilenced() {
|
||||||
// TODO do we really need to cancel the alarm and intent?
|
// TODO do we really need to cancel the alarm and intent?
|
||||||
mAlarmController.cancelAlarm(getRingingObject(), false);
|
mAlarmController.cancelAlarm(getRingingObject(), false, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user