Remove SyncV2Service

pull/795/head
Alex Baker 7 years ago
parent efb826e1bb
commit bbdf45f259

@ -8,6 +8,7 @@ package com.todoroo.astrid.activity;
import static android.app.Activity.RESULT_OK;
import static androidx.core.content.ContextCompat.getColor;
import static com.todoroo.andlib.utility.AndroidUtilities.assertMainThread;
import android.app.Activity;
import android.content.BroadcastReceiver;
@ -98,13 +99,11 @@ public class TaskListFragment extends InjectingFragment
// --- instance variables
private static final int REQUEST_EDIT_FILTER = 11544;
private static final int SEARCH_DEBOUNCE_TIMEOUT = 300;
private final RefreshReceiver refreshReceiver = new RefreshReceiver();
@Inject protected Tracker tracker;
protected Filter filter;
@Inject SyncAdapters syncAdapters;
@Inject TaskDeleter taskDeleter;
@Inject @ForActivity Context context;
@Inject Preferences preferences;
@Inject protected Preferences preferences;
@Inject DialogBuilder dialogBuilder;
@Inject CheckBoxes checkBoxes;
@Inject TaskCreator taskCreator;
@ -134,10 +133,11 @@ public class TaskListFragment extends InjectingFragment
private TaskListViewModel taskListViewModel;
private TaskAdapter taskAdapter = null;
private TaskListRecyclerAdapter recyclerAdapter;
private final RefreshReceiver refreshReceiver = new RefreshReceiver();
protected Filter filter;
private PublishSubject<String> searchSubject = PublishSubject.create();
private Disposable searchDisposable;
private CompositeDisposable disposables;
protected CompositeDisposable disposables;
/*
* ======================================================================
@ -166,14 +166,10 @@ public class TaskListFragment extends InjectingFragment
}
protected void setSyncOngoing(final boolean ongoing) {
Activity activity = getActivity();
if (activity != null) {
activity.runOnUiThread(
() -> {
assertMainThread();
swipeRefreshLayout.setRefreshing(ongoing);
emptyRefreshLayout.setRefreshing(ongoing);
});
}
}
@Override

@ -6,6 +6,8 @@
package com.todoroo.astrid.gtasks.sync;
import static com.todoroo.andlib.utility.AndroidUtilities.assertNotMainThread;
import android.content.Context;
import android.text.TextUtils;
import com.google.api.client.googleapis.extensions.android.gms.auth.UserRecoverableAuthIOException;
@ -30,6 +32,7 @@ import org.tasks.data.GoogleTaskListDao;
import org.tasks.gtasks.GtaskSyncAdapterHelper;
import org.tasks.injection.ApplicationScope;
import org.tasks.injection.ForApplication;
import org.tasks.jobs.WorkManager;
import org.tasks.preferences.Preferences;
import timber.log.Timber;
@ -44,6 +47,7 @@ public class GtasksSyncService {
private final GtaskSyncAdapterHelper gtaskSyncAdapterHelper;
private final Tracker tracker;
private final GoogleTaskDao googleTaskDao;
private final WorkManager workManager;
@Inject
public GtasksSyncService(
@ -53,18 +57,24 @@ public class GtasksSyncService {
GtaskSyncAdapterHelper gtaskSyncAdapterHelper,
Tracker tracker,
GoogleTaskDao googleTaskDao,
GoogleTaskListDao googleTaskListDao) {
GoogleTaskListDao googleTaskListDao,
WorkManager workManager) {
this.context = context;
this.taskDao = taskDao;
this.preferences = preferences;
this.gtaskSyncAdapterHelper = gtaskSyncAdapterHelper;
this.tracker = tracker;
this.googleTaskDao = googleTaskDao;
this.workManager = workManager;
new OperationPushThread(operationQueue).start();
}
public void clearCompleted(GoogleTaskList googleTaskList) {
operationQueue.offer(new ClearOp(googleTaskList));
public void clearCompleted(GoogleTaskList googleTaskList) throws IOException {
assertNotMainThread();
GtasksInvoker invoker = new GtasksInvoker(context, googleTaskList.getAccount());
invoker.clearCompleted(googleTaskList.getRemoteId());
workManager.syncNow();
}
public void triggerMoveForMetadata(GoogleTaskList googleTaskList, GoogleTask googleTask) {
@ -178,21 +188,6 @@ public class GtasksSyncService {
}
}
private class ClearOp implements SyncOnSaveOperation {
private GoogleTaskList googleTaskList;
ClearOp(GoogleTaskList googleTaskList) {
this.googleTaskList = googleTaskList;
}
@Override
public void op() throws IOException {
GtasksInvoker invoker = new GtasksInvoker(context, googleTaskList.getAccount());
invoker.clearCompleted(googleTaskList.getRemoteId());
}
}
private class OperationPushThread extends Thread {
private final LinkedBlockingQueue<SyncOnSaveOperation> queue;

@ -1,57 +0,0 @@
/*
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.service;
import com.todoroo.astrid.gtasks.sync.GtasksSyncService;
import com.todoroo.astrid.sync.SyncResultCallback;
import javax.inject.Inject;
import org.tasks.data.GoogleTaskList;
import org.tasks.gtasks.GtaskSyncAdapterHelper;
import org.tasks.sync.SyncExecutor;
/**
* SyncV2Service is a simplified synchronization interface for supporting next-generation sync
* interfaces such as Google Tasks and Astrid.com
*
* @author Tim Su <tim@astrid.com>
*/
public class SyncV2Service {
/*
* At present, sync provider interactions are handled through code. If
* there is enough interest, the Astrid team could create an interface
* for responding to sync requests through this new API.
*/
private final SyncExecutor syncExecutor;
private final GtaskSyncAdapterHelper gtaskSyncAdapterHelper;
private final GtasksSyncService gtasksSyncService;
@Inject
public SyncV2Service(
SyncExecutor syncExecutor,
GtaskSyncAdapterHelper gtaskSyncAdapterHelper,
GtasksSyncService gtasksSyncService) {
this.syncExecutor = syncExecutor;
this.gtaskSyncAdapterHelper = gtaskSyncAdapterHelper;
this.gtasksSyncService = gtasksSyncService;
}
public void clearCompleted(final GoogleTaskList list, final SyncResultCallback callback) {
if (gtaskSyncAdapterHelper.isEnabled()) {
syncExecutor.execute(
callback,
() -> {
callback.started();
try {
gtasksSyncService.clearCompleted(list);
} finally {
callback.finished();
}
});
}
}
}

