From f953d5b319ce33b27f2d74cea6f0c11e12733053 Mon Sep 17 00:00:00 2001 From: Sam Bosley Date: Fri, 1 Jun 2012 15:06:54 -0700 Subject: [PATCH] Push file attach/delete on save --- .../astrid/actfm/sync/ActFmSyncService.java | 23 +++++++++++++++++++ .../todoroo/astrid/files/FilesControlSet.java | 5 ++++ .../astrid/activity/TaskEditFragment.java | 5 ++++ 3 files changed, 33 insertions(+) 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 f656e34cd..d42176d56 100644 --- a/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java +++ b/astrid/plugin-src/com/todoroo/astrid/actfm/sync/ActFmSyncService.java @@ -589,6 +589,29 @@ public final class ActFmSyncService { } } + public void pushAttachmentInBackground(final Metadata fileMetadata) { + new Thread(new Runnable() { + @Override + public void run() { + waitUntilEmpty.close(); + taskPushThreads.incrementAndGet(); + try { + Task t = taskDao.fetch(fileMetadata.getValue(Metadata.TASK), Task.REMOTE_ID); + if (t == null || t.getValue(Task.REMOTE_ID) <= 0) + return; + if (fileMetadata.getValue(FileMetadata.DELETION_DATE) > 0) + deleteAttachment(fileMetadata); + else + pushAttachment(t.getValue(Task.REMOTE_ID), fileMetadata); + } finally { + if (taskPushThreads.decrementAndGet() == 0) { + waitUntilEmpty.open(); + } + } + } + }).start(); + } + /** * Push a file attachment to the server * @param remoteTaskId diff --git a/astrid/plugin-src/com/todoroo/astrid/files/FilesControlSet.java b/astrid/plugin-src/com/todoroo/astrid/files/FilesControlSet.java index 799a3547b..991eef0fb 100644 --- a/astrid/plugin-src/com/todoroo/astrid/files/FilesControlSet.java +++ b/astrid/plugin-src/com/todoroo/astrid/files/FilesControlSet.java @@ -34,6 +34,7 @@ import com.todoroo.andlib.utility.AndroidUtilities; import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; +import com.todoroo.astrid.actfm.sync.ActFmSyncService; import com.todoroo.astrid.dao.MetadataDao.MetadataCriteria; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Task; @@ -45,6 +46,9 @@ public class FilesControlSet extends PopupControlSet { @Autowired private MetadataService metadataService; + @Autowired + private ActFmSyncService actFmSyncService; + private final ArrayList files = new ArrayList(); private final LinearLayout fileDisplayList; private LinearLayout fileList; @@ -158,6 +162,7 @@ public class FilesControlSet extends PopupControlSet { if (m.getValue(FileMetadata.REMOTE_ID) > 0) { m.setValue(FileMetadata.DELETION_DATE, DateUtilities.now()); metadataService.save(m); + actFmSyncService.pushAttachmentInBackground(m); } else { metadataService.delete(m); } diff --git a/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java b/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java index e4d9f0069..c8cee3941 100755 --- a/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java +++ b/astrid/src/com/todoroo/astrid/activity/TaskEditFragment.java @@ -77,6 +77,7 @@ import com.todoroo.astrid.actfm.ActFmCameraModule; import com.todoroo.astrid.actfm.ActFmCameraModule.CameraResultCallback; import com.todoroo.astrid.actfm.EditPeopleControlSet; import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; +import com.todoroo.astrid.actfm.sync.ActFmSyncService; import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Task; import com.todoroo.astrid.files.AACRecordingActivity; @@ -211,6 +212,9 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener { @Autowired private ActFmPreferenceService actFmPreferenceService; + @Autowired + private ActFmSyncService actFmSyncService; + // --- UI components private ImageButton voiceAddNoteButton; @@ -1092,6 +1096,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener { private void createNewFileAttachment(String path, String fileName, String fileType) { Metadata fileMetadata = FileMetadata.createNewFileMetadata(model.getId(), path, fileName, fileType); metadataService.save(fileMetadata); + actFmSyncService.pushAttachmentInBackground(fileMetadata); filesControlSet.refreshMetadata(); }