|
|
@ -3,9 +3,33 @@ package com.todoroo.astrid.adapter
|
|
|
|
import com.todoroo.astrid.dao.TaskDao
|
|
|
|
import com.todoroo.astrid.dao.TaskDao
|
|
|
|
import org.tasks.BuildConfig
|
|
|
|
import org.tasks.BuildConfig
|
|
|
|
import org.tasks.data.GoogleTaskDao
|
|
|
|
import org.tasks.data.GoogleTaskDao
|
|
|
|
|
|
|
|
import org.tasks.data.TaskContainer
|
|
|
|
|
|
|
|
|
|
|
|
class GoogleTaskAdapter internal constructor(taskDao: TaskDao, googleTaskDao: GoogleTaskDao, private val newTasksOnTop: Boolean) : GoogleTaskManualSortAdapter(taskDao, googleTaskDao) {
|
|
|
|
open class GoogleTaskAdapter internal constructor(private val taskDao: TaskDao, private val googleTaskDao: GoogleTaskDao, private val newTasksOnTop: Boolean) : TaskAdapter() {
|
|
|
|
override fun supportsManualSorting() = false
|
|
|
|
|
|
|
|
|
|
|
|
override fun canMove(source: TaskContainer, from: Int, target: TaskContainer, to: Int): Boolean {
|
|
|
|
|
|
|
|
return if (!source.hasChildren() || to <= 0 || to >= count - 1) {
|
|
|
|
|
|
|
|
true
|
|
|
|
|
|
|
|
} else if (from < to) {
|
|
|
|
|
|
|
|
when {
|
|
|
|
|
|
|
|
target.hasChildren() -> false
|
|
|
|
|
|
|
|
target.hasParent() -> !getTask(to + 1).hasParent()
|
|
|
|
|
|
|
|
else -> true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
when {
|
|
|
|
|
|
|
|
target.hasChildren() -> true
|
|
|
|
|
|
|
|
target.hasParent() -> target.parent == source.id && target.secondarySort == 0L
|
|
|
|
|
|
|
|
else -> true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun maxIndent(previousPosition: Int, task: TaskContainer) = if (task.hasChildren()) 0 else 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun minIndent(nextPosition: Int, task: TaskContainer) = if (task.hasChildren() || !getTask(nextPosition).hasParent()) 0 else 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun supportsParentingOrManualSort() = true
|
|
|
|
|
|
|
|
|
|
|
|
override fun moved(from: Int, to: Int, indent: Int) {
|
|
|
|
override fun moved(from: Int, to: Int, indent: Int) {
|
|
|
|
val task = getTask(from)
|
|
|
|
val task = getTask(from)
|
|
|
|