Remove list from SyncV2Service

pull/189/head
Alex Baker 10 years ago
parent 1b6c7eaa69
commit 6d01f886f8

@ -20,7 +20,6 @@ import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import com.todoroo.astrid.gtasks.sync.GtasksSyncV2Provider;
import com.todoroo.astrid.service.SyncV2Service;
import com.todoroo.astrid.sync.SyncResultCallback;
@ -115,10 +114,9 @@ public class SyncActionHelper {
}
public void performSyncAction() {
List<GtasksSyncV2Provider> activeV2Providers = syncService.activeProviders();
int activeSyncs = activeV2Providers.size();
if (activeSyncs == 0) {
if (syncService.isActive()) {
syncService.synchronizeActiveTasks(syncResultCallback);
} else {
String desiredCategory = activity.getString(R.string.SyP_label);
// Get a list of all sync plugins and bring user to the prefs pane
@ -165,9 +163,6 @@ public class SyncActionHelper {
} else {
showSyncOptionMenu(actions, listener);
}
} else {
syncService.synchronizeActiveTasks(syncResultCallback);
}
}
@ -175,8 +170,7 @@ public class SyncActionHelper {
* Show menu of sync options. This is shown when you're not logged into any
* services, or logged into more than one.
*/
private <TYPE> void showSyncOptionMenu(TYPE[] items,
DialogInterface.OnClickListener listener) {
private <TYPE> void showSyncOptionMenu(TYPE[] items, DialogInterface.OnClickListener listener) {
if (items.length == 1) {
listener.onClick(null, 0);
return;
@ -189,7 +183,6 @@ public class SyncActionHelper {
new AlertDialog.Builder(activity).setTitle(R.string.Sync_now_label).setAdapter(
adapter, listener).show().setOwnerActivity(activity);
}
}

@ -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));
}
}
}
}

Loading…
Cancel
Save