Duplicate alarms and geofences

pull/848/head
Alex Baker 5 years ago
parent da4c3da758
commit 4367d74031

@ -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

@ -29,4 +29,7 @@ public interface AlarmDao {
@Insert
long insert(Alarm alarm);
@Insert
void insert(Iterable<Alarm> alarms);
}

@ -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;

@ -18,7 +18,7 @@ public interface TagDao {
void insert(Tag tag);
@Insert
void insert(List<Tag> tags);
void insert(Iterable<Tag> tags);
@Query("DELETE FROM tags WHERE task = :taskId AND tag_uid in (:tagUids)")
void deleteTags(long taskId, List<String> tagUids);

Loading…
Cancel
Save