Dont cancel notifications on application startup

pull/574/head
Alex Baker 7 years ago
parent af99bc45d2
commit 4542fb1046

@ -26,10 +26,8 @@ import org.tasks.preferences.ActivityPermissionRequestor;
import org.tasks.preferences.Device;
import org.tasks.preferences.PermissionChecker;
import org.tasks.preferences.PermissionRequestor;
import org.tasks.preferences.Preferences;
import org.tasks.scheduling.GeofenceSchedulingIntentService;
import org.tasks.scheduling.NotificationSchedulerIntentService;
import org.tasks.themes.ThemeCache;
import org.tasks.time.DateTime;
import org.tasks.ui.TimePreference;
@ -50,8 +48,6 @@ public class ReminderPreferences extends InjectingPreferenceActivity {
@Inject Device device;
@Inject ActivityPermissionRequestor permissionRequestor;
@Inject PermissionChecker permissionChecker;
@Inject Preferences preferences;
@Inject ThemeCache themeCache;
private CheckBoxPreference fieldMissedCalls;
@ -66,8 +62,7 @@ public class ReminderPreferences extends InjectingPreferenceActivity {
R.string.p_rmd_enable_quiet,
R.string.p_rmd_quietStart,
R.string.p_rmd_quietEnd,
R.string.p_rmd_persistent,
R.string.p_bundle_notifications);
R.string.p_rmd_persistent);
resetGeofencesOnChange(
R.string.p_geofence_radius,
R.string.p_geofence_responsiveness);
@ -84,6 +79,11 @@ public class ReminderPreferences extends InjectingPreferenceActivity {
findPreference(R.string.notification_channel_settings).setOnPreferenceClickListener(this::openNotificationChannelSettings);
findPreference(R.string.battery_optimization_settings).setOnPreferenceClickListener(this::openBatteryOptimizationSettings);
findPreference(R.string.p_bundle_notifications).setOnPreferenceChangeListener((preference, o) -> {
NotificationSchedulerIntentService.enqueueWork(this, true);
return true;
});
requires(device.supportsLocationServices(), R.string.geolocation_reminders);
requires(atLeastOreo(), R.string.notification_channel_settings);
requires(atLeastMarshmallow(), R.string.battery_optimization_settings);
@ -110,7 +110,7 @@ public class ReminderPreferences extends InjectingPreferenceActivity {
private void rescheduleNotificationsOnChange(int... resIds) {
for (int resId : resIds) {
findPreference(getString(resId)).setOnPreferenceChangeListener((preference, newValue) -> {
NotificationSchedulerIntentService.enqueueWork(this);
NotificationSchedulerIntentService.enqueueWork(this, false);
return true;
});
}

@ -135,19 +135,21 @@ public class NotificationManager {
.subscribe();
}
public void restoreNotifications() {
public void restoreNotifications(boolean cancelExisting) {
List<org.tasks.notifications.Notification> notifications = notificationDao.getAllOrdered();
for (org.tasks.notifications.Notification notification : notifications) {
notificationManagerCompat.cancel(notification.taskId.intValue());
if (cancelExisting) {
for (org.tasks.notifications.Notification notification : notifications) {
notificationManagerCompat.cancel(notification.taskId.intValue());
}
}
if (preferences.bundleNotifications() && notifications.size() > 1) {
updateSummary(false, false, false, Collections.emptyList());
createNotifications(notifications, false, false, false, true);
} else {
createNotifications(notifications, false, false, false, false);
notificationManagerCompat.cancel(SUMMARY_NOTIFICATION_ID);
}
createNotifications(notifications, false, false, false, true);
}
public void notifyTasks(List<org.tasks.notifications.Notification> newNotifications, boolean alert, boolean nonstop, boolean fiveTimes) {
@ -183,6 +185,7 @@ public class NotificationManager {
for (org.tasks.notifications.Notification notification : notifications) {
NotificationCompat.Builder builder = getTaskNotification(notification);
if (builder == null) {
notificationManagerCompat.cancel(notification.taskId.intValue());
notificationDao.delete(notification.taskId);
} else {
builder.setGroup(useGroupKey ? GROUP_KEY : notification.taskId.toString())
@ -267,7 +270,6 @@ public class NotificationManager {
.setGroupSummary(true)
.setGroup(GROUP_KEY)
.setTicker(Joiner.on(", ").join(ticker))
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setGroupAlertBehavior(notify ? NotificationCompat.GROUP_ALERT_SUMMARY : NotificationCompat.GROUP_ALERT_CHILDREN);
Intent snoozeIntent = new Intent(context, SnoozeActivity.class);

@ -36,7 +36,7 @@ public class BackgroundScheduler extends InjectingJobIntentService {
Timber.d("onHandleWork(%s)", intent);
NotificationSchedulerIntentService.enqueueWork(context);
NotificationSchedulerIntentService.enqueueWork(context, false);
CalendarNotificationIntentService.enqueueWork(context);
GeofenceSchedulingIntentService.enqueueWork(context);

@ -20,8 +20,12 @@ import timber.log.Timber;
public class NotificationSchedulerIntentService extends InjectingJobIntentService {
public static void enqueueWork(Context context) {
JobIntentService.enqueueWork(context, NotificationSchedulerIntentService.class, JobManager.JOB_ID_NOTIFICATION_SCHEDULER, new Intent());
public static final String EXTRA_CANCEL_EXISTING_NOTIFICATIONS = "extra_cancel_existing_notifications";
public static void enqueueWork(Context context, boolean cancelNotifications) {
Intent intent = new Intent();
intent.putExtra(EXTRA_CANCEL_EXISTING_NOTIFICATIONS, cancelNotifications);
JobIntentService.enqueueWork(context, NotificationSchedulerIntentService.class, JobManager.JOB_ID_NOTIFICATION_SCHEDULER, intent);
}
@Inject AlarmService alarmService;
@ -38,7 +42,9 @@ public class NotificationSchedulerIntentService extends InjectingJobIntentServic
jobQueue.clear();
notificationManager.restoreNotifications();
boolean cancelExistingNotifications = intent.getBooleanExtra(EXTRA_CANCEL_EXISTING_NOTIFICATIONS, false);
notificationManager.restoreNotifications(cancelExistingNotifications);
reminderService.scheduleAllAlarms(taskDao);
alarmService.scheduleAllAlarms();
}

Loading…
Cancel
Save