Clone CaldavTask

pull/848/head
Alex Baker 5 years ago
parent 2188d788c3
commit 1c55f2bc3c

@ -1,21 +1,23 @@
package com.todoroo.astrid.service;
import static com.google.common.collect.Lists.transform;
import static com.todoroo.andlib.utility.DateUtilities.now;
import com.todoroo.astrid.dao.TaskDao;
import com.todoroo.astrid.data.SyncFlags;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.gcal.GCalHelper;
import com.todoroo.astrid.helper.UUIDHelper;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.tasks.LocalBroadcastManager;
import org.tasks.data.CaldavDao;
import org.tasks.data.CaldavTask;
import org.tasks.data.GoogleTask;
import org.tasks.data.GoogleTaskDao;
import org.tasks.data.Tag;
import org.tasks.data.TagDao;
import org.tasks.data.TagData;
import org.tasks.data.TagDataDao;
import org.tasks.preferences.Preferences;
public class TaskDuplicator {
@ -23,7 +25,9 @@ public class TaskDuplicator {
private final GCalHelper gcalHelper;
private final TaskDao taskDao;
private final TagDao tagDao;
private final TagDataDao tagDataDao;
private final GoogleTaskDao googleTaskDao;
private final CaldavDao caldavDao;
private final Preferences preferences;
private final LocalBroadcastManager localBroadcastManager;
@ -33,13 +37,17 @@ public class TaskDuplicator {
TaskDao taskDao,
LocalBroadcastManager localBroadcastManager,
TagDao tagDao,
TagDataDao tagDataDao,
GoogleTaskDao googleTaskDao,
CaldavDao caldavDao,
Preferences preferences) {
this.gcalHelper = gcalHelper;
this.taskDao = taskDao;
this.localBroadcastManager = localBroadcastManager;
this.tagDao = tagDao;
this.tagDataDao = tagDataDao;
this.googleTaskDao = googleTaskDao;
this.caldavDao = caldavDao;
this.preferences = preferences;
}
@ -53,30 +61,31 @@ public class TaskDuplicator {
}
private Task clone(Task clone) {
long originalId = clone.getId();
clone.setCreationDate(now());
clone.setModificationDate(now());
clone.setCompletionDate(0L);
clone.setCalendarUri("");
clone.setUuid(UUIDHelper.newUUID());
List<Tag> tags = tagDao.getTagsForTask(clone.getId());
GoogleTask googleTask = googleTaskDao.getByTaskId(clone.getId());
if (googleTask != null) {
clone.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true);
}
clone.setUuid(null);
clone.putTransitory(SyncFlags.GTASKS_SUPPRESS_SYNC, true);
clone.putTransitory(TaskDao.TRANS_SUPPRESS_REFRESH, true);
taskDao.createNew(clone);
tagDao.insert(
transform(
tags, tag -> new Tag(clone, tag.getName(), tag.getTagUid())));
for (TagData tagData : tagDataDao.getTagDataForTask(originalId)) {
tagDao.insert(new Tag(clone, tagData));
}
GoogleTask googleTask = googleTaskDao.getByTaskId(originalId);
if (googleTask != null) {
googleTaskDao.insertAndShift(
new GoogleTask(clone.getId(), googleTask.getListId()), preferences.addGoogleTasksToTop());
}
CaldavTask caldavTask = caldavDao.getTask(originalId);
if (caldavTask != null) {
caldavDao.insert(new CaldavTask(clone.getId(), caldavTask.getCalendar()));
}
gcalHelper.createTaskEventIfEnabled(clone);
taskDao.save(clone, null); // TODO: delete me

Loading…
Cancel
Save