Remove all notifications when summary is cleared

pull/574/head
Alex Baker 7 years ago
parent 74e1f31acb
commit 1d9780e4d8

@ -5,9 +5,9 @@
*/
package com.todoroo.astrid.reminders;
import android.app.Notification;
import android.content.Context;
import android.support.test.runner.AndroidJUnit4;
import android.support.v4.app.NotificationCompat;
import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.dao.TaskDao;
@ -93,7 +93,7 @@ public class NotificationTests extends DatabaseTestCase {
notifier.triggerTaskNotification(task.getId(), ReminderService.TYPE_DUE);
verify(notificationManager).notify(eq((int) task.getId()), any(Notification.class), true, false, false);
verify(notificationManager).notify(eq((int) task.getId()), any(NotificationCompat.Builder.class), true, false, false);
}
@Test

@ -24,6 +24,9 @@ public interface NotificationDao {
@Query("DELETE FROM notification WHERE task = :taskId")
int delete(long taskId);
@Query("DELETE FROM notification WHERE task IN(:taskIds)")
void deleteAll(List<Long> taskIds);
@Query("SELECT MAX(timestamp) FROM notification")
long latestTimestamp();
}

@ -45,9 +45,9 @@ import timber.log.Timber;
import static android.content.Intent.FLAG_ACTIVITY_MULTIPLE_TASK;
import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;
import static com.google.common.collect.Iterables.transform;
import static com.google.common.collect.Iterables.tryFind;
import static com.google.common.collect.Lists.newArrayList;
import static com.google.common.collect.Lists.transform;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastJellybean;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastOreo;
@ -103,7 +103,13 @@ public class NotificationManager {
public void cancel(long id) {
notificationManagerCompat.cancel((int) id);
Completable.fromAction(() -> {
if (notificationDao.delete(id) > 0) {
if (id == SUMMARY_NOTIFICATION_ID) {
List<Long> tasks = transform(notificationDao.getAll(), n -> n.taskId);
for (Long task : tasks) {
notificationManagerCompat.cancel(task.intValue());
}
notificationDao.deleteAll(tasks);
} else if (notificationDao.delete(id) > 0) {
if (notificationDao.count() == 1) {
List<org.tasks.notifications.Notification> notifications = notificationDao.getAll();
org.tasks.notifications.Notification notification = notifications.get(0);
@ -189,7 +195,7 @@ public class NotificationManager {
notificationManagerCompat.cancel(SUMMARY_NOTIFICATION_ID);
} else {
List<org.tasks.notifications.Notification> notifications = notificationDao.getAllOrdered();
Iterable<Long> notificationIds = transform(notifications, n -> n.taskId);
List<Long> notificationIds = transform(notifications, n -> n.taskId);
QueryTemplate query = new QueryTemplate().where(Task.ID.in(notificationIds));
Filter filter = new Filter(context.getString(R.string.notifications), query);
List<Task> tasks = taskDao.toList(Query.select(Task.PROPERTIES)

Loading…
Cancel
Save