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

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

Loading…
Cancel
Save