Launch coroutine in cleared method

pull/1061/head
Alex Baker 5 years ago
parent 1178b8f3e6
commit 9af9dd4115

@ -13,9 +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.NonCancellable
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
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
@ -215,14 +213,18 @@ class DragAndDropRecyclerAdapter(
if (from < to) { if (from < to) {
to++ to++
} }
vh.task.setIndent(targetIndent) scope.launch {
vh.indent = targetIndent vh.task.setIndent(targetIndent)
moved(from, to, targetIndent) vh.indent = targetIndent
moved(from, to, targetIndent)
}
} else if (task.getIndent() != targetIndent) { } else if (task.getIndent() != targetIndent) {
val position = vh.adapterPosition scope.launch {
vh.task.setIndent(targetIndent) val position = vh.adapterPosition
vh.indent = targetIndent vh.task.setIndent(targetIndent)
moved(position, position, targetIndent) vh.indent = targetIndent
moved(position, position, targetIndent)
}
} }
} }
from = -1 from = -1
@ -234,7 +236,7 @@ class DragAndDropRecyclerAdapter(
throw UnsupportedOperationException() throw UnsupportedOperationException()
} }
private fun moved(fromOrig: Int, to: Int, indent: Int) { private suspend 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)) {
@ -242,14 +244,10 @@ class DragAndDropRecyclerAdapter(
} else { } else {
from from
} }
scope.launch { adapter.moved(from, to, indent)
withContext(NonCancellable) { val task: TaskContainer = items.removeAt(from)
adapter.moved(from, to, indent) items.add(if (from < to) to - 1 else to, task)
} taskList.loadTaskListContent()
val task: TaskContainer = items.removeAt(from)
items.add(if (from < to) to - 1 else to, task)
taskList.loadTaskListContent()
}
} }
} }

Loading…
Cancel
Save