mirror of https://github.com/tasks/tasks
Remove StartupService
parent
54b5cd31c9
commit
2fbc356e84
@ -1,52 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2012 Todoroo Inc
|
|
||||||
*
|
|
||||||
* See the file "LICENSE" for the full license governing this code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.todoroo.astrid.service;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import dagger.Lazy;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import org.tasks.BuildConfig;
|
|
||||||
import org.tasks.analytics.Tracker;
|
|
||||||
import org.tasks.injection.ForApplication;
|
|
||||||
import org.tasks.preferences.Preferences;
|
|
||||||
import org.tasks.scheduling.BackgroundScheduler;
|
|
||||||
import timber.log.Timber;
|
|
||||||
|
|
||||||
public class StartupService {
|
|
||||||
|
|
||||||
private final Preferences preferences;
|
|
||||||
private final Context context;
|
|
||||||
private final Lazy<Upgrader> upgrader;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
public StartupService(
|
|
||||||
Preferences preferences,
|
|
||||||
Tracker tracker,
|
|
||||||
@ForApplication Context context,
|
|
||||||
Lazy<Upgrader> upgrader) {
|
|
||||||
this.preferences = preferences;
|
|
||||||
this.context = context;
|
|
||||||
this.upgrader = upgrader;
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Called when this application is started up */
|
|
||||||
public synchronized void onStartupApplication() {
|
|
||||||
// read current version
|
|
||||||
final int lastVersion = preferences.getLastSetVersion();
|
|
||||||
final int currentVersion = BuildConfig.VERSION_CODE;
|
|
||||||
|
|
||||||
Timber.i("Astrid Startup. %s => %s", lastVersion, currentVersion);
|
|
||||||
|
|
||||||
// invoke upgrade service
|
|
||||||
if (lastVersion != currentVersion) {
|
|
||||||
upgrader.get().upgrade(lastVersion, currentVersion);
|
|
||||||
preferences.setDefaults();
|
|
||||||
}
|
|
||||||
|
|
||||||
BackgroundScheduler.enqueueWork(context);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
package org.tasks.scheduling;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import com.todoroo.astrid.dao.TaskDao;
|
|
||||||
import com.todoroo.astrid.data.Task;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import org.tasks.files.FileHelper;
|
|
||||||
import org.tasks.injection.ForApplication;
|
|
||||||
import org.tasks.injection.InjectingJobIntentService;
|
|
||||||
import org.tasks.injection.ServiceComponent;
|
|
||||||
import org.tasks.jobs.WorkManager;
|
|
||||||
import org.tasks.preferences.Preferences;
|
|
||||||
import timber.log.Timber;
|
|
||||||
|
|
||||||
public class BackgroundScheduler extends InjectingJobIntentService {
|
|
||||||
|
|
||||||
@Inject @ForApplication Context context;
|
|
||||||
@Inject TaskDao taskDao;
|
|
||||||
@Inject WorkManager jobManager;
|
|
||||||
@Inject RefreshScheduler refreshScheduler;
|
|
||||||
@Inject Preferences preferences;
|
|
||||||
|
|
||||||
public static void enqueueWork(Context context) {
|
|
||||||
BackgroundScheduler.enqueueWork(
|
|
||||||
context,
|
|
||||||
BackgroundScheduler.class,
|
|
||||||
InjectingJobIntentService.JOB_ID_BACKGROUND_SCHEDULER,
|
|
||||||
new Intent(context, BackgroundScheduler.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doWork(@NonNull Intent intent) {
|
|
||||||
Timber.d("onHandleWork(%s)", intent);
|
|
||||||
|
|
||||||
NotificationSchedulerIntentService.enqueueWork(context, false);
|
|
||||||
CalendarNotificationIntentService.enqueueWork(context);
|
|
||||||
GeofenceSchedulingIntentService.enqueueWork(context);
|
|
||||||
|
|
||||||
for (Task task : taskDao.needsRefresh()) {
|
|
||||||
refreshScheduler.scheduleRefresh(task);
|
|
||||||
}
|
|
||||||
|
|
||||||
FileHelper.delete(context, preferences.getCacheDirectory());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void inject(ServiceComponent component) {
|
|
||||||
component.inject(this);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,36 +0,0 @@
|
|||||||
package org.tasks.scheduling;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import androidx.core.app.JobIntentService;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import org.tasks.injection.InjectingJobIntentService;
|
|
||||||
import org.tasks.injection.ServiceComponent;
|
|
||||||
import org.tasks.location.GeofenceService;
|
|
||||||
import timber.log.Timber;
|
|
||||||
|
|
||||||
public class GeofenceSchedulingIntentService extends InjectingJobIntentService {
|
|
||||||
|
|
||||||
@Inject GeofenceService geofenceService;
|
|
||||||
|
|
||||||
public static void enqueueWork(Context context) {
|
|
||||||
JobIntentService.enqueueWork(
|
|
||||||
context,
|
|
||||||
GeofenceSchedulingIntentService.class,
|
|
||||||
InjectingJobIntentService.JOB_ID_GEOFENCE_SCHEDULING,
|
|
||||||
new Intent(context, GeofenceSchedulingIntentService.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doWork(Intent intent) {
|
|
||||||
Timber.d("onHandleWork(%s)", intent);
|
|
||||||
|
|
||||||
geofenceService.cancelGeofences();
|
|
||||||
geofenceService.setupGeofences();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void inject(ServiceComponent component) {
|
|
||||||
component.inject(this);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue