Uncomplete parents when subtask is uncompleted

pull/1736/head
Alex Baker 2 years ago
parent fa9cb460cc
commit 1edd9b8c5d

@ -80,6 +80,8 @@ class TaskDao @Inject constructor(
suspend fun getChildren(id: Long): List<Long> = taskDao.getChildren(id)
suspend fun getParents(parent: Long): List<Long> = taskDao.getParents(parent)
suspend fun setCollapsed(id: Long, collapsed: Boolean) {
taskDao.setCollapsed(listOf(id), collapsed)
syncAdapters.sync()

@ -30,12 +30,23 @@ class TaskCompleter @Inject internal constructor(
val completionDate = if (completed) DateUtilities.now() else 0L
googleTaskDao
.getChildTasks(item.id)
.plus(taskDao.getChildren(item.id)
.takeIf { it.isNotEmpty() }
?.let { taskDao.fetch(it) }
?: emptyList()
.let {
if (completed) {
it
} else {
it
.plus(googleTaskDao.getParentTask(item.id))
.plus(taskDao.getParents(item.id).mapNotNull { ids -> taskDao.fetch(ids) })
}
}
.plus(
taskDao.getChildren(item.id)
.takeIf { it.isNotEmpty() }
?.let { taskDao.fetch(it) }
?: emptyList()
)
.plus(listOf(item))
.filterNotNull()
.filter { it.isCompleted != completionDate > 0 }
.let { setComplete(it, completionDate) }
}

@ -1,6 +1,12 @@
package org.tasks.data
import androidx.room.*
import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.Query
import androidx.room.RoomWarnings
import androidx.room.Transaction
import androidx.room.Update
import com.todoroo.astrid.data.Task
import org.tasks.db.SuspendDbUtils.chunkedMap
import org.tasks.time.DateTimeUtils.currentTimeMillis
@ -110,6 +116,9 @@ WHERE gt_task IN (:ids)
@Query("SELECT tasks.* FROM tasks JOIN google_tasks ON tasks._id = gt_task WHERE gt_parent = :taskId")
abstract suspend fun getChildTasks(taskId: Long): List<Task>
@Query("SELECT tasks.* FROM tasks JOIN google_tasks ON tasks._id = gt_parent WHERE gt_task = :taskId")
abstract suspend fun getParentTask(taskId: Long): Task?
@Query("SELECT * FROM google_tasks WHERE gt_parent = :id AND gt_deleted = 0")
abstract suspend fun getChildren(id: Long): List<GoogleTask>

@ -174,6 +174,19 @@ FROM recursive_tasks
""")
abstract suspend fun getChildren(ids: List<Long>): List<Long>
@Query("""
WITH RECURSIVE recursive_tasks (task, parent) AS (
SELECT _id, parent FROM tasks WHERE _id = :parent
UNION ALL
SELECT _id, tasks.parent FROM tasks
INNER JOIN recursive_tasks ON recursive_tasks.parent = tasks._id
WHERE tasks.deleted = 0
)
SELECT task
FROM recursive_tasks
""")
abstract suspend fun getParents(parent: Long): List<Long>
internal suspend fun setCollapsed(preferences: Preferences, filter: Filter, collapsed: Boolean) {
fetchTasks(preferences, filter)
.filter(TaskContainer::hasChildren)

Loading…
Cancel
Save