Fix notification restore

pull/574/head
Alex Baker 8 years ago
parent 328a7603fa
commit 21dab947f3

@ -16,7 +16,6 @@ import com.todoroo.astrid.voice.VoiceOutputAssistant;
import org.tasks.injection.ForApplication; import org.tasks.injection.ForApplication;
import org.tasks.jobs.JobQueueEntry; import org.tasks.jobs.JobQueueEntry;
import org.tasks.notifications.AudioManager; import org.tasks.notifications.AudioManager;
import org.tasks.notifications.NotificationDao;
import org.tasks.notifications.NotificationManager; import org.tasks.notifications.NotificationManager;
import org.tasks.notifications.TelephonyManager; import org.tasks.notifications.TelephonyManager;
import org.tasks.preferences.Preferences; import org.tasks.preferences.Preferences;
@ -44,14 +43,13 @@ public class Notifier {
private final AudioManager audioManager; private final AudioManager audioManager;
private final VoiceOutputAssistant voiceOutputAssistant; private final VoiceOutputAssistant voiceOutputAssistant;
private final Preferences preferences; private final Preferences preferences;
private final NotificationDao notificationDao;
private final CheckBoxes checkBoxes; private final CheckBoxes checkBoxes;
@Inject @Inject
public Notifier(@ForApplication Context context, TaskDao taskDao, public Notifier(@ForApplication Context context, TaskDao taskDao,
NotificationManager notificationManager, TelephonyManager telephonyManager, NotificationManager notificationManager, TelephonyManager telephonyManager,
AudioManager audioManager, VoiceOutputAssistant voiceOutputAssistant, AudioManager audioManager, VoiceOutputAssistant voiceOutputAssistant,
Preferences preferences, NotificationDao notificationDao, CheckBoxes checkBoxes) { Preferences preferences, CheckBoxes checkBoxes) {
this.context = context; this.context = context;
this.taskDao = taskDao; this.taskDao = taskDao;
this.notificationManager = notificationManager; this.notificationManager = notificationManager;
@ -59,7 +57,6 @@ public class Notifier {
this.audioManager = audioManager; this.audioManager = audioManager;
this.voiceOutputAssistant = voiceOutputAssistant; this.voiceOutputAssistant = voiceOutputAssistant;
this.preferences = preferences; this.preferences = preferences;
this.notificationDao = notificationDao;
this.checkBoxes = checkBoxes; this.checkBoxes = checkBoxes;
} }
@ -115,10 +112,6 @@ public class Notifier {
triggerNotifications(Collections.singletonList(notification), true); triggerNotifications(Collections.singletonList(notification), true);
} }
public void restoreNotifications() {
triggerNotifications(notificationDao.getAll(), false);
}
public void triggerTaskNotifications(List<? extends JobQueueEntry> entries) { public void triggerTaskNotifications(List<? extends JobQueueEntry> entries) {
triggerNotifications(transform(entries, JobQueueEntry::toNotification), true); triggerNotifications(transform(entries, JobQueueEntry::toNotification), true);
} }

@ -131,6 +131,15 @@ public class NotificationManager {
.subscribe(); .subscribe();
} }
public void restoreNotifications() {
List<org.tasks.notifications.Notification> notifications = notificationDao.getAllOrdered();
for (org.tasks.notifications.Notification notification : notifications) {
notificationManagerCompat.cancel(notification.taskId.intValue());
}
notificationManagerCompat.cancel(SUMMARY_NOTIFICATION_ID);
notifyTasks(notifications, false, false, false);
}
public void notifyTasks(List<org.tasks.notifications.Notification> newNotifications, boolean alert, boolean nonstop, boolean fiveTimes) { public void notifyTasks(List<org.tasks.notifications.Notification> newNotifications, boolean alert, boolean nonstop, boolean fiveTimes) {
notificationDao.insertAll(newNotifications); notificationDao.insertAll(newNotifications);
List<org.tasks.notifications.Notification> notifications = notificationDao.getAllOrdered(); List<org.tasks.notifications.Notification> notifications = notificationDao.getAllOrdered();
@ -173,11 +182,12 @@ public class NotificationManager {
for (org.tasks.notifications.Notification notification : newNotifications) { for (org.tasks.notifications.Notification notification : newNotifications) {
NotificationCompat.Builder builder = getTaskNotification(notification); NotificationCompat.Builder builder = getTaskNotification(notification);
if (builder != null) { if (builder != null) {
builder.setGroup(GROUP_KEY)
.setGroupAlertBehavior(alert ? NotificationCompat.GROUP_ALERT_CHILDREN : NotificationCompat.GROUP_ALERT_SUMMARY);
notify(notification.taskId, builder, alert, nonstop, fiveTimes); notify(notification.taskId, builder, alert, nonstop, fiveTimes);
alert = false; alert = false;
} }
} }
notificationManagerCompat.cancel(SUMMARY_NOTIFICATION_ID);
} }
} }

@ -8,11 +8,11 @@ import com.todoroo.astrid.alarms.AlarmService;
import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.reminders.ReminderService; import com.todoroo.astrid.reminders.ReminderService;
import org.tasks.Notifier;
import org.tasks.injection.InjectingJobIntentService; import org.tasks.injection.InjectingJobIntentService;
import org.tasks.injection.IntentServiceComponent; import org.tasks.injection.IntentServiceComponent;
import org.tasks.jobs.JobManager; import org.tasks.jobs.JobManager;
import org.tasks.jobs.JobQueue; import org.tasks.jobs.JobQueue;
import org.tasks.notifications.NotificationManager;
import javax.inject.Inject; import javax.inject.Inject;
@ -28,7 +28,7 @@ public class NotificationSchedulerIntentService extends InjectingJobIntentServic
@Inject ReminderService reminderService; @Inject ReminderService reminderService;
@Inject TaskDao taskDao; @Inject TaskDao taskDao;
@Inject JobQueue jobQueue; @Inject JobQueue jobQueue;
@Inject Notifier notifier; @Inject NotificationManager notificationManager;
@Override @Override
protected void onHandleWork(Intent intent) { protected void onHandleWork(Intent intent) {
@ -38,7 +38,7 @@ public class NotificationSchedulerIntentService extends InjectingJobIntentServic
jobQueue.clear(); jobQueue.clear();
notifier.restoreNotifications(); notificationManager.restoreNotifications();
reminderService.scheduleAllAlarms(taskDao); reminderService.scheduleAllAlarms(taskDao);
alarmService.scheduleAllAlarms(); alarmService.scheduleAllAlarms();
} }

Loading…
Cancel
Save