Invert google task adapter hierarchy

pull/996/head
Alex Baker 4 years ago
parent 6b2cc35a24
commit 61c7f2f0e8

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

@ -3,33 +3,8 @@ 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
open class GoogleTaskManualSortAdapter internal constructor(val taskDao: TaskDao, val googleTaskDao: GoogleTaskDao) : TaskAdapter() { class GoogleTaskManualSortAdapter internal constructor(val taskDao: TaskDao, val googleTaskDao: GoogleTaskDao) : GoogleTaskAdapter(taskDao, googleTaskDao, 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 supportsManualSorting() = true override fun supportsManualSorting() = true

Loading…
Cancel
Save