|
|
|
@ -12,10 +12,6 @@ import com.todoroo.astrid.sync.SyncResultCallback;
|
|
|
|
|
|
|
|
|
|
import org.tasks.injection.ForApplication;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
import javax.inject.Singleton;
|
|
|
|
|
|
|
|
|
@ -34,28 +30,17 @@ public class SyncV2Service {
|
|
|
|
|
* there is enough interest, the Astrid team could create an interface
|
|
|
|
|
* for responding to sync requests through this new API.
|
|
|
|
|
*/
|
|
|
|
|
private final GtasksSyncV2Provider[] providers;
|
|
|
|
|
private final GtasksSyncV2Provider provider;
|
|
|
|
|
private final Context context;
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
public SyncV2Service(@ForApplication Context context, GtasksSyncV2Provider gtasksSyncV2Provider) {
|
|
|
|
|
this.context = context;
|
|
|
|
|
providers = new GtasksSyncV2Provider[] {
|
|
|
|
|
gtasksSyncV2Provider
|
|
|
|
|
};
|
|
|
|
|
provider = gtasksSyncV2Provider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns active sync providers
|
|
|
|
|
*/
|
|
|
|
|
public List<GtasksSyncV2Provider> activeProviders() {
|
|
|
|
|
ArrayList<GtasksSyncV2Provider> actives = new ArrayList<>();
|
|
|
|
|
for(GtasksSyncV2Provider provider : providers) {
|
|
|
|
|
if(provider.isActive()) {
|
|
|
|
|
actives.add(provider);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return Collections.unmodifiableList(actives);
|
|
|
|
|
public boolean isActive() {
|
|
|
|
|
return provider.isActive();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -65,20 +50,12 @@ public class SyncV2Service {
|
|
|
|
|
* @return true if any servide was logged in and initiated a sync
|
|
|
|
|
*/
|
|
|
|
|
public boolean synchronizeActiveTasks(SyncResultCallback callback) {
|
|
|
|
|
final List<GtasksSyncV2Provider> active = activeProviders();
|
|
|
|
|
|
|
|
|
|
if (active.size() == 0) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (active.size() > 1) { // This should never happen anymore--they can't be active at the same time, but if for some reason they both are, just use ActFm
|
|
|
|
|
active.get(1).synchronizeActiveTasks(new WidgetUpdatingCallbackWrapper(context, callback));
|
|
|
|
|
} else if (active.size() == 1) {
|
|
|
|
|
active.get(0).synchronizeActiveTasks(new WidgetUpdatingCallbackWrapper(context, callback));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (provider.isActive()) {
|
|
|
|
|
provider.synchronizeActiveTasks(new WidgetUpdatingCallbackWrapper(context, callback));
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initiate synchronization of task list
|
|
|
|
@ -87,10 +64,8 @@ public class SyncV2Service {
|
|
|
|
|
* @param callback result callback
|
|
|
|
|
*/
|
|
|
|
|
public void synchronizeList(Object list, SyncResultCallback callback) {
|
|
|
|
|
for(GtasksSyncV2Provider provider : providers) {
|
|
|
|
|
if(provider.isActive()) {
|
|
|
|
|
provider.synchronizeList(list, new WidgetUpdatingCallbackWrapper(context, callback));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|