mirror of https://github.com/tasks/tasks
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.8 KiB
Java
52 lines
1.8 KiB
Java
package org.tasks.scheduling;
|
|
|
|
import android.content.Context;
|
|
import android.content.Intent;
|
|
import android.support.v4.app.JobIntentService;
|
|
import com.todoroo.astrid.alarms.AlarmService;
|
|
import com.todoroo.astrid.reminders.ReminderService;
|
|
import javax.inject.Inject;
|
|
import org.tasks.injection.InjectingJobIntentService;
|
|
import org.tasks.injection.IntentServiceComponent;
|
|
import org.tasks.jobs.JobManager;
|
|
import org.tasks.jobs.NotificationQueue;
|
|
import org.tasks.notifications.NotificationManager;
|
|
import timber.log.Timber;
|
|
|
|
public class NotificationSchedulerIntentService extends InjectingJobIntentService {
|
|
|
|
private static final String EXTRA_CANCEL_EXISTING_NOTIFICATIONS = "extra_cancel_existing_notifications";
|
|
@Inject AlarmService alarmService;
|
|
@Inject ReminderService reminderService;
|
|
@Inject NotificationQueue notificationQueue;
|
|
@Inject NotificationManager notificationManager;
|
|
|
|
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);
|
|
}
|
|
|
|
@Override
|
|
protected void onHandleWork(Intent intent) {
|
|
super.onHandleWork(intent);
|
|
|
|
Timber.d("onHandleWork(%s)", intent);
|
|
|
|
notificationQueue.clear();
|
|
|
|
boolean cancelExistingNotifications = intent
|
|
.getBooleanExtra(EXTRA_CANCEL_EXISTING_NOTIFICATIONS, false);
|
|
|
|
notificationManager.restoreNotifications(cancelExistingNotifications);
|
|
reminderService.scheduleAllAlarms();
|
|
alarmService.scheduleAllAlarms();
|
|
}
|
|
|
|
@Override
|
|
protected void inject(IntentServiceComponent component) {
|
|
component.inject(this);
|
|
}
|
|
}
|