From 6d01f886f863dd7e035cb17129c07cfb53e626a1 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Sat, 19 Jul 2014 01:46:34 -0500 Subject: [PATCH] Remove list from SyncV2Service --- .../astrid/helper/SyncActionHelper.java | 15 ++----- .../todoroo/astrid/service/SyncV2Service.java | 45 +++++-------------- 2 files changed, 14 insertions(+), 46 deletions(-) diff --git a/astrid/src/main/java/com/todoroo/astrid/helper/SyncActionHelper.java b/astrid/src/main/java/com/todoroo/astrid/helper/SyncActionHelper.java index 644f9198b..56e4e70c5 100644 --- a/astrid/src/main/java/com/todoroo/astrid/helper/SyncActionHelper.java +++ b/astrid/src/main/java/com/todoroo/astrid/helper/SyncActionHelper.java @@ -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 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 void showSyncOptionMenu(TYPE[] items, - DialogInterface.OnClickListener listener) { + private 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); } - } diff --git a/astrid/src/main/java/com/todoroo/astrid/service/SyncV2Service.java b/astrid/src/main/java/com/todoroo/astrid/service/SyncV2Service.java index 021fb0d0c..c30f124c9 100644 --- a/astrid/src/main/java/com/todoroo/astrid/service/SyncV2Service.java +++ b/astrid/src/main/java/com/todoroo/astrid/service/SyncV2Service.java @@ -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 activeProviders() { - ArrayList actives = new ArrayList<>(); - for(GtasksSyncV2Provider provider : providers) { - if(provider.isActive()) { - actives.add(provider); - } - } - return Collections.unmodifiableList(actives); + public boolean isActive() { + return provider.isActive(); } /** @@ -65,19 +50,11 @@ public class SyncV2Service { * @return true if any servide was logged in and initiated a sync */ public boolean synchronizeActiveTasks(SyncResultCallback callback) { - final List 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 true; + return false; } /** @@ -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)); - } + if(provider.isActive()) { + provider.synchronizeList(list, new WidgetUpdatingCallbackWrapper(context, callback)); } } }