Remove SubsetCaldav

pull/2146/head
Alex Baker 3 years ago
parent ac62b4f385
commit f6ca98e096

@ -48,14 +48,14 @@ class CaldavManualSortTaskAdapter internal constructor(
private suspend fun changeParent(task: TaskContainer, newParent: Long) { private suspend fun changeParent(task: TaskContainer, newParent: Long) {
val caldavTask = task.getCaldavTask() val caldavTask = task.getCaldavTask()
if (newParent == 0L) { if (newParent == 0L) {
caldavTask.cd_remote_parent = "" caldavTask.remoteParent = ""
task.parent = 0 task.parent = 0
} else { } else {
val parentTask = caldavDao.getTask(newParent) ?: return val parentTask = caldavDao.getTask(newParent) ?: return
caldavTask.cd_remote_parent = parentTask.remoteId caldavTask.remoteParent = parentTask.remoteId
task.parent = newParent task.parent = newParent
} }
caldavDao.update(caldavTask.cd_id, caldavTask.cd_remote_parent) caldavDao.update(caldavTask.id, caldavTask.remoteParent)
taskDao.save(task.getTask(), null) taskDao.save(task.getTask(), null)
} }
} }

@ -246,15 +246,10 @@ open class TaskAdapter(
if (newTasksOnTop) 0 else googleTaskDao.getBottom(list, newParent?.id ?: 0) if (newTasksOnTop) 0 else googleTaskDao.getBottom(list, newParent?.id ?: 0)
) )
} else { } else {
val googleTask = CaldavTask(task.id, list) task.caldavTask = CaldavTask(task.id, list).apply {
googleTask.parent = newParent.id parent = newParent.id
googleTaskDao.insertAndShift(googleTask, newTasksOnTop)
task.caldavTask = SubsetCaldav().apply {
cd_id = googleTask.id
cd_calendar = googleTask.calendar
cd_order = googleTask.order ?: 0
gt_parent = googleTask.parent
} }
googleTaskDao.insertAndShift(task.caldavTask, newTasksOnTop)
} }
taskDao.touch(task.id) taskDao.touch(task.id)
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
@ -264,14 +259,17 @@ open class TaskAdapter(
private suspend fun changeCaldavParent(task: TaskContainer, newParent: TaskContainer?) { private suspend fun changeCaldavParent(task: TaskContainer, newParent: TaskContainer?) {
val list = newParent?.caldav ?: task.caldav!! val list = newParent?.caldav ?: task.caldav!!
val caldavTask = task.getCaldavTask() ?: SubsetCaldav() val caldavTask = task.getCaldavTask() ?: CaldavTask(
task.id,
list,
)
val newParentId = newParent?.id ?: 0 val newParentId = newParent?.id ?: 0
if (newParentId == 0L) { if (newParentId == 0L) {
caldavTask.cd_remote_parent = "" caldavTask.remoteParent = ""
} else { } else {
val parentTask = caldavDao.getTask(newParentId) ?: return val parentTask = caldavDao.getTask(newParentId) ?: return
caldavTask.cd_calendar = list caldavTask.calendar = list
caldavTask.cd_remote_parent = parentTask.remoteId caldavTask.remoteParent = parentTask.remoteId
} }
task.task.order = if (newTasksOnTop) { task.task.order = if (newTasksOnTop) {
caldavDao.findFirstTask(list, newParentId) caldavDao.findFirstTask(list, newParentId)
@ -282,10 +280,10 @@ open class TaskAdapter(
?.takeIf { task.creationDate.toAppleEpoch() <= it } ?.takeIf { task.creationDate.toAppleEpoch() <= it }
?.plus(1) ?.plus(1)
} }
if (caldavTask.cd_id == 0L) { if (caldavTask.id == 0L) {
val newTask = CaldavTask(task.id, list) val newTask = CaldavTask(task.id, list)
newTask.remoteParent = caldavTask.cd_remote_parent newTask.remoteParent = caldavTask.remoteParent
caldavTask.cd_id = caldavDao.insert(newTask) caldavTask.id = caldavDao.insert(newTask)
task.caldavTask = caldavTask task.caldavTask = caldavTask
} else { } else {
caldavDao.update(caldavTask) caldavDao.update(caldavTask)

@ -142,10 +142,6 @@ WHERE cd_calendar = :calendar
@Update @Update
abstract suspend fun updateTasks(tasks: Iterable<Task>) abstract suspend fun updateTasks(tasks: Iterable<Task>)
suspend fun update(caldavTask: SubsetCaldav) {
update(caldavTask.cd_id, caldavTask.cd_remote_parent)
}
@Query("UPDATE caldav_tasks SET cd_remote_parent = :remoteParent WHERE cd_id = :id") @Query("UPDATE caldav_tasks SET cd_remote_parent = :remoteParent WHERE cd_id = :id")
internal abstract suspend fun update(id: Long, remoteParent: String?) internal abstract suspend fun update(id: Long, remoteParent: String?)

@ -38,21 +38,21 @@ abstract class GoogleTaskDao {
internal abstract suspend fun shiftUp(listId: String, parent: Long, position: Long) internal abstract suspend fun shiftUp(listId: String, parent: Long, position: Long)
@Transaction @Transaction
open suspend fun move(task: SubsetCaldav, newParent: Long, newPosition: Long) { open suspend fun move(task: CaldavTask, newParent: Long, newPosition: Long) {
val previousParent = task.gt_parent val previousParent = task.parent
val previousPosition = task.cd_order!! val previousPosition = task.order!!
if (newParent == previousParent) { if (newParent == previousParent) {
if (previousPosition < newPosition) { if (previousPosition < newPosition) {
shiftUp(task.cd_calendar!!, newParent, previousPosition, newPosition) shiftUp(task.calendar!!, newParent, previousPosition, newPosition)
} else { } else {
shiftDown(task.cd_calendar!!, newParent, previousPosition, newPosition) shiftDown(task.calendar!!, newParent, previousPosition, newPosition)
} }
} else { } else {
shiftUp(task.cd_calendar!!, previousParent, previousPosition) shiftUp(task.calendar!!, previousParent, previousPosition)
shiftDown(task.cd_calendar!!, newParent, newPosition) shiftDown(task.calendar!!, newParent, newPosition)
} }
task.gt_parent = newParent task.parent = newParent
task.cd_order = newPosition task.order = newPosition
update(task) update(task)
} }
@ -65,10 +65,6 @@ abstract class GoogleTaskDao {
@Update @Update
abstract suspend fun update(googleTask: CaldavTask) abstract suspend fun update(googleTask: CaldavTask)
private suspend fun update(googleTask: SubsetCaldav) {
update(googleTask.cd_id, googleTask.gt_parent, googleTask.cd_order!!)
}
@Query("UPDATE caldav_tasks SET cd_order = :order, gt_parent = :parent, gt_moved = 1 WHERE cd_id = :id") @Query("UPDATE caldav_tasks SET cd_order = :order, gt_parent = :parent, gt_moved = 1 WHERE cd_id = :id")
abstract suspend fun update(id: Long, parent: Long, order: Long) abstract suspend fun update(id: Long, parent: Long, order: Long)

@ -1,34 +0,0 @@
package org.tasks.data
class SubsetCaldav {
var cd_id: Long = 0
var cd_calendar: String? = null
var cd_remote_parent: String? = null
var gt_parent: Long = 0
var cd_order: Long? = null
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is SubsetCaldav) return false
if (cd_id != other.cd_id) return false
if (cd_calendar != other.cd_calendar) return false
if (cd_remote_parent != other.cd_remote_parent) return false
if (gt_parent != other.gt_parent) return false
if (cd_order != other.cd_order) return false
return true
}
override fun hashCode(): Int {
var result = cd_id.hashCode()
result = 31 * result + (cd_calendar?.hashCode() ?: 0)
result = 31 * result + (cd_remote_parent?.hashCode() ?: 0)
result = 31 * result + (gt_parent.hashCode())
result = 31 * result + (cd_order.hashCode())
return result
}
override fun toString(): String =
"SubsetCaldav(cd_id=$cd_id, cd_calendar=$cd_calendar, cd_remote_parent=$cd_remote_parent, gt_parent=$gt_parent, cd_order=$cd_order)"
}

@ -7,7 +7,7 @@ import java.util.Objects;
public class TaskContainer { public class TaskContainer {
@Embedded public Task task; @Embedded public Task task;
@Embedded public SubsetCaldav caldavTask; @Embedded public CaldavTask caldavTask;
@Embedded public Location location; @Embedded public Location location;
public boolean isGoogleTask; public boolean isGoogleTask;
public boolean parentComplete; public boolean parentComplete;
@ -24,7 +24,10 @@ public class TaskContainer {
} }
public @Nullable String getCaldav() { public @Nullable String getCaldav() {
return caldavTask.getCd_calendar(); if (caldavTask != null) {
return caldavTask.getCalendar();
}
return null;
} }
public boolean isCaldavTask() { public boolean isCaldavTask() {
@ -173,7 +176,7 @@ public class TaskContainer {
public long getParent() { public long getParent() {
if (isGoogleTask) { if (isGoogleTask) {
return caldavTask.getGt_parent(); return caldavTask.getParent();
} else { } else {
return task.getParent(); return task.getParent();
} }
@ -181,7 +184,7 @@ public class TaskContainer {
public void setParent(long parent) { public void setParent(long parent) {
if (isGoogleTask) { if (isGoogleTask) {
caldavTask.setGt_parent(parent); caldavTask.setParent(parent);
} else { } else {
task.setParent(parent); task.setParent(parent);
} }
@ -195,7 +198,7 @@ public class TaskContainer {
return children > 0; return children > 0;
} }
public SubsetCaldav getCaldavTask() { public CaldavTask getCaldavTask() {
return caldavTask; return caldavTask;
} }

Loading…
Cancel
Save