From fe48285be8e50dc009d594d1d674f35a662d69fb Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Wed, 29 Dec 2021 13:46:24 -0600 Subject: [PATCH] Fix drag and drop differ --- .../org/tasks/activities/DragAndDropDiffer.kt | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/org/tasks/activities/DragAndDropDiffer.kt b/app/src/main/java/org/tasks/activities/DragAndDropDiffer.kt index a2f5eda47..bbd718f7b 100644 --- a/app/src/main/java/org/tasks/activities/DragAndDropDiffer.kt +++ b/app/src/main/java/org/tasks/activities/DragAndDropDiffer.kt @@ -48,15 +48,18 @@ interface DragAndDropDiffer : ListUpdateCallback { @ExperimentalCoroutinesApi fun initializeDiffer(list: List): R { val initial = transform(list) - scope.launch(Dispatchers.Main) { - flow - .scan(Pair(initial, null), { last: Pair, next: R -> - calculateDiff(last, next) - }) - .drop(1) - .flowOn(Executors.newSingleThreadExecutor().asCoroutineDispatcher()) - .collect { applyDiff(it) } - } + flow + .scan(Pair(initial, null), { last: Pair, next: R -> + calculateDiff(last, next) + }) + .drop(1) + .flowOn(Executors.newSingleThreadExecutor().asCoroutineDispatcher()) + .onEach { + withContext(Dispatchers.Main) { + applyDiff(it) + } + } + .launchIn(scope) return initial }