|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
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;
|
|
|
|
@ -10,10 +11,14 @@ import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import javax.inject.Inject;
|
|
|
|
|
import org.tasks.LocalBroadcastManager;
|
|
|
|
|
import org.tasks.data.Alarm;
|
|
|
|
|
import org.tasks.data.AlarmDao;
|
|
|
|
|
import org.tasks.data.CaldavDao;
|
|
|
|
|
import org.tasks.data.CaldavTask;
|
|
|
|
|
import org.tasks.data.Geofence;
|
|
|
|
|
import org.tasks.data.GoogleTask;
|
|
|
|
|
import org.tasks.data.GoogleTaskDao;
|
|
|
|
|
import org.tasks.data.LocationDao;
|
|
|
|
|
import org.tasks.data.Tag;
|
|
|
|
|
import org.tasks.data.TagDao;
|
|
|
|
|
import org.tasks.data.TagData;
|
|
|
|
@ -28,6 +33,8 @@ public class TaskDuplicator {
|
|
|
|
|
private final TagDataDao tagDataDao;
|
|
|
|
|
private final GoogleTaskDao googleTaskDao;
|
|
|
|
|
private final CaldavDao caldavDao;
|
|
|
|
|
private final LocationDao locationDao;
|
|
|
|
|
private final AlarmDao alarmDao;
|
|
|
|
|
private final Preferences preferences;
|
|
|
|
|
private final LocalBroadcastManager localBroadcastManager;
|
|
|
|
|
|
|
|
|
@ -40,6 +47,8 @@ public class TaskDuplicator {
|
|
|
|
|
TagDataDao tagDataDao,
|
|
|
|
|
GoogleTaskDao googleTaskDao,
|
|
|
|
|
CaldavDao caldavDao,
|
|
|
|
|
LocationDao locationDao,
|
|
|
|
|
AlarmDao alarmDao,
|
|
|
|
|
Preferences preferences) {
|
|
|
|
|
this.gcalHelper = gcalHelper;
|
|
|
|
|
this.taskDao = taskDao;
|
|
|
|
@ -48,6 +57,8 @@ public class TaskDuplicator {
|
|
|
|
|
this.tagDataDao = tagDataDao;
|
|
|
|
|
this.googleTaskDao = googleTaskDao;
|
|
|
|
|
this.caldavDao = caldavDao;
|
|
|
|
|
this.locationDao = locationDao;
|
|
|
|
|
this.alarmDao = alarmDao;
|
|
|
|
|
this.preferences = preferences;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -71,8 +82,9 @@ public class TaskDuplicator {
|
|
|
|
|
clone.putTransitory(TaskDao.TRANS_SUPPRESS_REFRESH, true);
|
|
|
|
|
taskDao.createNew(clone);
|
|
|
|
|
|
|
|
|
|
for (TagData tagData : tagDataDao.getTagDataForTask(originalId)) {
|
|
|
|
|
tagDao.insert(new Tag(clone, tagData));
|
|
|
|
|
List<TagData> tags = tagDataDao.getTagDataForTask(originalId);
|
|
|
|
|
if (!tags.isEmpty()) {
|
|
|
|
|
tagDao.insert(transform(tags, td -> new Tag(clone, td)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GoogleTask googleTask = googleTaskDao.getByTaskId(originalId);
|
|
|
|
@ -86,6 +98,16 @@ public class TaskDuplicator {
|
|
|
|
|
caldavDao.insert(new CaldavTask(clone.getId(), caldavTask.getCalendar()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (Geofence g : locationDao.getGeofencesForTask(originalId)) {
|
|
|
|
|
locationDao.insert(
|
|
|
|
|
new Geofence(clone.getId(), g.getPlace(), g.isArrival(), g.isDeparture(), g.getRadius()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<Alarm> alarms = alarmDao.getAlarms(originalId);
|
|
|
|
|
if (!alarms.isEmpty()) {
|
|
|
|
|
alarmDao.insert(transform(alarms, a -> new Alarm(clone.getId(), a.getTime())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gcalHelper.createTaskEventIfEnabled(clone);
|
|
|
|
|
|
|
|
|
|
taskDao.save(clone, null); // TODO: delete me
|
|
|
|
|