Convert CaldavTask to data class

pull/2349/head
Alex Baker 1 year ago
parent 53738031d1
commit 52d664856d

@ -40,10 +40,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"uid"
],
"autoGenerate": true
]
},
"indices": [
{
@ -118,10 +118,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"_id"
],
"autoGenerate": true
]
},
"indices": [],
"foreignKeys": []
@ -168,10 +168,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"_id"
],
"autoGenerate": true
]
},
"indices": [],
"foreignKeys": []
@ -206,10 +206,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"file_id"
],
"autoGenerate": true
]
},
"indices": [],
"foreignKeys": []
@ -244,10 +244,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"_id"
],
"autoGenerate": true
]
},
"indices": [],
"foreignKeys": []
@ -398,10 +398,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"_id"
],
"autoGenerate": true
]
},
"indices": [
{
@ -472,10 +472,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"_id"
],
"autoGenerate": true
]
},
"indices": [
{
@ -581,10 +581,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"place_id"
],
"autoGenerate": true
]
},
"indices": [
{
@ -635,10 +635,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"geofence_id"
],
"autoGenerate": true
]
},
"indices": [
{
@ -701,10 +701,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"_id"
],
"autoGenerate": true
]
},
"indices": [
{
@ -785,10 +785,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"_id"
],
"autoGenerate": true
]
},
"indices": [],
"foreignKeys": []
@ -865,17 +865,17 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"cdl_id"
],
"autoGenerate": true
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "caldav_tasks",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`cd_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `cd_task` INTEGER NOT NULL, `cd_calendar` TEXT, `cd_object` TEXT, `cd_remote_id` TEXT, `cd_etag` TEXT, `cd_last_sync` INTEGER NOT NULL, `cd_deleted` INTEGER NOT NULL, `cd_remote_parent` TEXT, `gt_moved` INTEGER NOT NULL, `gt_remote_order` INTEGER NOT NULL, FOREIGN KEY(`cd_task`) REFERENCES `tasks`(`_id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`cd_id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `cd_task` INTEGER NOT NULL, `cd_calendar` TEXT, `cd_remote_id` TEXT, `cd_object` TEXT, `cd_etag` TEXT, `cd_last_sync` INTEGER NOT NULL, `cd_deleted` INTEGER NOT NULL, `cd_remote_parent` TEXT, `gt_moved` INTEGER NOT NULL, `gt_remote_order` INTEGER NOT NULL, FOREIGN KEY(`cd_task`) REFERENCES `tasks`(`_id`) ON UPDATE NO ACTION ON DELETE CASCADE )",
"fields": [
{
"fieldPath": "id",
@ -896,14 +896,14 @@
"notNull": false
},
{
"fieldPath": "object",
"columnName": "cd_object",
"fieldPath": "remoteId",
"columnName": "cd_remote_id",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "remoteId",
"columnName": "cd_remote_id",
"fieldPath": "object",
"columnName": "cd_object",
"affinity": "TEXT",
"notNull": false
},
@ -945,10 +945,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"cd_id"
],
"autoGenerate": true
]
},
"indices": [
{
@ -1041,10 +1041,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"cda_id"
],
"autoGenerate": true
]
},
"indices": [],
"foreignKeys": []
@ -1085,10 +1085,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
],
"autoGenerate": true
]
},
"indices": [
{
@ -1152,10 +1152,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"id"
],
"autoGenerate": true
]
},
"indices": [
{
@ -1233,10 +1233,10 @@
}
],
"primaryKey": {
"autoGenerate": true,
"columnNames": [
"attachment_id"
],
"autoGenerate": true
]
},
"indices": [
{

@ -198,7 +198,7 @@ class CaldavTaskAdapterTest : InjectingTestCase() {
val t = newTaskContainer(*properties)
val task = t.task
taskDao.createNew(task)
val caldavTask = CaldavTask(t.id, "calendar")
val caldavTask = CaldavTask(task = t.id, calendar = "calendar")
if (task.parent > 0) {
caldavTask.remoteParent = caldavDao.getRemoteIdForTask(task.parent)
}
@ -207,4 +207,4 @@ class CaldavTaskAdapterTest : InjectingTestCase() {
t.copy(caldavTask = caldavTask)
)
}
}
}

@ -148,7 +148,7 @@ class CaldavDaoShiftTests : InjectingTestCase() {
val t = TaskContainerMaker.newTaskContainer(*properties)
val task = t.task
taskDao.createNew(task)
val caldavTask = CaldavTask(t.id, calendar)
val caldavTask = CaldavTask(task = t.id, calendar = calendar)
if (task.parent > 0) {
caldavTask.remoteParent = caldavDao.getRemoteIdForTask(task.parent)
}
@ -157,4 +157,4 @@ class CaldavDaoShiftTests : InjectingTestCase() {
t.copy(caldavTask = caldavTask)
)
}
}
}

@ -27,8 +27,7 @@ class CaldavDaoTests : InjectingTestCase() {
fun insertNewTaskAtTopOfEmptyList() = runBlocking {
val task = newTask()
taskDao.createNew(task)
val caldavTask = CaldavTask(task.id, "calendar")
caldavDao.insert(task, caldavTask, true)
caldavDao.insert(task, CaldavTask(task = task.id, calendar = "calendar"), true)
checkOrder(null, task.id)
}
@ -40,9 +39,8 @@ class CaldavDaoTests : InjectingTestCase() {
val second = newTask(with(CREATION_TIME, created.plusSeconds(1)))
taskDao.createNew(first)
taskDao.createNew(second)
caldavDao.insert(first, CaldavTask(first.id, "calendar"), true)
caldavDao.insert(second, CaldavTask(second.id, "calendar"), true)
caldavDao.insert(first, CaldavTask(task = first.id, calendar = "calendar"), true)
caldavDao.insert(second, CaldavTask(task = second.id, calendar = "calendar"), true)
checkOrder(null, first.id)
checkOrder(created.minusSeconds(1), second.id)
@ -55,9 +53,8 @@ class CaldavDaoTests : InjectingTestCase() {
val second = newTask(with(CREATION_TIME, created.plusSeconds(1)))
taskDao.createNew(first)
taskDao.createNew(second)
caldavDao.insert(first, CaldavTask(first.id, "calendar"), false)
caldavDao.insert(second, CaldavTask(second.id, "calendar"), false)
caldavDao.insert(first, CaldavTask(task = first.id, calendar = "calendar"), false)
caldavDao.insert(second, CaldavTask(task = second.id, calendar = "calendar"), false)
checkOrder(null, first.id)
checkOrder(null, second.id)
@ -70,9 +67,8 @@ class CaldavDaoTests : InjectingTestCase() {
val second = newTask(with(CREATION_TIME, created))
taskDao.createNew(first)
taskDao.createNew(second)
caldavDao.insert(first, CaldavTask(first.id, "calendar"), false)
caldavDao.insert(second, CaldavTask(second.id, "calendar"), false)
caldavDao.insert(first, CaldavTask(task = first.id, calendar = "calendar"), false)
caldavDao.insert(second, CaldavTask(task = second.id, calendar = "calendar"), false)
checkOrder(null, first.id)
checkOrder(created.plusSeconds(1), second.id)
@ -82,8 +78,7 @@ class CaldavDaoTests : InjectingTestCase() {
fun insertNewTaskAtBottomOfEmptyList() = runBlocking {
val task = newTask()
taskDao.createNew(task)
val caldavTask = CaldavTask(task.id, "calendar")
caldavDao.insert(task, caldavTask, false)
caldavDao.insert(task, CaldavTask(task = task.id, calendar = "calendar"), false)
checkOrder(null, task.id)
}
@ -106,4 +101,4 @@ class CaldavDaoTests : InjectingTestCase() {
assertEquals(order, sortOrder)
}
}
}
}

@ -61,7 +61,7 @@ class DeletionDaoTests : InjectingTestCase() {
val task = newTask(with(DELETION_TIME, newDateTime()))
taskDao.createNew(task)
caldavDao.insert(CaldavCalendar(name = "", uuid = "1234", account = LOCAL))
caldavDao.insert(CaldavTask(task.id, "1234"))
caldavDao.insert(CaldavTask(task = task.id, calendar = "1234"))
deletionDao.purgeDeleted()
@ -73,7 +73,7 @@ class DeletionDaoTests : InjectingTestCase() {
val task = newTask()
taskDao.createNew(task)
caldavDao.insert(CaldavCalendar(name = "", uuid = "1234", account = LOCAL))
caldavDao.insert(CaldavTask(task.id, "1234"))
caldavDao.insert(CaldavTask(task = task.id, calendar = "1234"))
deletionDao.purgeDeleted()
@ -85,10 +85,10 @@ class DeletionDaoTests : InjectingTestCase() {
val task = newTask(with(DELETION_TIME, newDateTime()))
taskDao.createNew(task)
caldavDao.insert(CaldavCalendar(name = "", uuid = "1234", account = UUIDHelper.newUUID()))
caldavDao.insert(CaldavTask(task.id, "1234"))
caldavDao.insert(CaldavTask(task = task.id, calendar = "1234"))
deletionDao.purgeDeleted()
assertNotNull(taskDao.fetch(task.id))
}
}
}

@ -35,7 +35,7 @@ class UpgraderDaoTests : InjectingTestCase() {
tagDataDao.createNew(two)
tagDao.insert(TagMaker.newTag(MakeItEasy.with(TagMaker.TASK, task), MakeItEasy.with(TagMaker.TAGDATA, one)))
tagDao.insert(TagMaker.newTag(MakeItEasy.with(TagMaker.TASK, task), MakeItEasy.with(TagMaker.TAGDATA, two)))
caldavDao.insert(CaldavTask(task.id, "calendar"))
caldavDao.insert(CaldavTask(task = task.id, calendar = "calendar"))
assertEquals(listOf(task.id), upgraderDao.tasksWithTags())
}
@ -54,7 +54,7 @@ class UpgraderDaoTests : InjectingTestCase() {
val task = TaskMaker.newTask(MakeItEasy.with(TaskMaker.ID, 1L))
taskDao.createNew(task)
tagDataDao.createNew(TagDataMaker.newTagData())
caldavDao.insert(CaldavTask(task.id, "calendar"))
caldavDao.insert(CaldavTask(task = task.id, calendar = "calendar"))
assertTrue(upgraderDao.tasksWithTags().isEmpty())
}
}
}

@ -259,7 +259,11 @@ open class TaskAdapter(
task.parent = newParent.id
googleTaskDao.insertAndShift(
task = task.task,
caldavTask = CaldavTask(task.id, list, remoteId = null),
caldavTask = CaldavTask(
task = task.id,
calendar = list,
remoteId = null
),
top = newTasksOnTop
)
}
@ -272,8 +276,8 @@ open class TaskAdapter(
private suspend fun changeCaldavParent(task: TaskContainer, newParent: TaskContainer?) {
val list = newParent?.caldav ?: task.caldav!!
val caldavTask = task.caldavTask ?: CaldavTask(
task.id,
list,
task = task.id,
calendar = list,
)
val newParentId = newParent?.id ?: 0
if (newParentId == 0L) {
@ -293,7 +297,10 @@ open class TaskAdapter(
?.plus(1)
}
if (caldavTask.id == 0L) {
val newTask = CaldavTask(task.id, list)
val newTask = CaldavTask(
task = task.id,
calendar = list,
)
newTask.remoteParent = caldavTask.remoteParent
caldavTask.id = caldavDao.insert(newTask)
} else {

@ -17,11 +17,23 @@ import com.todoroo.astrid.helper.UUIDHelper
import com.todoroo.astrid.utility.TitleParser.parse
import org.tasks.R
import org.tasks.Strings.isNullOrEmpty
import org.tasks.data.*
import org.tasks.data.Alarm
import org.tasks.data.Alarm.Companion.TYPE_RANDOM
import org.tasks.data.Alarm.Companion.whenDue
import org.tasks.data.Alarm.Companion.whenOverdue
import org.tasks.data.Alarm.Companion.whenStarted
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.Place
import org.tasks.data.Tag
import org.tasks.data.TagDao
import org.tasks.data.TagData
import org.tasks.data.TagDataDao
import org.tasks.preferences.DefaultFilterProvider
import org.tasks.preferences.Preferences
import org.tasks.time.DateTimeUtils.startOfDay
@ -56,23 +68,43 @@ class TaskCreator @Inject constructor(
if (task.hasTransitory(GoogleTask.KEY)) {
googleTaskDao.insertAndShift(
task,
CaldavTask(task.id, task.getTransitory<String>(GoogleTask.KEY)!!, remoteId = null),
CaldavTask(
task = task.id,
calendar = task.getTransitory<String>(GoogleTask.KEY)!!,
remoteId = null
),
addToTop
)
} else if (task.hasTransitory(CaldavTask.KEY)) {
caldavDao.insert(
task, CaldavTask(task.id, task.getTransitory<String>(CaldavTask.KEY)), addToTop)
task,
CaldavTask(
task = task.id,
calendar = task.getTransitory(CaldavTask.KEY),
),
addToTop
)
} else {
val remoteList = defaultFilterProvider.getDefaultList()
if (remoteList is GtasksFilter) {
googleTaskDao.insertAndShift(
task,
CaldavTask(task.id, remoteList.remoteId, remoteId = null),
CaldavTask(
task = task.id,
calendar = remoteList.remoteId,
remoteId = null
),
addToTop
)
} else if (remoteList is CaldavFilter) {
caldavDao.insert(
task, CaldavTask(task.id, remoteList.uuid), addToTop)
task,
CaldavTask(
task = task.id,
calendar = remoteList.uuid,
),
addToTop
)
}
}
if (task.hasTransitory(Place.KEY)) {

@ -5,7 +5,18 @@ import com.todoroo.astrid.dao.TaskDao
import com.todoroo.astrid.data.Task
import com.todoroo.astrid.gcal.GCalHelper
import org.tasks.LocalBroadcastManager
import org.tasks.data.*
import org.tasks.data.Alarm
import org.tasks.data.AlarmDao
import org.tasks.data.Attachment
import org.tasks.data.CaldavDao
import org.tasks.data.CaldavTask
import org.tasks.data.Geofence
import org.tasks.data.GoogleTaskDao
import org.tasks.data.LocationDao
import org.tasks.data.Tag
import org.tasks.data.TagDao
import org.tasks.data.TagDataDao
import org.tasks.data.TaskAttachmentDao
import org.tasks.db.DbUtils.dbchunk
import org.tasks.preferences.Preferences
import javax.inject.Inject
@ -59,15 +70,21 @@ class TaskDuplicator @Inject constructor(
if (googleTask != null) {
googleTaskDao.insertAndShift(
clone,
CaldavTask(clone.id, googleTask.calendar!!, remoteId = null),
CaldavTask(
task = clone.id,
calendar = googleTask.calendar,
remoteId = null
),
addToTop
)
}
val caldavTask = caldavDao.getTask(originalId)
if (caldavTask != null) {
val newDavTask = CaldavTask(clone.id, caldavTask.calendar)
if (parentId != 0L)
{
val newDavTask = CaldavTask(
task = clone.id,
calendar = caldavTask.calendar
)
if (parentId != 0L) {
val remoteParent = caldavDao.getRemoteIdForTask(parentId)
newDavTask.remoteParent = remoteParent
}

@ -107,19 +107,35 @@ class TaskMover @Inject constructor(
val listId = selected.remoteId
googleTaskDao.insertAndShift(
task = task,
caldavTask = CaldavTask(id, listId, remoteId = null),
caldavTask = CaldavTask(
task = id,
calendar = listId,
remoteId = null,
),
top = preferences.addTasksToTop()
)
children.takeIf { it.isNotEmpty() }
?.map { CaldavTask(task = it, calendar = listId, remoteId = null) }
?.map {
CaldavTask(
task = it,
calendar = listId,
remoteId = null,
)
}
?.let { googleTaskDao.insert(it) }
}
is CaldavFilter -> {
val listId = selected.uuid
val newParent = CaldavTask(id, listId)
val newParent = CaldavTask(
task = id,
calendar = listId,
)
caldavDao.insert(task, newParent, preferences.addTasksToTop())
children.map {
val newChild = CaldavTask(it, listId)
val newChild = CaldavTask(
task = it,
calendar = listId
)
newChild.remoteParent = newParent.remoteId
newChild
}.let { caldavDao.insert(it) }
@ -147,12 +163,22 @@ class TaskMover @Inject constructor(
val from = caldavDao.getCalendar(caldavTask.calendar!!)
val id1 = caldavTask.task
val listId = selected.uuid
val newParent = CaldavTask(id1, listId, caldavTask.remoteId, caldavTask.`object`)
val newParent = CaldavTask(
task = id1,
calendar = listId,
remoteId = caldavTask.remoteId,
`object` = caldavTask.`object`,
)
vtodoCache.move(from!!, selected.calendar, caldavTask)
caldavDao.insert(task, newParent, preferences.addTasksToTop())
children.takeIf { it.isNotEmpty() }
?.map {
val newChild = CaldavTask(it.task, listId, it.remoteId, it.`object`)
val newChild = CaldavTask(
task = it.task,
calendar = listId,
remoteId = it.remoteId,
`object` = it.`object`,
)
vtodoCache.move(from, selected.calendar, it)
newChild.remoteParent = it.remoteParent
newChild
@ -171,10 +197,16 @@ class TaskMover @Inject constructor(
val id = task.id
val listId = selected.uuid
val tasks: MutableMap<Long, CaldavTask> = HashMap()
val root = CaldavTask(id, listId)
val root = CaldavTask(
task = id,
calendar = listId,
)
val children = taskDao.getChildren(id).mapNotNull { taskDao.fetch(it) }
for (child in children) {
val newTask = CaldavTask(child.id, listId)
val newTask = CaldavTask(
task = child.id,
calendar = listId,
)
val parent = child.parent
newTask.remoteParent = (if (parent == id) root else tasks[parent])!!.remoteId
tasks[child.id] = newTask
@ -192,11 +224,21 @@ class TaskMover @Inject constructor(
val listId = filter.remoteId
googleTaskDao.insertAndShift(
task,
CaldavTask(id, listId, remoteId = null),
CaldavTask(
task = id,
calendar = listId,
remoteId = null
),
preferences.addTasksToTop()
)
children.takeIf { it.isNotEmpty() }
?.map { CaldavTask(it, listId, remoteId = null) }
?.map {
CaldavTask(
task = it,
calendar = listId,
remoteId = null
)
}
?.let { googleTaskDao.insert(it) }
}
}

@ -214,11 +214,10 @@ class TasksJsonImporter @Inject constructor(
task = taskId,
calendar = googleTask.listId,
remoteId = googleTask.remoteId,
).apply {
remoteOrder = googleTask.remoteOrder
remoteParent = googleTask.remoteParent
lastSync = googleTask.lastSync
}
remoteOrder = googleTask.remoteOrder,
remoteParent = googleTask.remoteParent,
lastSync = googleTask.lastSync,
)
)
}
for (location in backup.locations) {

@ -46,12 +46,13 @@ class VtodoCache @Inject constructor(
}
fun putVtodo(calendar: CaldavCalendar, caldavTask: CaldavTask, vtodo: String?) {
val `object` = caldavTask.`object`?.takeIf { it.isNotBlank() } ?: return
val directory =
fileStorage
.getFile(calendar.account, caldavTask.calendar)
?.apply { mkdirs() }
?: return
fileStorage.write(File(directory, caldavTask.`object`!!), vtodo)
fileStorage.write(File(directory, `object`), vtodo)
}
suspend fun delete(taskIds: List<Long>) {

@ -10,7 +10,6 @@ import com.todoroo.astrid.data.Task.Companion.HIDE_UNTIL_SPECIFIC_DAY
import com.todoroo.astrid.data.Task.Companion.HIDE_UNTIL_SPECIFIC_DAY_TIME
import com.todoroo.astrid.data.Task.Companion.URGENCY_SPECIFIC_DAY
import com.todoroo.astrid.data.Task.Companion.URGENCY_SPECIFIC_DAY_TIME
import com.todoroo.astrid.helper.UUIDHelper
import com.todoroo.astrid.service.TaskCreator
import com.todoroo.astrid.service.TaskCreator.Companion.getDefaultAlarms
import com.todoroo.astrid.service.TaskCreator.Companion.setDefaultReminders
@ -19,17 +18,37 @@ import net.fortuna.ical4j.model.Parameter
import net.fortuna.ical4j.model.Property
import net.fortuna.ical4j.model.component.VAlarm
import net.fortuna.ical4j.model.parameter.RelType
import net.fortuna.ical4j.model.property.*
import org.tasks.Strings.isNullOrEmpty
import net.fortuna.ical4j.model.property.Action
import net.fortuna.ical4j.model.property.Completed
import net.fortuna.ical4j.model.property.DateProperty
import net.fortuna.ical4j.model.property.DtStart
import net.fortuna.ical4j.model.property.Due
import net.fortuna.ical4j.model.property.Geo
import net.fortuna.ical4j.model.property.ProdId
import net.fortuna.ical4j.model.property.RelatedTo
import net.fortuna.ical4j.model.property.Status
import net.fortuna.ical4j.model.property.XProperty
import org.tasks.BuildConfig
import org.tasks.caldav.GeoUtils.equalish
import org.tasks.caldav.GeoUtils.toGeo
import org.tasks.caldav.GeoUtils.toLikeString
import org.tasks.caldav.extensions.toAlarms
import org.tasks.caldav.extensions.toVAlarms
import org.tasks.data.*
import org.tasks.data.Alarm
import org.tasks.data.Alarm.Companion.TYPE_RANDOM
import org.tasks.data.Alarm.Companion.TYPE_SNOOZE
import org.tasks.data.AlarmDao
import org.tasks.data.CaldavAccount
import org.tasks.data.CaldavCalendar
import org.tasks.data.CaldavCalendar.Companion.ACCESS_READ_ONLY
import org.tasks.data.CaldavDao
import org.tasks.data.CaldavTask
import org.tasks.data.Geofence
import org.tasks.data.LocationDao
import org.tasks.data.Place
import org.tasks.data.TagDao
import org.tasks.data.TagData
import org.tasks.data.TagDataDao
import org.tasks.date.DateTimeUtils.newDateTime
import org.tasks.date.DateTimeUtils.toDateTime
import org.tasks.date.DateTimeUtils.toLocal
@ -45,7 +64,7 @@ import timber.log.Timber
import java.io.ByteArrayOutputStream
import java.io.StringReader
import java.text.ParseException
import java.util.*
import java.util.TimeZone
import javax.inject.Inject
import kotlin.math.max
import kotlin.math.min
@ -151,13 +170,10 @@ class iCalendar @Inject constructor(
val categories = remoteModel.categories
categories.clear()
categories.addAll(tagDataDao.getTagDataForTask(task.id).map { it.name!! })
if (isNullOrEmpty(caldavTask.remoteId)) {
val caldavUid = UUIDHelper.newUUID()
caldavTask.remoteId = caldavUid
remoteModel.uid = caldavUid
} else {
remoteModel.uid = caldavTask.remoteId
if (BuildConfig.DEBUG && caldavTask.remoteId.isNullOrBlank()) {
throw IllegalStateException()
}
remoteModel.uid = caldavTask.remoteId
val location = locationDao.getGeofences(task.id)
val localGeo = toGeo(location)
if (localGeo == null || !localGeo.equalish(remoteModel.geoPosition)) {
@ -189,7 +205,12 @@ class iCalendar @Inject constructor(
taskDao.createNew(this)
existing?.task = id
}
val caldavTask = existing ?: CaldavTask(task.id, calendar.uuid, remote.uid, obj)
val caldavTask = existing ?: CaldavTask(
task = task.id,
calendar = calendar.uuid,
remoteId = remote.uid,
`object` = obj
)
val isNew = caldavTask.id == com.todoroo.astrid.data.Task.NO_ID
val dirty = task.modificationDate > caldavTask.lastSync || caldavTask.lastSync == 0L
val local = vtodoCache.getVtodo(calendar, caldavTask)?.let { fromVtodo(it) }

@ -1,6 +1,9 @@
package org.tasks.data
import androidx.room.*
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.ForeignKey
import androidx.room.PrimaryKey
import com.todoroo.andlib.data.Table
import com.todoroo.astrid.data.Task
import com.todoroo.astrid.helper.UUIDHelper
@ -16,67 +19,35 @@ import com.todoroo.astrid.helper.UUIDHelper
),
]
)
class CaldavTask {
data class CaldavTask(
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "cd_id")
@Transient
var id: Long = 0
var id: Long = 0,
@ColumnInfo(name = "cd_task", index = true)
@Transient
var task: Long = 0
var task: Long,
@ColumnInfo(name = "cd_calendar")
var calendar: String? = null
@ColumnInfo(name = "cd_object")
var `object`: String? = null
get() = field ?: "$remoteId.ics"
var calendar: String?,
@ColumnInfo(name = "cd_remote_id")
var remoteId: String? = null
var remoteId: String? = UUIDHelper.newUUID(),
@ColumnInfo(name = "cd_object")
var `object`: String? = remoteId?.let { "$it.ics" },
@ColumnInfo(name = "cd_etag")
var etag: String? = null
var etag: String? = null,
@ColumnInfo(name = "cd_last_sync")
var lastSync: Long = 0
var lastSync: Long = 0,
@ColumnInfo(name = "cd_deleted")
var deleted: Long = 0
var deleted: Long = 0,
@ColumnInfo(name = "cd_remote_parent")
var remoteParent: String? = null
var remoteParent: String? = null,
@ColumnInfo(name = "gt_moved")
var isMoved: Boolean = false
var isMoved: Boolean = false,
@ColumnInfo(name = "gt_remote_order")
var remoteOrder: Long = 0
constructor()
@Ignore
constructor(task: Long, calendar: String?) {
this.task = task
this.calendar = calendar
remoteId = UUIDHelper.newUUID()
`object` = "$remoteId.ics"
}
@Ignore
constructor(task: Long, calendar: String?, remoteId: String?, `object`: String? = null) {
this.task = task
this.calendar = calendar
this.remoteId = remoteId
this.`object` = `object`
}
var remoteOrder: Long = 0,
) {
fun isDeleted() = deleted > 0
override fun toString(): String =
"CaldavTask(id=$id, task=$task, calendar=$calendar, `object`=$`object`, remoteId=$remoteId, etag=$etag, lastSync=$lastSync, deleted=$deleted, remoteParent=$remoteParent, isMoved=$isMoved, remoteOrder=$remoteOrder)"
companion object {
const val KEY = "caldav"
@JvmField val TABLE = Table("caldav_tasks")

@ -311,7 +311,11 @@ class GoogleTaskSynchronizer @Inject constructor(
var googleTask = googleTaskDao.getByRemoteId(remoteId)
var task: com.todoroo.astrid.data.Task? = null
if (googleTask == null) {
googleTask = CaldavTask(0, "", remoteId = null)
googleTask = CaldavTask(
task = 0,
calendar = "",
remoteId = null,
)
} else if (googleTask.task > 0) {
task = taskDao.fetch(googleTask.task)
}

@ -317,15 +317,22 @@ class TaskEditViewModel @Inject constructor(
taskDao.createNew(subtask)
alarmDao.insert(subtask.getDefaultAlarms())
firebase?.addTask("subtasks")
when (selectedList.value) {
when (val filter = selectedList.value) {
is GtasksFilter -> {
val googleTask = CaldavTask(subtask.id, (selectedList.value as GtasksFilter).remoteId, remoteId = null)
val googleTask = CaldavTask(
task = subtask.id,
calendar = filter.remoteId,
remoteId = null,
)
subtask.parent = task.id
googleTask.isMoved = true
googleTaskDao.insertAndShift(subtask, googleTask, false)
}
is CaldavFilter -> {
val caldavTask = CaldavTask(subtask.id, (selectedList.value as CaldavFilter).uuid)
val caldavTask = CaldavTask(
task = subtask.id,
calendar = filter.uuid,
)
subtask.parent = task.id
caldavTask.remoteParent = caldavDao.getRemoteIdForTask(task.id)
taskDao.save(subtask)

@ -16,7 +16,7 @@ import org.tasks.time.DateTime
import java.io.StringReader
import java.nio.file.Files
import java.nio.file.Paths
import java.util.*
import java.util.TimeZone
object TestUtilities {
fun withTZ(id: String, runnable: suspend () -> Unit) =
@ -57,7 +57,7 @@ object TestUtilities {
val task = Task()
val remote = icalendarFromFile(path)
task.applyRemote(remote, null)
return Triple(task, CaldavTask(), remote)
return Triple(task, CaldavTask(task = 0, calendar = null), remote)
}
fun icalendarFromFile(path: String): at.bitfire.ical4android.Task =

@ -4,6 +4,7 @@ import com.natpryce.makeiteasy.Instantiator
import com.natpryce.makeiteasy.Property
import com.natpryce.makeiteasy.Property.newProperty
import com.natpryce.makeiteasy.PropertyValue
import com.todoroo.astrid.helper.UUIDHelper
import org.tasks.data.CaldavTask
import org.tasks.makers.Maker.make
@ -16,12 +17,15 @@ object CaldavTaskMaker {
val OBJECT: Property<CaldavTask, String?> = newProperty()
private val instantiator = Instantiator {
val task = CaldavTask(it.valueOf(TASK, 1L), it.valueOf(CALENDAR, "calendar"))
task.remoteId = it.valueOf(REMOTE_ID, task.remoteId)
task.remoteParent = it.valueOf(REMOTE_PARENT, null as String?)
task.etag = it.valueOf(ETAG, null as String?)
task.`object` = it.valueOf(OBJECT, task.remoteId?.let { id -> "$id.ics" })
task
val remoteId = it.valueOf(REMOTE_ID, UUIDHelper.newUUID())
CaldavTask(
task = it.valueOf(TASK, 1L),
calendar = it.valueOf(CALENDAR, "calendar"),
remoteId = remoteId,
remoteParent = it.valueOf(REMOTE_PARENT, null as String?),
etag = it.valueOf(ETAG, null as String?),
`object` = it.valueOf(OBJECT, remoteId?.let { id -> "$id.ics" }),
)
}
fun newCaldavTask(vararg properties: PropertyValue<in CaldavTask?, *>): CaldavTask {

Loading…
Cancel
Save