Push file attach/delete on save

pull/14/head
Sam Bosley 13 years ago
parent 005271be06
commit f953d5b319

@ -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 * Push a file attachment to the server
* @param remoteTaskId * @param remoteTaskId

@ -34,6 +34,7 @@ import com.todoroo.andlib.utility.AndroidUtilities;
import com.todoroo.andlib.utility.DateUtilities; import com.todoroo.andlib.utility.DateUtilities;
import com.todoroo.andlib.utility.DialogUtilities; import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; 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.dao.MetadataDao.MetadataCriteria;
import com.todoroo.astrid.data.Metadata; import com.todoroo.astrid.data.Metadata;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
@ -45,6 +46,9 @@ public class FilesControlSet extends PopupControlSet {
@Autowired @Autowired
private MetadataService metadataService; private MetadataService metadataService;
@Autowired
private ActFmSyncService actFmSyncService;
private final ArrayList<Metadata> files = new ArrayList<Metadata>(); private final ArrayList<Metadata> files = new ArrayList<Metadata>();
private final LinearLayout fileDisplayList; private final LinearLayout fileDisplayList;
private LinearLayout fileList; private LinearLayout fileList;
@ -158,6 +162,7 @@ public class FilesControlSet extends PopupControlSet {
if (m.getValue(FileMetadata.REMOTE_ID) > 0) { if (m.getValue(FileMetadata.REMOTE_ID) > 0) {
m.setValue(FileMetadata.DELETION_DATE, DateUtilities.now()); m.setValue(FileMetadata.DELETION_DATE, DateUtilities.now());
metadataService.save(m); metadataService.save(m);
actFmSyncService.pushAttachmentInBackground(m);
} else { } else {
metadataService.delete(m); metadataService.delete(m);
} }

@ -77,6 +77,7 @@ import com.todoroo.astrid.actfm.ActFmCameraModule;
import com.todoroo.astrid.actfm.ActFmCameraModule.CameraResultCallback; import com.todoroo.astrid.actfm.ActFmCameraModule.CameraResultCallback;
import com.todoroo.astrid.actfm.EditPeopleControlSet; import com.todoroo.astrid.actfm.EditPeopleControlSet;
import com.todoroo.astrid.actfm.sync.ActFmPreferenceService; 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.Metadata;
import com.todoroo.astrid.data.Task; import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.files.AACRecordingActivity; import com.todoroo.astrid.files.AACRecordingActivity;
@ -211,6 +212,9 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
@Autowired @Autowired
private ActFmPreferenceService actFmPreferenceService; private ActFmPreferenceService actFmPreferenceService;
@Autowired
private ActFmSyncService actFmSyncService;
// --- UI components // --- UI components
private ImageButton voiceAddNoteButton; private ImageButton voiceAddNoteButton;
@ -1092,6 +1096,7 @@ ViewPager.OnPageChangeListener, EditNoteActivity.UpdatesChangedListener {
private void createNewFileAttachment(String path, String fileName, String fileType) { private void createNewFileAttachment(String path, String fileName, String fileType) {
Metadata fileMetadata = FileMetadata.createNewFileMetadata(model.getId(), path, fileName, fileType); Metadata fileMetadata = FileMetadata.createNewFileMetadata(model.getId(), path, fileName, fileType);
metadataService.save(fileMetadata); metadataService.save(fileMetadata);
actFmSyncService.pushAttachmentInBackground(fileMetadata);
filesControlSet.refreshMetadata(); filesControlSet.refreshMetadata();
} }

Loading…
Cancel
Save