diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmDataService.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmDataService.java index 99ba0d876..727ecfe26 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmDataService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmDataService.java @@ -5,8 +5,6 @@ */ package com.todoroo.astrid.actfm.sync; -import java.util.ArrayList; - import org.json.JSONException; import org.json.JSONObject; @@ -33,7 +31,6 @@ import com.todoroo.astrid.data.User; import com.todoroo.astrid.notes.NoteMetadata; import com.todoroo.astrid.service.MetadataService; import com.todoroo.astrid.service.TagDataService; -import com.todoroo.astrid.tags.TagMetadata; import com.todoroo.astrid.tags.TagService; public final class ActFmDataService { @@ -102,65 +99,6 @@ public final class ActFmDataService { Task.MODIFICATION_DATE.gt(Task.LAST_SYNC))).groupBy(Task.ID)); } - /** - * Searches for a local task with same remote id, updates this task's id - * @param remoteTask - * @return true if found local match - */ - public boolean findLocalMatch(ActFmTaskContainer remoteTask) { - if(remoteTask.task.getId() != Task.NO_ID) - return true; - TodorooCursor cursor = taskDao.query(Query.select(Task.ID). - where(Task.REMOTE_ID.eq(remoteTask.task.getValue(Task.REMOTE_ID)))); - try { - if(cursor.getCount() == 0) - return false; - cursor.moveToFirst(); - remoteTask.task.setId(cursor.get(Task.ID)); - return true; - } finally { - cursor.close(); - } - } - - /** - * Saves a task and its metadata - * @param task - */ - public void saveTaskAndMetadata(ActFmTaskContainer task) { - taskDao.save(task.task); - - metadataService.synchronizeMetadata(task.task.getId(), task.metadata, - Criterion.or(Criterion.and(MetadataCriteria.withKey(NoteMetadata.METADATA_KEY), - NoteMetadata.EXT_PROVIDER.eq(NOTE_PROVIDER)), - MetadataCriteria.withKey(TagMetadata.KEY))); - } - - /** - * Reads a task and its metadata - * @param task - * @return - */ - public ActFmTaskContainer readTaskAndMetadata(TodorooCursor taskCursor) { - Task task = new Task(taskCursor); - - // read tags, notes, etc - ArrayList metadata = new ArrayList(); - TodorooCursor metadataCursor = metadataService.query(Query.select(Metadata.PROPERTIES). - where(Criterion.and(MetadataCriteria.byTask(task.getId()), - Criterion.or(MetadataCriteria.withKey(TagMetadata.KEY), - MetadataCriteria.withKey(NoteMetadata.METADATA_KEY))))); - try { - for(metadataCursor.moveToFirst(); !metadataCursor.isAfterLast(); metadataCursor.moveToNext()) { - metadata.add(new Metadata(metadataCursor)); - } - } finally { - metadataCursor.close(); - } - - return new ActFmTaskContainer(task, metadata); - } - /** * Reads task notes out of a task */ diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java index ca9ff05ed..be2279a9d 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java @@ -818,7 +818,7 @@ public final class ActFmSyncService { JsonHelper.taskFromJson(result, task, metadata); task.putTransitory(SyncFlags.ACTFM_SUPPRESS_SYNC, true); taskService.save(task); - metadataService.synchronizeMetadata(task.getId(), metadata, Metadata.KEY.eq(TagMetadata.KEY)); + metadataService.synchronizeMetadata(task.getId(), metadata, Metadata.KEY.eq(TagMetadata.KEY), false); synchronizeAttachments(result, task); } @@ -1253,7 +1253,7 @@ public final class ActFmSyncService { } ids.add(remote.getId()); - metadataService.synchronizeMetadata(remote.getId(), metadata, MetadataCriteria.withKey(TagMetadata.KEY)); + metadataService.synchronizeMetadata(remote.getId(), metadata, MetadataCriteria.withKey(TagMetadata.KEY), false); synchronizeAttachments(item, remote); remote.clear(); } @@ -1574,10 +1574,7 @@ public final class ActFmSyncService { String name = tag.getString("name"); if(TextUtils.isEmpty(name)) continue; - Metadata tagMetadata = new Metadata(); - tagMetadata.setValue(Metadata.KEY, TagMetadata.KEY); - tagMetadata.setValue(TagMetadata.TAG_NAME, name); - tagMetadata.setValue(TagMetadata.TAG_UUID, tag.getLong("id")); + Metadata tagMetadata = TagMetadata.newTagMetadata(model.getId(), remoteId, name, tag.getLong("id")); metadata.add(tagMetadata); } } diff --git a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmTaskContainer.java b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmTaskContainer.java deleted file mode 100644 index 437a8b445..000000000 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmTaskContainer.java +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright (c) 2012 Todoroo Inc - * - * See the file "LICENSE" for the full license governing this code. - */ -package com.todoroo.astrid.actfm.sync; - -import java.util.ArrayList; -import java.util.Date; - -import org.json.JSONObject; - -import com.todoroo.andlib.service.ContextManager; -import com.todoroo.andlib.utility.DateUtilities; -import com.todoroo.astrid.data.Metadata; -import com.todoroo.astrid.data.Task; -import com.todoroo.astrid.notes.NoteMetadata; -import com.todoroo.astrid.sync.SyncContainer; - -/** - * RTM Task Container - * - * @author Tim Su - * - */ -public class ActFmTaskContainer extends SyncContainer { - - public ActFmTaskContainer(Task task, ArrayList metadata) { - this.task = task; - this.metadata = metadata; - } - - @SuppressWarnings("nls") - public ActFmTaskContainer(Task task, ArrayList metadata, JSONObject remoteTask) { - this(task, metadata); - task.setValue(Task.REMOTE_ID, remoteTask.optLong("id")); - } - - /** create note metadata from comment json object */ - @SuppressWarnings("nls") - public static Metadata newNoteMetadata(JSONObject comment) { - Metadata metadata = new Metadata(); - metadata.setValue(Metadata.KEY, NoteMetadata.METADATA_KEY); - metadata.setValue(NoteMetadata.EXT_ID, comment.optString("id")); - metadata.setValue(NoteMetadata.EXT_PROVIDER, - ActFmDataService.NOTE_PROVIDER); - - Date creationDate = new Date(comment.optInt("date") * 1000L); - metadata.setValue(Metadata.CREATION_DATE, creationDate.getTime()); - metadata.setValue(NoteMetadata.BODY, comment.optString("message")); - - JSONObject owner = comment.optJSONObject("owner"); - metadata.setValue(NoteMetadata.THUMBNAIL, owner.optString("picture")); - String title = String.format("%s on %s", - owner.optString("name"), - DateUtilities.getDateString(ContextManager.getContext(), creationDate)); - metadata.setValue(NoteMetadata.TITLE, title); - - return metadata; - } - -} diff --git a/astrid/plugin-src/com/todoroo/astrid/alarms/AlarmService.java b/astrid/plugin-src/com/todoroo/astrid/alarms/AlarmService.java index 28def416e..141e0adde 100644 --- a/astrid/plugin-src/com/todoroo/astrid/alarms/AlarmService.java +++ b/astrid/plugin-src/com/todoroo/astrid/alarms/AlarmService.java @@ -94,7 +94,7 @@ public class AlarmService { PendingIntent pendingIntent = pendingIntentForAlarm(m, taskId); am.cancel(pendingIntent); } - }); + }, true); if(changed) scheduleAlarms(taskId); diff --git a/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevDataService.java b/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevDataService.java index 4fcf1b1ef..c0e38b56b 100644 --- a/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevDataService.java +++ b/astrid/plugin-src/com/todoroo/astrid/producteev/sync/ProducteevDataService.java @@ -157,7 +157,7 @@ public final class ProducteevDataService { // note we don't include note metadata, since we only receive deltas metadataService.synchronizeMetadata(task.task.getId(), task.metadata, Criterion.or(MetadataCriteria.withKey(ProducteevTask.METADATA_KEY), - MetadataCriteria.withKey(TagMetadata.KEY))); + MetadataCriteria.withKey(TagMetadata.KEY)), true); } /** diff --git a/astrid/plugin-src/com/todoroo/astrid/tags/Astrid44SyncMigrator.java b/astrid/plugin-src/com/todoroo/astrid/tags/Astrid44SyncMigrator.java index 16b5d639b..5b7afbec6 100644 --- a/astrid/plugin-src/com/todoroo/astrid/tags/Astrid44SyncMigrator.java +++ b/astrid/plugin-src/com/todoroo/astrid/tags/Astrid44SyncMigrator.java @@ -40,7 +40,7 @@ public class Astrid44SyncMigrator { } @SuppressWarnings("nls") - public void migrateTagMetadataToTable() { + public void performMigration() { if (Preferences.getBoolean(PREF_MIGRATED_TASKS_TO_TAGS, false)) return; diff --git a/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitDataService.java b/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitDataService.java index d3e2efed1..8b4192a29 100644 --- a/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitDataService.java +++ b/astrid/plugin-src/com/todoroo/astrid/taskrabbit/TaskRabbitDataService.java @@ -60,7 +60,7 @@ public final class TaskRabbitDataService { task.metadata.add(task.trTask); // note we don't include note metadata, since we only receive deltas metadataService.synchronizeMetadata(task.task.getId(), task.metadata, - MetadataCriteria.withKey(TaskRabbitMetadata.METADATA_KEY)); + MetadataCriteria.withKey(TaskRabbitMetadata.METADATA_KEY), true); } /** diff --git a/astrid/src/com/todoroo/astrid/service/MetadataService.java b/astrid/src/com/todoroo/astrid/service/MetadataService.java index 312fe3cf2..109500432 100644 --- a/astrid/src/com/todoroo/astrid/service/MetadataService.java +++ b/astrid/src/com/todoroo/astrid/service/MetadataService.java @@ -106,7 +106,7 @@ public class MetadataService { * @return true if there were changes */ public boolean synchronizeMetadata(long taskId, ArrayList metadata, - Criterion metadataCriterion, SynchronizeMetadataCallback callback) { + Criterion metadataCriterion, SynchronizeMetadataCallback callback, boolean hardDelete) { boolean dirty = false; HashSet newMetadataValues = new HashSet(); for(Metadata metadatum : metadata) { @@ -142,11 +142,16 @@ public class MetadataService { } // not matched. cut it + item.setId(id); if (callback != null) { - item.setId(id); callback.beforeDeleteMetadata(item); } - metadataDao.delete(id); + if (hardDelete) + metadataDao.delete(id); + else { + item.setValue(Metadata.DELETION_DATE, DateUtilities.now()); + metadataDao.persist(item); + } dirty = true; } } finally { @@ -166,8 +171,8 @@ public class MetadataService { } public boolean synchronizeMetadata(long taskId, ArrayList metadata, - Criterion metadataCriterion) { - return synchronizeMetadata(taskId, metadata, metadataCriterion, null); + Criterion metadataCriterion, boolean hardDelete) { + return synchronizeMetadata(taskId, metadata, metadataCriterion, null, hardDelete); } /** diff --git a/astrid/src/com/todoroo/astrid/service/UpgradeService.java b/astrid/src/com/todoroo/astrid/service/UpgradeService.java index ddf82a376..faca70f48 100644 --- a/astrid/src/com/todoroo/astrid/service/UpgradeService.java +++ b/astrid/src/com/todoroo/astrid/service/UpgradeService.java @@ -198,7 +198,7 @@ public final class UpgradeService { new DueDateTimeMigrator().migrateDueTimes(); if (from < V4_4_0) - new Astrid44SyncMigrator().migrateTagMetadataToTable(); + new Astrid44SyncMigrator().performMigration(); } finally { DialogUtilities.dismissDialog((Activity)context, dialog);