@ -10,8 +10,10 @@ import com.todoroo.astrid.activity.MainActivity;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.Filter;
import com.todoroo.astrid.api.GtasksFilter;
import com.todoroo.astrid.service.SyncV2Service;
import com.todoroo.astrid.sync.SyncResultCallback;
import com.todoroo.astrid.gtasks.sync.GtasksSyncService;
import io.reactivex.Completable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import javax.inject.Inject;
import org.tasks.R;
import org.tasks.activities.GoogleTaskListSettingsActivity;
@ -24,7 +26,7 @@ public class GtasksListFragment extends TaskListFragment {
private static final String EXTRA_STORE_OBJECT = "extra_store_object";
private static final int REQUEST_LIST_SETTINGS = 10101;
protected GoogleTaskList list;
@Inject SyncV2Service syncService;
@Inject GtasksSyncService gtasksSyncService;
public static TaskListFragment newGtasksListFragment(GtasksFilter filter, GoogleTaskList list) {
GtasksListFragment fragment = new GtasksListFragment();
@ -86,21 +88,11 @@ public class GtasksListFragment extends TaskListFragment {
@Override
protected void clearCompleted() {
tracker.reportEvent(Tracking.Events.GTASK_CLEAR_COMPLETED);
syncService.clearCompleted(
list,
new SyncResultCallback() {
@Override
public void started() {
setSyncOngoing(true);
}
@Override
public void finished() {
setSyncOngoing(false);
onRefresh();
}
});
disposables.add(Completable.fromAction(() -> gtasksSyncService.clearCompleted(list))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(() -> preferences.isSyncOngoing()));
}
@Override

Loading…
Cancel
Save