diff --git a/app/src/main/java/com/todoroo/astrid/data/Task.kt b/app/src/main/java/com/todoroo/astrid/data/Task.kt index d317f82e3..00b5393c3 100644 --- a/app/src/main/java/com/todoroo/astrid/data/Task.kt +++ b/app/src/main/java/com/todoroo/astrid/data/Task.kt @@ -15,6 +15,7 @@ import org.tasks.Strings import org.tasks.backup.XmlReader import org.tasks.data.Tag import org.tasks.date.DateTimeUtils +import org.tasks.time.DateTime import timber.log.Timber import java.util.* @@ -254,6 +255,16 @@ class Task : Parcelable { recurrence = rrule.toIcal() + if (afterCompletion) ";FROM=COMPLETION" else "" } + fun setRecurrence(rrule: net.fortuna.ical4j.model.property.RRule?) { + if (rrule == null) { + repeatUntil = 0 + recurrence = null + } else { + repeatUntil = rrule.recur.until?.let { DateTime.from(it).millis } ?: 0 + recurrence = "RRULE:${rrule.value.sanitizeRRule()}" + if (repeatAfterCompletion()) ";FROM=COMPLETION" else "" + } + } + fun hasNotes(): Boolean { return !Strings.isNullOrEmpty(notes) } diff --git a/app/src/main/java/org/tasks/caldav/CaldavConverter.java b/app/src/main/java/org/tasks/caldav/CaldavConverter.java index 906ce4ff8..8795cb629 100644 --- a/app/src/main/java/org/tasks/caldav/CaldavConverter.java +++ b/app/src/main/java/org/tasks/caldav/CaldavConverter.java @@ -16,7 +16,6 @@ import java.util.Locale; import java.util.TimeZone; import net.fortuna.ical4j.model.Date; import net.fortuna.ical4j.model.DateTime; -import net.fortuna.ical4j.model.Recur; import net.fortuna.ical4j.model.property.Completed; import net.fortuna.ical4j.model.property.DtStart; import net.fortuna.ical4j.model.property.Due; @@ -48,16 +47,7 @@ public class CaldavConverter { local.setTitle(remote.getSummary()); local.setNotes(remote.getDescription()); local.setPriority(fromRemote(remote.getPriority())); - RRule repeatRule = remote.getRRule(); - if (repeatRule == null) { - local.setRecurrence(""); - } else { - Recur recur = repeatRule.getRecur(); - Date until = recur.getUntil(); - local.setRepeatUntil(until == null ? 0 : org.tasks.time.DateTime.from(until).getMillis()); - local.setRecurrence( - "RRULE:" + Task.sanitizeRRule(recur.toString()) + (local.repeatAfterCompletion() ? ";FROM=COMPLETION" : "")); - } + local.setRecurrence(remote.getRRule()); Due due = remote.getDue(); if (due == null) { local.setDueDate(0L); diff --git a/app/src/main/java/org/tasks/caldav/iCalendar.kt b/app/src/main/java/org/tasks/caldav/iCalendar.kt index 8735b8ed7..b2dfa1f81 100644 --- a/app/src/main/java/org/tasks/caldav/iCalendar.kt +++ b/app/src/main/java/org/tasks/caldav/iCalendar.kt @@ -98,7 +98,14 @@ class iCalendar @Inject constructor( } } - suspend fun setPlace(taskId: Long, geo: Geo) { + suspend fun setPlace(taskId: Long, geo: Geo?) { + if (geo == null) { + locationDao.getActiveGeofences(taskId).forEach { + locationDao.delete(it.geofence) + geofenceApi.update(it.place) + } + return + } var place: Place? = locationDao.findPlace( geo.latitude.toLikeString(), geo.longitude.toLikeString()) @@ -179,15 +186,7 @@ class iCalendar @Inject constructor( } CaldavConverter.apply(task, remote) caldavTask.order = remote.order - val geo = remote.geoPosition - if (geo == null) { - locationDao.getActiveGeofences(task.id).forEach { - locationDao.delete(it.geofence) - geofenceApi.update(it.place) - } - } else { - setPlace(task.id, geo) - } + setPlace(task.id, remote.geoPosition) tagDao.applyTags(task, tagDataDao, getTags(remote.categories)) task.suppressSync() task.suppressRefresh()