Update to work manager alpha 10

pull/757/head
Alex Baker 6 years ago
parent 3ebb98a7f5
commit 45430d7532

@ -112,7 +112,7 @@ final SUPPORT_VERSION = '28.0.0'
final ROOM_VERSION = '1.1.1'
final STETHO_VERSION = '1.5.0'
final TESTING_SUPPORT_VERSION = '1.0.0'
final WORK_VERSION = '1.0.0-alpha06'
final WORK_VERSION = '1.0.0-alpha10'
final LEAKCANARY_VERSION = '1.6.1'
dependencies {
@ -169,9 +169,15 @@ dependencies {
implementation 'com.google.apis:google-api-services-tasks:v1-rev52-1.23.0'
implementation 'com.google.api-client:google-api-client-android:1.23.0'
implementation 'com.android.billingclient:billing:1.1'
implementation "android.arch.work:work-runtime:${WORK_VERSION}"
implementation("android.arch.work:work-runtime:${WORK_VERSION}") {
// https://groups.google.com/forum/#!topic/guava-announce/Km82fZG68Sw
exclude group: 'com.google.guava', module: 'listenablefuture'
}
googleplayImplementation "android.arch.work:work-firebase:${WORK_VERSION}"
googleplayImplementation("android.arch.work:work-firebase:${WORK_VERSION}") {
// https://groups.google.com/forum/#!topic/guava-announce/Km82fZG68Sw
exclude group: 'com.google.guava', module: 'listenablefuture'
}
googleplayImplementation 'com.crashlytics.sdk.android:crashlytics:2.9.5'
googleplayImplementation "com.google.firebase:firebase-core:16.0.4"
googleplayImplementation "com.google.android.gms:play-services-location:16.0.0"

@ -10,7 +10,6 @@ import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import android.support.test.runner.AndroidJUnit4;
import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.Task;
import java.io.File;
@ -21,6 +20,7 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.tasks.R;
import org.tasks.backup.TasksJsonExporter;
import org.tasks.backup.TasksJsonExporter.ExportType;
import org.tasks.injection.InjectingTestCase;
import org.tasks.injection.TestComponent;
import org.tasks.preferences.Preferences;
@ -28,7 +28,6 @@ import org.tasks.preferences.Preferences;
@RunWith(AndroidJUnit4.class)
public class BackupServiceTests extends InjectingTestCase {
private static final long BACKUP_WAIT_TIME = 500L;
@Inject TasksJsonExporter jsonExporter;
@Inject TaskDao taskDao;
@Inject Preferences preferences;
@ -80,11 +79,7 @@ public class BackupServiceTests extends InjectingTestCase {
public void testBackup() {
assertEquals(0, temporaryDirectory.list().length);
// create a backup
BackupWork service = new BackupWork(getTargetContext(), jsonExporter, preferences);
service.startBackup(getTargetContext());
AndroidUtilities.sleepDeep(BACKUP_WAIT_TIME);
jsonExporter.exportTasks(getTargetContext(), ExportType.EXPORT_TYPE_SERVICE, null);
// assert file created
File[] files = temporaryDirectory.listFiles();

@ -118,36 +118,39 @@ public class TasksJsonExporter {
this.latestSetVersionName = null;
this.progressDialog = progressDialog;
handler = exportType == ExportType.EXPORT_TYPE_MANUAL ? new Handler() : null;
if (exportType == ExportType.EXPORT_TYPE_MANUAL) {
handler = new Handler();
new Thread(() -> runBackup(exportType)).start();
} else {
runBackup(exportType);
}
}
new Thread(
() -> {
try {
String output = setupFile(backupDirectory, exportType);
private void runBackup(ExportType exportType) {
try {
String output = setupFile(backupDirectory, exportType);
List<Task> tasks = taskDao.getAll();
List<Task> tasks = taskDao.getAll();
if (tasks.size() > 0) {
doTasksExport(output, tasks);
}
if (tasks.size() > 0) {
doTasksExport(output, tasks);
}
if (exportType == ExportType.EXPORT_TYPE_MANUAL) {
onFinishExport(output);
}
} catch (IOException e) {
Timber.e(e);
} finally {
post(
() -> {
if (progressDialog != null
&& progressDialog.isShowing()
&& context instanceof Activity) {
DialogUtilities.dismissDialog((Activity) context, progressDialog);
}
});
}
})
.start();
if (exportType == ExportType.EXPORT_TYPE_MANUAL) {
onFinishExport(output);
}
} catch (IOException e) {
Timber.e(e);
} finally {
post(
() -> {
if (progressDialog != null
&& progressDialog.isShowing()
&& context instanceof Activity) {
DialogUtilities.dismissDialog((Activity) context, progressDialog);
}
});
}
}
private void doTasksExport(String output, List<Task> tasks) throws IOException {

@ -1,7 +1,9 @@
package org.tasks.injection;
import android.content.Context;
import android.support.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;
import javax.inject.Inject;
import org.tasks.analytics.Tracker;
import timber.log.Timber;
@ -10,6 +12,10 @@ public abstract class InjectingWorker extends Worker {
@Inject Tracker tracker;
public InjectingWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
}
@NonNull
@Override
public Result doWork() {

@ -6,6 +6,8 @@ import static com.todoroo.andlib.utility.DateUtilities.now;
import static java.util.Collections.emptyList;
import android.content.Context;
import android.support.annotation.NonNull;
import androidx.work.WorkerParameters;
import java.io.File;
import java.io.FileFilter;
import java.util.Arrays;
@ -33,13 +35,8 @@ public class BackupWork extends RepeatingWorker {
@Inject Preferences preferences;
@Inject WorkManager workManager;
@SuppressWarnings("unused")
public BackupWork() {}
BackupWork(Context context, TasksJsonExporter tasksJsonExporter, Preferences preferences) {
this.context = context;
this.tasksJsonExporter = tasksJsonExporter;
this.preferences = preferences;
public BackupWork(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
}
@Override

@ -1,6 +1,8 @@
package org.tasks.jobs;
import android.content.Context;
import android.support.annotation.NonNull;
import androidx.work.WorkerParameters;
import com.todoroo.astrid.alarms.AlarmService;
import com.todoroo.astrid.reminders.ReminderService;
import com.todoroo.astrid.timers.TimerPlugin;
@ -21,6 +23,10 @@ public class CleanupWork extends InjectingWorker {
@Inject ReminderService reminderService;
@Inject AlarmService alarmService;
public CleanupWork(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
}
@NonNull
@Override
public Result run() {

@ -1,5 +1,8 @@
package org.tasks.jobs;
import android.content.Context;
import android.support.annotation.NonNull;
import androidx.work.WorkerParameters;
import javax.inject.Inject;
import org.tasks.LocalBroadcastManager;
import org.tasks.injection.JobComponent;
@ -9,6 +12,10 @@ public class MidnightRefreshWork extends RepeatingWorker {
@Inject WorkManager workManager;
@Inject LocalBroadcastManager localBroadcastManager;
public MidnightRefreshWork(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
}
@Override
protected Result run() {
localBroadcastManager.broadcastRefresh();

@ -1,11 +1,12 @@
package org.tasks.jobs;
import android.content.Context;
import android.support.annotation.NonNull;
import androidx.work.WorkerParameters;
import java.util.List;
import javax.inject.Inject;
import org.tasks.BuildConfig;
import org.tasks.Notifier;
import org.tasks.injection.InjectingWorker;
import org.tasks.injection.JobComponent;
import org.tasks.preferences.Preferences;
@ -15,6 +16,10 @@ public class NotificationWork extends RepeatingWorker {
@Inject Notifier notifier;
@Inject NotificationQueue notificationQueue;
public NotificationWork(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
}
@NonNull
@Override
public Result run() {

@ -1,9 +1,10 @@
package org.tasks.jobs;
import android.content.Context;
import android.support.annotation.NonNull;
import androidx.work.WorkerParameters;
import javax.inject.Inject;
import org.tasks.LocalBroadcastManager;
import org.tasks.injection.InjectingWorker;
import org.tasks.injection.JobComponent;
import org.tasks.scheduling.RefreshScheduler;
@ -12,11 +13,16 @@ public class RefreshWork extends RepeatingWorker {
@Inject RefreshScheduler refreshScheduler;
@Inject LocalBroadcastManager localBroadcastManager;
public RefreshWork(@NonNull Context context,
@NonNull WorkerParameters workerParams) {
super(context, workerParams);
}
@NonNull
@Override
public Result run() {
localBroadcastManager.broadcastRefresh();
return Result.SUCCESS;
localBroadcastManager.broadcastRefresh();
return Result.SUCCESS;
}
@Override

@ -1,10 +1,16 @@
package org.tasks.jobs;
import android.content.Context;
import android.support.annotation.NonNull;
import androidx.work.WorkerParameters;
import org.tasks.injection.InjectingWorker;
public abstract class RepeatingWorker extends InjectingWorker {
public RepeatingWorker(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
}
@NonNull
@Override
public final Result doWork() {

@ -1,6 +1,8 @@
package org.tasks.jobs;
import android.content.Context;
import android.support.annotation.NonNull;
import androidx.work.WorkerParameters;
import javax.inject.Inject;
import org.tasks.LocalBroadcastManager;
import org.tasks.caldav.CaldavSynchronizer;
@ -19,6 +21,10 @@ public class SyncWork extends InjectingWorker {
@Inject LocalBroadcastManager localBroadcastManager;
@Inject Preferences preferences;
public SyncWork(@NonNull Context context, @NonNull WorkerParameters workerParams) {
super(context, workerParams);
}
@NonNull
@Override
public Result run() {

Loading…
Cancel
Save