Check for null on notifications

pull/69/head
Alinson S. Xavier 10 years ago
parent ef847dac17
commit 7778c5fb21

@ -91,10 +91,12 @@ public class HabitBroadcastReceiver extends BroadcastReceiver
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
long delayMinutes = Long.parseLong(prefs.getString("pref_snooze_interval", "15")); long delayMinutes = Long.parseLong(prefs.getString("pref_snooze_interval", "15"));
Habit habit = Habit.get(ContentUris.parseId(data)); long habitId = ContentUris.parseId(data);
ReminderHelper.createReminderAlarm(context, habit, Habit habit = Habit.get(habitId);
new Date().getTime() + delayMinutes * 60 * 1000); if(habit != null)
dismissNotification(context, habit); ReminderHelper.createReminderAlarm(context, habit,
new Date().getTime() + delayMinutes * 60 * 1000);
dismissNotification(context, habitId);
} }
private void checkHabit(Context context, Intent intent) private void checkHabit(Context context, Intent intent)
@ -102,10 +104,11 @@ public class HabitBroadcastReceiver extends BroadcastReceiver
Uri data = intent.getData(); Uri data = intent.getData();
Long timestamp = intent.getLongExtra("timestamp", DateHelper.getStartOfToday()); Long timestamp = intent.getLongExtra("timestamp", DateHelper.getStartOfToday());
Habit habit = Habit.get(ContentUris.parseId(data)); long habitId = ContentUris.parseId(data);
habit.repetitions.toggle(timestamp); Habit habit = Habit.get(habitId);
habit.save(); if(habit != null)
dismissNotification(context, habit); habit.repetitions.toggle(timestamp);
dismissNotification(context, habitId);
sendRefreshBroadcast(context); sendRefreshBroadcast(context);
} }
@ -128,12 +131,12 @@ public class HabitBroadcastReceiver extends BroadcastReceiver
} }
} }
private void dismissNotification(Context context, Habit habit) private void dismissNotification(Context context, Long habitId)
{ {
NotificationManager notificationManager = NotificationManager notificationManager =
(NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE); (NotificationManager) context.getSystemService(Activity.NOTIFICATION_SERVICE);
int notificationId = (int) (habit.getId() % Integer.MAX_VALUE); int notificationId = (int) (habitId % Integer.MAX_VALUE);
notificationManager.cancel(notificationId); notificationManager.cancel(notificationId);
} }
@ -145,6 +148,7 @@ public class HabitBroadcastReceiver extends BroadcastReceiver
Long timestamp = intent.getLongExtra("timestamp", DateHelper.getStartOfToday()); Long timestamp = intent.getLongExtra("timestamp", DateHelper.getStartOfToday());
Long reminderTime = intent.getLongExtra("reminderTime", DateHelper.getStartOfToday()); Long reminderTime = intent.getLongExtra("reminderTime", DateHelper.getStartOfToday());
if (habit == null) return;
if (habit.repetitions.hasImplicitRepToday()) return; if (habit.repetitions.hasImplicitRepToday()) return;
habit.highlight = 1; habit.highlight = 1;

Loading…
Cancel
Save