From 28eb615b0ed2076d1d09f3f5e53e9e0e8fc07337 Mon Sep 17 00:00:00 2001 From: Alinson Xavier Date: Sun, 17 Jul 2016 08:43:14 -0400 Subject: [PATCH] Notification: add checkmark instead of toggling --- .../uhabits/HabitBroadcastReceiver.java | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/org/isoron/uhabits/HabitBroadcastReceiver.java b/app/src/main/java/org/isoron/uhabits/HabitBroadcastReceiver.java index c76c3b44a..57cb6211b 100644 --- a/app/src/main/java/org/isoron/uhabits/HabitBroadcastReceiver.java +++ b/app/src/main/java/org/isoron/uhabits/HabitBroadcastReceiver.java @@ -38,7 +38,7 @@ import javax.inject.*; /** * The Android BroadcastReceiver for Loop Habit Tracker. - *

+ *

* All broadcast messages are received and processed by this class. */ public class HabitBroadcastReceiver extends BroadcastReceiver @@ -66,16 +66,6 @@ public class HabitBroadcastReceiver extends BroadcastReceiver HabitsApplication.getComponent().inject(this); } - public static void dismissNotification(Context context, Habit habit) - { - NotificationManager notificationManager = - (NotificationManager) context.getSystemService( - Activity.NOTIFICATION_SERVICE); - - int notificationId = (int) (habit.getId() % Integer.MAX_VALUE); - notificationManager.cancel(notificationId); - } - @Override public void onReceive(final Context context, Intent intent) { @@ -87,7 +77,7 @@ public class HabitBroadcastReceiver extends BroadcastReceiver break; case ACTION_DISMISS: - dismissAllHabits(); + // NOP break; case ACTION_CHECK: @@ -112,14 +102,21 @@ public class HabitBroadcastReceiver extends BroadcastReceiver long habitId = ContentUris.parseId(data); Habit habit = habits.getById(habitId); - if (habit != null) + try { + if (habit == null) return; + + Repetition rep = habit.getRepetitions().getByTimestamp(timestamp); + if (rep != null) return; + ToggleRepetitionCommand command = new ToggleRepetitionCommand(habit, timestamp); commandRunner.execute(command, habitId); } - - dismissNotification(context, habitId); + finally + { + dismissNotification(context, habitId); + } } private boolean checkWeekday(Intent intent, Habit habit) @@ -226,11 +223,6 @@ public class HabitBroadcastReceiver extends BroadcastReceiver () -> ReminderUtils.createReminderAlarms(context, habits), 5000); } - private void dismissAllHabits() - { - - } - private void dismissNotification(Context context, Long habitId) { NotificationManager notificationManager =