Skip to content

Commit

Permalink
Deleting an alarm now clears all notifications tied to it. Fixes an app
Browse files Browse the repository at this point in the history
crash.
  • Loading branch information
dllud committed Mar 25, 2015
1 parent fa01e2e commit 980561c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import mobi.boilr.boilr.R;
import mobi.boilr.boilr.activities.AlarmListActivity;
import mobi.boilr.boilr.utils.Log;
import mobi.boilr.boilr.utils.Notifications;
import mobi.boilr.boilr.widget.AlarmListAdapter;
import mobi.boilr.libpricealarm.Alarm;
import android.content.ClipData;
Expand Down Expand Up @@ -203,6 +204,7 @@ public boolean onTouch(final View view, MotionEvent event) {
b.putInt("filteredPos", mPointToPosition);
b.putInt("originalPos", adapter.originalIndexOf(alarm));
adapter.remove(alarm);
Notifications.clearNotification(mActivity, alarm);
mUndoBar.clear();
mUndoBar.message(R.string.alarm_deleted).token(b).show();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ public void deleteAlarm(int alarmID) {
}

public void deleteAlarm(Alarm alarm) {
Notifications.clearNotification(this, alarm);
removeFromAlarmManager(alarm.getId());
db.deleteAlarm(alarm);
alarmsMap.remove(alarm.getId());
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/mobi/boilr/boilr/utils/Notifications.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private static void statusBarNotifAux(Context context, Alarm alarm, String firin
.addNextIntentWithParentStack(alarmSettingsIntent)
.getPendingIntent(alarm.getId(), PendingIntent.FLAG_UPDATE_CURRENT);
} else {
pendingIntent = PendingIntent.getActivity(context, alarm.getId(), alarmSettingsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntent = PendingIntent.getActivity(context, alarm.hashCode(), alarmSettingsIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}
notification.setContentIntent(pendingIntent);
//notification.setPriority(Notification.PRIORITY_DEFAULT); API 16 only
Expand Down Expand Up @@ -205,10 +205,10 @@ private static String getFiringReasonBody(Context context, Alarm alarm) {
return "Could not retrieve firing reason.";
}

public static void clearNotification(Context context, int alarmID) {
public static void clearNotification(Context context, Alarm alarm) {
// Log.d("Clearing notifications for alarm instance: " + alarmID);
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nm.cancel(alarmID);
nm.cancel(alarm.hashCode());
}

public static void clearNoInternetNotification(Context context) {
Expand Down

0 comments on commit 980561c

Please sign in to comment.