Fixed bug where a missed, non-recurring alarm that superseded a previous alarm was not disabled after exiting AlarmActivity. Fixed bug where successive alarms would cancel missed alarm notifications for previous alarms.

This commit is contained in:
Phillip Hsu 2016-09-01 19:39:34 -07:00
parent 7b81bb467f
commit d7b3fc6ee1
3 changed files with 35 additions and 20 deletions

View File

@ -2,6 +2,7 @@ package com.philliphsu.clock2.alarms;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.view.ViewGroup;
@ -32,9 +33,25 @@ public class AlarmActivity extends RingtoneActivity<Alarm> {
@Override
public void finish() {
super.finish();
// If the presently ringing alarm is about to be superseded by a successive alarm,
// this, unfortunately, will cancel the missed alarm notification for the presently
// ringing alarm.
//
// A workaround is to override onNewIntent() and post the missed alarm notification again,
// AFTER calling through to its base implementation, because it calls finish().
mNotificationManager.cancel(TAG, getRingingObject().getIntId());
}
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
// -------------- TOneverDO: precede super ---------------
// Even though the base implementation calls finish() on this instance and starts a new
// instance, this instance will still be alive with all of its member state intact at
// this point. So this notification will still refer to the Alarm that was just missed.
postMissedAlarmNote();
}
@Override
protected Class<? extends RingtoneService> getRingtoneServiceClass() {
return AlarmRingtoneService.class;
@ -102,7 +119,10 @@ public class AlarmActivity extends RingtoneActivity<Alarm> {
@Override
protected void showAutoSilenced() {
super.showAutoSilenced();
// Post notification that alarm was missed
postMissedAlarmNote();
}
private void postMissedAlarmNote() {
String alarmTime = DateFormatUtils.formatTime(this,
getRingingObject().hour(), getRingingObject().minutes());
Notification note = new NotificationCompat.Builder(this)

View File

@ -1,6 +1,5 @@
package com.philliphsu.clock2.ringtone;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
@ -130,10 +129,6 @@ public abstract class RingtoneActivity<T extends Parcelable> extends AppCompatAc
@Override
protected void onNewIntent(Intent intent) {
//super.onNewIntent(intent); // Not needed since no fragments hosted?
// TODO: Do we need this anymore? I think the broadcast that calls through to
// this was only sent from EditAlarmActivity?
// Notifies alarm missed and stops the service
LocalBroadcastHelper.sendBroadcast(this, RingtoneService.ACTION_NOTIFY_MISSED);
finish();
@ -180,7 +175,6 @@ public abstract class RingtoneActivity<T extends Parcelable> extends AppCompatAc
@OnClick(R.id.ok)
public void finish() {
super.finish();
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
}
public static boolean isAlive() {

View File

@ -3,6 +3,8 @@ package com.philliphsu.clock2.ringtone;
import android.app.Notification;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.media.Ringtone;
@ -57,17 +59,16 @@ public abstract class RingtoneService<T extends Parcelable> extends Service {
}
};
// Pretty sure this won't ever get called anymore... b/c EditAlarmActivity, the only component
// that sends such a broadcast, is deprecated.
// private final BroadcastReceiver mNotifyMissedReceiver = new BroadcastReceiver() {
// @Override
// public void onReceive(Context context, Intent intent) {
// // TODO: Do we need to call mAlarmController.cancelAlarm()?
// onAutoSilenced();
// stopSelf();
// // Activity finishes itself
// }
// };
// // Pretty sure this won't ever get called anymore... b/c EditAlarmActivity, the only component
// // that sends such a broadcast, is deprecated.
private final BroadcastReceiver mNotifyMissedReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
onAutoSilenced();
stopSelf();
// Activity finishes itself
}
};
/**
* Callback invoked when this Service is stopping and the corresponding
@ -137,7 +138,7 @@ public abstract class RingtoneService<T extends Parcelable> extends Service {
super.onCreate();
// Pretty sure this won't ever get called anymore... b/c EditAlarmActivity, the only component
// that sends such a broadcast, is deprecated.
// LocalBroadcastHelper.registerReceiver(this, mNotifyMissedReceiver, ACTION_NOTIFY_MISSED);
LocalBroadcastHelper.registerReceiver(this, mNotifyMissedReceiver, ACTION_NOTIFY_MISSED);
}
@Override
@ -152,7 +153,7 @@ public abstract class RingtoneService<T extends Parcelable> extends Service {
stopForeground(true);
// Pretty sure this won't ever get called anymore... b/c EditAlarmActivity, the only component
// that sends such a broadcast, is deprecated.
// LocalBroadcastHelper.unregisterReceiver(this, mNotifyMissedReceiver);
LocalBroadcastHelper.unregisterReceiver(this, mNotifyMissedReceiver);
}
@Override