Remove SyncV2Provider

pull/189/head
Alex Baker 10 years ago
parent 7ab8d3a811
commit d5511a05c9

@ -33,7 +33,6 @@ import com.todoroo.astrid.gtasks.api.GtasksInvoker;
import com.todoroo.astrid.gtasks.auth.GtasksTokenValidator; import com.todoroo.astrid.gtasks.auth.GtasksTokenValidator;
import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.service.TaskService;
import com.todoroo.astrid.sync.SyncResultCallback; import com.todoroo.astrid.sync.SyncResultCallback;
import com.todoroo.astrid.sync.SyncV2Provider;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -53,7 +52,26 @@ import javax.inject.Singleton;
import static org.tasks.date.DateTimeUtils.newDate; import static org.tasks.date.DateTimeUtils.newDate;
@Singleton @Singleton
public class GtasksSyncV2Provider extends SyncV2Provider { public class GtasksSyncV2Provider {
public class SyncExceptionHandler {
public void handleException(String tag, Exception e) {
getUtilities().setLastError(e.toString());
log.error("{}: {}", tag, e.getMessage(), e);
}
}
private final SyncExceptionHandler handler = new SyncExceptionHandler();
private void finishSync(SyncResultCallback callback) {
getUtilities().recordSuccessfulSync();
callback.finished();
}
@Override
public String toString() {
return getName();
}
private static final Logger log = LoggerFactory.getLogger(GtasksSyncV2Provider.class); private static final Logger log = LoggerFactory.getLogger(GtasksSyncV2Provider.class);
@ -89,12 +107,10 @@ public class GtasksSyncV2Provider extends SyncV2Provider {
this.executor = executor; this.executor = executor;
} }
@Override private String getName() {
public String getName() {
return context.getString(R.string.gtasks_GPr_header); return context.getString(R.string.gtasks_GPr_header);
} }
@Override
public GtasksPreferenceService getUtilities() { public GtasksPreferenceService getUtilities() {
return gtasksPreferenceService; return gtasksPreferenceService;
} }
@ -106,12 +122,10 @@ public class GtasksSyncV2Provider extends SyncV2Provider {
gtasksMetadataService.clearMetadata(); gtasksMetadataService.clearMetadata();
} }
@Override
public boolean isActive() { public boolean isActive() {
return gtasksPreferenceService.isLoggedIn(); return gtasksPreferenceService.isLoggedIn();
} }
@Override
public void synchronizeActiveTasks(final SyncResultCallback callback) { public void synchronizeActiveTasks(final SyncResultCallback callback) {
executor.execute(callback, new Runnable() { executor.execute(callback, new Runnable() {
@Override @Override
@ -174,7 +188,6 @@ public class GtasksSyncV2Provider extends SyncV2Provider {
} }
} }
@Override
public void synchronizeList(Object list, final SyncResultCallback callback) { public void synchronizeList(Object list, final SyncResultCallback callback) {
if (!(list instanceof StoreObject)) { if (!(list instanceof StoreObject)) {
return; return;

@ -25,9 +25,9 @@ import com.todoroo.astrid.activity.TaskListFragment;
import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.AstridApiConstants;
import com.todoroo.astrid.api.SyncAction; import com.todoroo.astrid.api.SyncAction;
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;
import com.todoroo.astrid.sync.SyncV2Provider;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -164,7 +164,7 @@ public class SyncActionHelper {
} }
public void performSyncAction() { public void performSyncAction() {
List<SyncV2Provider> activeV2Providers = syncService.activeProviders(); List<GtasksSyncV2Provider> activeV2Providers = syncService.activeProviders();
int activeSyncs = syncActions.size() + activeV2Providers.size(); int activeSyncs = syncActions.size() + activeV2Providers.size();
if (activeSyncs == 0) { if (activeSyncs == 0) {

@ -9,7 +9,6 @@ import android.content.Context;
import com.todoroo.astrid.gtasks.sync.GtasksSyncV2Provider; import com.todoroo.astrid.gtasks.sync.GtasksSyncV2Provider;
import com.todoroo.astrid.sync.SyncResultCallback; import com.todoroo.astrid.sync.SyncResultCallback;
import com.todoroo.astrid.sync.SyncV2Provider;
import org.tasks.injection.ForApplication; import org.tasks.injection.ForApplication;
@ -35,13 +34,13 @@ 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 SyncV2Provider[] providers; private final GtasksSyncV2Provider[] providers;
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 SyncV2Provider[] { providers = new GtasksSyncV2Provider[] {
gtasksSyncV2Provider gtasksSyncV2Provider
}; };
} }
@ -49,9 +48,9 @@ public class SyncV2Service {
/** /**
* Returns active sync providers * Returns active sync providers
*/ */
public List<SyncV2Provider> activeProviders() { public List<GtasksSyncV2Provider> activeProviders() {
ArrayList<SyncV2Provider> actives = new ArrayList<>(); ArrayList<GtasksSyncV2Provider> actives = new ArrayList<>();
for(SyncV2Provider provider : providers) { for(GtasksSyncV2Provider provider : providers) {
if(provider.isActive()) { if(provider.isActive()) {
actives.add(provider); actives.add(provider);
} }
@ -66,7 +65,7 @@ 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<SyncV2Provider> active = activeProviders(); final List<GtasksSyncV2Provider> active = activeProviders();
if (active.size() == 0) { if (active.size() == 0) {
return false; return false;
@ -88,7 +87,7 @@ 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(SyncV2Provider provider : providers) { for(GtasksSyncV2Provider provider : providers) {
if(provider.isActive()) { if(provider.isActive()) {
provider.synchronizeList(list, new WidgetUpdatingCallbackWrapper(context, callback)); provider.synchronizeList(list, new WidgetUpdatingCallbackWrapper(context, callback));
} }

@ -1,64 +0,0 @@
/**
* Copyright (c) 2012 Todoroo Inc
*
* See the file "LICENSE" for the full license governing this code.
*/
package com.todoroo.astrid.sync;
import com.todoroo.astrid.gtasks.GtasksPreferenceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
abstract public class SyncV2Provider {
private static final Logger log = LoggerFactory.getLogger(SyncV2Provider.class);
public class SyncExceptionHandler {
public void handleException(String tag, Exception e) {
getUtilities().setLastError(e.toString());
log.error("{}: {}", tag, e.getMessage(), e);
}
}
protected final SyncExceptionHandler handler = new SyncExceptionHandler();
/**
* @return sync provider name (displayed in sync menu)
*/
abstract public String getName();
/**
* @return true if this provider is logged in
*/
abstract public boolean isActive();
/**
* Synchronize all of user's active tasks
* @param callback callback object
*/
abstract public void synchronizeActiveTasks(SyncResultCallback callback);
/**
* Synchronize a single list
* @param list object representing list (TaskListActivity-dependent)
* @param callback callback object
*/
abstract public void synchronizeList(Object list, SyncResultCallback callback);
/**
* @return sync utility instance
*/
abstract protected GtasksPreferenceService getUtilities();
protected void finishSync(SyncResultCallback callback) {
getUtilities().recordSuccessfulSync();
callback.finished();
}
@Override
public String toString() {
return getName();
}
}
Loading…
Cancel
Save