Remove WorkManager.init

pull/935/head
Alex Baker 5 years ago
parent c55c1e6333
commit 2de130f9f1

@ -28,20 +28,12 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.injection.InjectingTestCase;
import org.tasks.injection.TestComponent;
import org.tasks.jobs.WorkManager;
@RunWith(AndroidJUnit4.class)
public class TaskDaoTests extends InjectingTestCase {
@Inject TaskDao taskDao;
@Inject TaskDeleter taskDeleter;
@Inject WorkManager workManager;
@Override
public void setUp() {
super.setUp();
workManager.init();
}
/** Test basic task creation, fetch, and save */
@Test

@ -23,7 +23,6 @@ import org.tasks.data.GoogleTaskList;
import org.tasks.data.GoogleTaskListDao;
import org.tasks.injection.InjectingTestCase;
import org.tasks.injection.TestComponent;
import org.tasks.jobs.WorkManager;
import org.tasks.makers.RemoteGtaskListMaker;
@RunWith(AndroidJUnit4.class)
@ -31,7 +30,6 @@ public class GtasksListServiceTest extends InjectingTestCase {
@Inject TaskDeleter taskDeleter;
@Inject LocalBroadcastManager localBroadcastManager;
@Inject WorkManager workManager;
@Inject GoogleTaskListDao googleTaskListDao;
private GtasksListService gtasksListService;
@ -39,7 +37,6 @@ public class GtasksListServiceTest extends InjectingTestCase {
@Override
public void setUp() {
super.setUp();
workManager.init();
gtasksListService =
new GtasksListService(googleTaskListDao, taskDeleter, localBroadcastManager);
}

@ -39,7 +39,6 @@ import org.tasks.injection.InjectingTestCase;
import org.tasks.injection.TestComponent;
import org.tasks.jobs.NotificationQueue;
import org.tasks.jobs.ReminderEntry;
import org.tasks.jobs.WorkManager;
import org.tasks.preferences.Preferences;
import org.tasks.reminders.Random;
import org.tasks.time.DateTime;
@ -49,7 +48,6 @@ public class ReminderServiceTest extends InjectingTestCase {
@Inject Preferences preferences;
@Inject TaskDao taskDao;
@Inject WorkManager workManager;
private ReminderService service;
private Random random;
@ -58,7 +56,6 @@ public class ReminderServiceTest extends InjectingTestCase {
@Override
public void setUp() {
super.setUp();
workManager.init();
jobs = mock(NotificationQueue.class);
random = mock(Random.class);
when(random.nextFloat()).thenReturn(1.0f);

@ -56,7 +56,6 @@ public class TaskMoverTest extends InjectingTestCase {
@Before
public void setUp() {
super.setUp();
workManager.init();
taskDao.initialize(workManager);
}

@ -27,7 +27,6 @@ import org.tasks.R;
import org.tasks.data.TagDataDao;
import org.tasks.injection.InjectingTestCase;
import org.tasks.injection.TestComponent;
import org.tasks.jobs.WorkManager;
import org.tasks.preferences.Preferences;
import org.tasks.time.DateTime;
@ -37,12 +36,10 @@ public class TitleParserTest extends InjectingTestCase {
@Inject TagDataDao tagDataDao;
@Inject Preferences preferences;
@Inject TaskCreator taskCreator;
@Inject WorkManager workManager;
@Override
public void setUp() {
super.setUp();
workManager.init();
preferences.setStringFromInteger(R.string.p_default_urgency_key, 0);
}

@ -236,6 +236,11 @@
<!-- ======================================================= Providers = -->
<provider
android:name="androidx.work.impl.WorkManagerInitializer"
android:authorities="${applicationId}.workmanager-init"
tools:node="remove" />
<provider
android:authorities="${applicationId};${applicationId}.tasksprovider"
android:exported="true"

@ -3,7 +3,10 @@ package org.tasks;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import androidx.annotation.NonNull;
import androidx.core.app.JobIntentService;
import androidx.work.Configuration;
import com.jakewharton.processphoenix.ProcessPhoenix;
import com.jakewharton.threetenabp.AndroidThreeTen;
import com.todoroo.astrid.service.Upgrader;
@ -28,18 +31,18 @@ import org.tasks.scheduling.RefreshScheduler;
import org.tasks.themes.ThemeBase;
import timber.log.Timber;
public class Tasks extends InjectingApplication {
public class Tasks extends InjectingApplication implements Configuration.Provider {
@Inject @ForApplication Context context;
@Inject Lazy<Upgrader> upgrader;
@Inject Preferences preferences;
@Inject BuildSetup buildSetup;
@Inject Inventory inventory;
@Inject WorkManager workManager;
@Inject RefreshScheduler refreshScheduler;
@Inject GeofenceApi geofenceApi;
@Inject LocalBroadcastManager localBroadcastManager;
@Inject BillingClient billingClient;
@Inject Lazy<Upgrader> upgrader;
@Inject Lazy<WorkManager> workManager;
@Inject Lazy<RefreshScheduler> refreshScheduler;
@Inject Lazy<GeofenceApi> geofenceApi;
@Inject Lazy<BillingClient> billingClient;
@Override
public void onCreate() {
@ -51,8 +54,6 @@ public class Tasks extends InjectingApplication {
upgrade();
workManager.init();
AndroidThreeTen.init(this);
preferences.setSyncOngoing(false);
@ -80,13 +81,13 @@ public class Tasks extends InjectingApplication {
private void doInBackground() {
NotificationSchedulerIntentService.enqueueWork(context, false);
CalendarNotificationIntentService.enqueueWork(context);
refreshScheduler.scheduleAll();
workManager.updateBackgroundSync();
workManager.scheduleMidnightRefresh();
workManager.scheduleBackup();
geofenceApi.registerAll();
refreshScheduler.get().scheduleAll();
workManager.get().updateBackgroundSync();
workManager.get().scheduleMidnightRefresh();
workManager.get().scheduleBackup();
geofenceApi.get().registerAll();
FileHelper.delete(context, preferences.getCacheDirectory());
billingClient.queryPurchases();
billingClient.get().queryPurchases();
}
@Override
@ -94,7 +95,15 @@ public class Tasks extends InjectingApplication {
component.inject(this);
}
private class RefreshBroadcastReceiver extends BroadcastReceiver {
@NonNull
@Override
public Configuration getWorkManagerConfiguration() {
return new Configuration.Builder()
.setMinimumLoggingLevel(BuildConfig.DEBUG ? Log.DEBUG : Log.INFO)
.build();
}
private static class RefreshBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
JobIntentService.enqueueWork(

@ -76,9 +76,6 @@ public class WorkManager {
this.googleTaskListDao = googleTaskListDao;
this.caldavDao = caldavDao;
alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
}
public void init() {
workManager = androidx.work.WorkManager.getInstance(context);
}
@ -104,9 +101,6 @@ public class WorkManager {
}
public void sync(boolean immediate) {
if (workManager == null) {
return;
}
Constraints constraints =
new Constraints.Builder()
.setRequiredNetworkType(

Loading…
Cancel
Save