Make some caldav recur and geo code reusable

pull/1061/head
Alex Baker 4 years ago
parent a21df189fd
commit 15637e784e

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

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

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

Loading…
Cancel
Save