diff --git a/app/src/main/java/com/todoroo/astrid/service/TaskDuplicator.java b/app/src/main/java/com/todoroo/astrid/service/TaskDuplicator.java index c8dd091d4..59f2ad008 100644 --- a/app/src/main/java/com/todoroo/astrid/service/TaskDuplicator.java +++ b/app/src/main/java/com/todoroo/astrid/service/TaskDuplicator.java @@ -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 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 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 diff --git a/app/src/main/java/org/tasks/data/AlarmDao.java b/app/src/main/java/org/tasks/data/AlarmDao.java index 2bea4dbd2..0f855dc17 100644 --- a/app/src/main/java/org/tasks/data/AlarmDao.java +++ b/app/src/main/java/org/tasks/data/AlarmDao.java @@ -29,4 +29,7 @@ public interface AlarmDao { @Insert long insert(Alarm alarm); + + @Insert + void insert(Iterable alarms); } diff --git a/app/src/main/java/org/tasks/data/Geofence.java b/app/src/main/java/org/tasks/data/Geofence.java index f76f9a707..4a362b396 100644 --- a/app/src/main/java/org/tasks/data/Geofence.java +++ b/app/src/main/java/org/tasks/data/Geofence.java @@ -51,6 +51,12 @@ public class Geofence implements Serializable, Parcelable { public Geofence() {} + @Ignore + public Geofence(long task, String place, boolean arrival, boolean departure, int radius) { + this(place, arrival, departure, radius); + this.task = task; + } + @Ignore public Geofence(String place, boolean arrival, boolean departure, int radius) { this.place = place; diff --git a/app/src/main/java/org/tasks/data/TagDao.java b/app/src/main/java/org/tasks/data/TagDao.java index ad7e71f69..ad0666921 100644 --- a/app/src/main/java/org/tasks/data/TagDao.java +++ b/app/src/main/java/org/tasks/data/TagDao.java @@ -18,7 +18,7 @@ public interface TagDao { void insert(Tag tag); @Insert - void insert(List tags); + void insert(Iterable tags); @Query("DELETE FROM tags WHERE task = :taskId AND tag_uid in (:tagUids)") void deleteTags(long taskId, List tagUids);