Clone CaldavTask

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

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

Loading…
Cancel
Save