From d8b3f962b6668100fcf5f63f2b4a97457ffb3a72 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Mon, 4 Mar 2013 17:41:11 -0800 Subject: [PATCH] First draft of prompt to import --- .../astrid/gtasks/GtasksPreferences.java | 25 ++++++++-- .../gtasks/sync/GtasksSyncV2Provider.java | 46 ++++++++++++++++++- 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksPreferences.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksPreferences.java index 0ba616248..8006a232a 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksPreferences.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/GtasksPreferences.java @@ -15,13 +15,15 @@ import com.todoroo.andlib.service.Autowired; import com.todoroo.andlib.service.DependencyInjectionService; import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; +import com.todoroo.astrid.data.Task; import com.todoroo.astrid.gtasks.auth.GtasksLoginActivity; import com.todoroo.astrid.gtasks.sync.GtasksSyncV2Provider; -import com.todoroo.astrid.service.SyncResultCallbackWrapper.WidgetUpdatingCallbackWrapper; +import com.todoroo.astrid.gtasks.sync.GtasksSyncV2Provider.GtasksImportCallback; +import com.todoroo.astrid.gtasks.sync.GtasksSyncV2Provider.GtasksImportTuple; import com.todoroo.astrid.sync.SyncProviderPreferences; import com.todoroo.astrid.sync.SyncProviderUtilities; -import com.todoroo.astrid.sync.SyncResultCallback; import com.todoroo.astrid.sync.SyncResultCallbackAdapter; +import com.todoroo.astrid.tags.TagService; /** * Displays synchronization preferences and an action panel so users can @@ -34,6 +36,7 @@ public class GtasksPreferences extends SyncProviderPreferences { @Autowired private GtasksPreferenceService gtasksPreferenceService; @Autowired private ActFmPreferenceService actFmPreferenceService; + @Autowired private TagService tagService; public GtasksPreferences() { super(); @@ -97,13 +100,27 @@ public class GtasksPreferences extends SyncProviderPreferences { pd.setCancelable(false); pd.show(); - SyncResultCallback callback = new WidgetUpdatingCallbackWrapper(new SyncResultCallbackAdapter() { + GtasksImportCallback callback = new GtasksImportCallback(new SyncResultCallbackAdapter() {/**/}) { @Override public void finished() { super.finished(); + for (GtasksImportTuple tuple : importConflicts) { + final GtasksImportTuple finalTuple = tuple; + DialogUtilities.okCancelDialog(GtasksPreferences.this, + "Add task " + tuple.taskUuid + " to shared list " + tuple.tagUuid + "?", + new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + Task task = new Task(); + task.setId(finalTuple.taskId); + task.setUuid(finalTuple.taskUuid); + tagService.createLink(task, finalTuple.tagName, finalTuple.tagUuid); + } + }, null); + } DialogUtilities.dismissDialog(GtasksPreferences.this, pd); } - }); + }; GtasksSyncV2Provider.getInstance().synchronizeActiveTasks(true, callback); } diff --git a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncV2Provider.java b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncV2Provider.java index a86cb2fe8..f9c620096 100644 --- a/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncV2Provider.java +++ b/astrid/plugin-src/com/todoroo/astrid/gtasks/sync/GtasksSyncV2Provider.java @@ -32,6 +32,7 @@ import com.todoroo.astrid.core.PluginServices; import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; import com.todoroo.astrid.dao.StoreObjectDao; import com.todoroo.astrid.dao.TagDataDao; +import com.todoroo.astrid.dao.TagMetadataDao; import com.todoroo.astrid.dao.TaskDao; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.RemoteModel; @@ -53,6 +54,7 @@ import com.todoroo.astrid.service.AstridDependencyInjector; import com.todoroo.astrid.service.MetadataService; import com.todoroo.astrid.service.StatisticsConstants; import com.todoroo.astrid.service.StatisticsService; +import com.todoroo.astrid.service.SyncResultCallbackWrapper.WidgetUpdatingCallbackWrapper; import com.todoroo.astrid.service.TaskService; import com.todoroo.astrid.sync.SyncResultCallback; import com.todoroo.astrid.sync.SyncV2Provider; @@ -71,6 +73,7 @@ public class GtasksSyncV2Provider extends SyncV2Provider { @Autowired GtasksTaskListUpdater gtasksTaskListUpdater; @Autowired TagService tagService; @Autowired TagDataDao tagDataDao; + @Autowired TagMetadataDao tagMetadataDao; static { AstridDependencyInjector.initialize(); @@ -111,6 +114,27 @@ public class GtasksSyncV2Provider extends SyncV2Provider { return gtasksPreferenceService.isLoggedIn() && !actFmPreferenceService.isLoggedIn(); } + public static class GtasksImportTuple { + public long taskId; + public String taskUuid; + public String tagUuid; + public String tagName; + } + + public static class GtasksImportCallback extends WidgetUpdatingCallbackWrapper { + + protected final ArrayList importConflicts; + + public GtasksImportCallback(SyncResultCallback wrap) { + super(wrap); + importConflicts = new ArrayList(); + } + + public void addImportConflict(GtasksImportTuple tuple) { + importConflicts.add(tuple); + } + } + @Override public void synchronizeActiveTasks(final boolean manual, final SyncResultCallback callback) { // TODO: Improve this logic. Should only be able to import from settings or something. @@ -155,7 +179,7 @@ public class GtasksSyncV2Provider extends SyncV2Provider { if (!isImport) pushUpdated(invoker, callback); else - finishImport(); + finishImport(callback); finishSync(callback); } } @@ -378,11 +402,16 @@ public class GtasksSyncV2Provider extends SyncV2Provider { } } - private void finishImport() { + private void finishImport(SyncResultCallback callback) { TodorooCursor tasks = taskService.query(Query.select(Task.ID, Task.UUID, GtasksList.NAME) .join(Join.inner(Metadata.TABLE, Task.ID.eq(Metadata.TASK))) .join(Join.left(StoreObject.TABLE, GtasksMetadata.LIST_ID.eq(GtasksList.REMOTE_ID))) .where(MetadataCriteria.withKey(GtasksMetadata.METADATA_KEY))); + + GtasksImportCallback gtCallback = null; + if (callback instanceof GtasksImportCallback) + gtCallback = (GtasksImportCallback) callback; + try { for (tasks.moveToFirst(); !tasks.isAfterLast(); tasks.moveToNext()) { String listName = tasks.get(GtasksList.NAME); @@ -393,6 +422,19 @@ public class GtasksSyncV2Provider extends SyncV2Provider { if (existingTag.getCount() > 0) { existingTag.moveToFirst(); tagUuid = existingTag.get(TagData.UUID); + + if (tagMetadataDao.tagHasMembers(tagUuid)) { + GtasksImportTuple tuple = new GtasksImportTuple(); + tuple.taskId = tasks.get(Task.ID); + tuple.taskUuid = tasks.get(Task.UUID); + tuple.tagUuid = tagUuid; + tuple.tagName = listName; + + if (gtCallback != null) + gtCallback.addImportConflict(tuple); + + continue; + } } else { TagData td = new TagData(); td.setValue(TagData.NAME, listName);