|
|
@ -12,10 +12,6 @@ import com.todoroo.astrid.sync.SyncResultCallback;
|
|
|
|
|
|
|
|
|
|
|
|
import org.tasks.injection.ForApplication;
|
|
|
|
import org.tasks.injection.ForApplication;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
import javax.inject.Inject;
|
|
|
|
import javax.inject.Singleton;
|
|
|
|
import javax.inject.Singleton;
|
|
|
|
|
|
|
|
|
|
|
@ -34,28 +30,17 @@ public class SyncV2Service {
|
|
|
|
* there is enough interest, the Astrid team could create an interface
|
|
|
|
* there is enough interest, the Astrid team could create an interface
|
|
|
|
* for responding to sync requests through this new API.
|
|
|
|
* for responding to sync requests through this new API.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private final GtasksSyncV2Provider[] providers;
|
|
|
|
private final GtasksSyncV2Provider provider;
|
|
|
|
private final Context context;
|
|
|
|
private final Context context;
|
|
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
@Inject
|
|
|
|
public SyncV2Service(@ForApplication Context context, GtasksSyncV2Provider gtasksSyncV2Provider) {
|
|
|
|
public SyncV2Service(@ForApplication Context context, GtasksSyncV2Provider gtasksSyncV2Provider) {
|
|
|
|
this.context = context;
|
|
|
|
this.context = context;
|
|
|
|
providers = new GtasksSyncV2Provider[] {
|
|
|
|
provider = gtasksSyncV2Provider;
|
|
|
|
gtasksSyncV2Provider
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
public boolean isActive() {
|
|
|
|
* Returns active sync providers
|
|
|
|
return provider.isActive();
|
|
|
|
*/
|
|
|
|
|
|
|
|
public List<GtasksSyncV2Provider> activeProviders() {
|
|
|
|
|
|
|
|
ArrayList<GtasksSyncV2Provider> actives = new ArrayList<>();
|
|
|
|
|
|
|
|
for(GtasksSyncV2Provider provider : providers) {
|
|
|
|
|
|
|
|
if(provider.isActive()) {
|
|
|
|
|
|
|
|
actives.add(provider);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Collections.unmodifiableList(actives);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -65,19 +50,11 @@ public class SyncV2Service {
|
|
|
|
* @return true if any servide was logged in and initiated a sync
|
|
|
|
* @return true if any servide was logged in and initiated a sync
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public boolean synchronizeActiveTasks(SyncResultCallback callback) {
|
|
|
|
public boolean synchronizeActiveTasks(SyncResultCallback callback) {
|
|
|
|
final List<GtasksSyncV2Provider> active = activeProviders();
|
|
|
|
if (provider.isActive()) {
|
|
|
|
|
|
|
|
provider.synchronizeActiveTasks(new WidgetUpdatingCallbackWrapper(context, callback));
|
|
|
|
if (active.size() == 0) {
|
|
|
|
return true;
|
|
|
|
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));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -87,10 +64,8 @@ public class SyncV2Service {
|
|
|
|
* @param callback result callback
|
|
|
|
* @param callback result callback
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void synchronizeList(Object list, SyncResultCallback callback) {
|
|
|
|
public void synchronizeList(Object list, SyncResultCallback callback) {
|
|
|
|
for(GtasksSyncV2Provider provider : providers) {
|
|
|
|
if(provider.isActive()) {
|
|
|
|
if(provider.isActive()) {
|
|
|
|
provider.synchronizeList(list, new WidgetUpdatingCallbackWrapper(context, callback));
|
|
|
|
provider.synchronizeList(list, new WidgetUpdatingCallbackWrapper(context, callback));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|