Perform drag and drop changes on main thread

pull/1061/head
Alex Baker 4 years ago
parent 97264545d8
commit 5acceb6314

@ -13,7 +13,7 @@ import com.todoroo.astrid.adapter.TaskAdapter
import com.todoroo.astrid.utility.Flags import com.todoroo.astrid.utility.Flags
import io.reactivex.disposables.CompositeDisposable import io.reactivex.disposables.CompositeDisposable
import io.reactivex.subjects.PublishSubject import io.reactivex.subjects.PublishSubject
import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking
import org.tasks.activities.DragAndDropDiffer import org.tasks.activities.DragAndDropDiffer
import org.tasks.data.TaskContainer import org.tasks.data.TaskContainer
import org.tasks.preferences.Preferences import org.tasks.preferences.Preferences
@ -213,18 +213,14 @@ class DragAndDropRecyclerAdapter(
if (from < to) { if (from < to) {
to++ to++
} }
scope.launch { vh.task.setIndent(targetIndent)
vh.task.setIndent(targetIndent) vh.indent = targetIndent
vh.indent = targetIndent moved(from, to, targetIndent)
moved(from, to, targetIndent)
}
} else if (task.getIndent() != targetIndent) { } else if (task.getIndent() != targetIndent) {
scope.launch { val position = vh.adapterPosition
val position = vh.adapterPosition vh.task.setIndent(targetIndent)
vh.task.setIndent(targetIndent) vh.indent = targetIndent
vh.indent = targetIndent moved(position, position, targetIndent)
moved(position, position, targetIndent)
}
} }
} }
from = -1 from = -1
@ -236,7 +232,7 @@ class DragAndDropRecyclerAdapter(
throw UnsupportedOperationException() throw UnsupportedOperationException()
} }
private suspend fun moved(fromOrig: Int, to: Int, indent: Int) { private fun moved(fromOrig: Int, to: Int, indent: Int) {
val from = if (fromOrig == to) { val from = if (fromOrig == to) {
to to
} else if (fromOrig > to && isHeader(fromOrig)) { } else if (fromOrig > to && isHeader(fromOrig)) {
@ -244,7 +240,10 @@ class DragAndDropRecyclerAdapter(
} else { } else {
from from
} }
adapter.moved(from, to, indent) runBlocking {
// too much state change happens here, need to rewrite a bunch of stuff
adapter.moved(from, to, indent)
}
val task: TaskContainer = items.removeAt(from) val task: TaskContainer = items.removeAt(from)
items.add(if (from < to) to - 1 else to, task) items.add(if (from < to) to - 1 else to, task)
taskList.loadTaskListContent() taskList.loadTaskListContent()

Loading…
Cancel
Save