Skip to content

Commit 8cabc0c

Browse files
Cancel previous formatList(…) when starting a new one, to avoid race condition when marking Thread as seen
1 parent 390a3cd commit 8cabc0c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

app/src/main/java/com/infomaniak/mail/ui/main/folder/ThreadListAdapter.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@ import com.infomaniak.mail.utils.RealmChangesBinding
5959
import com.infomaniak.mail.utils.Utils.runCatchingRealm
6060
import com.infomaniak.mail.utils.extensions.*
6161
import dagger.hilt.android.qualifiers.ActivityContext
62-
import kotlinx.coroutines.CoroutineScope
63-
import kotlinx.coroutines.Dispatchers
64-
import kotlinx.coroutines.invoke
65-
import kotlinx.coroutines.launch
62+
import kotlinx.coroutines.*
6663
import javax.inject.Inject
6764
import kotlin.math.abs
6865
import com.google.android.material.R as RMaterial
@@ -75,6 +72,7 @@ class ThreadListAdapter @Inject constructor(
7572
private val globalCoroutineScope: CoroutineScope,
7673
) : DragDropSwipeAdapter<Any, ThreadListViewHolder>(mutableListOf()), RealmChangesBinding.OnRealmChanged<Thread> {
7774

75+
private var formatListJob: Job? = null
7876
private lateinit var recyclerView: RecyclerView
7977

8078
override val realmAsyncListDiffer: AsyncListDiffer<Thread>? = null
@@ -556,7 +554,9 @@ class ThreadListAdapter @Inject constructor(
556554
override fun createDiffUtil(oldList: List<Any>, newList: List<Any>): DragDropSwipeDiffCallback<Any>? = null
557555

558556
override fun updateList(itemList: List<Thread>) {
559-
globalCoroutineScope.launch {
557+
558+
formatListJob?.cancel()
559+
formatListJob = globalCoroutineScope.launch {
560560

561561
val formattedList = runCatchingRealm {
562562
formatList(itemList, recyclerView.context, folderRole, localSettings.threadDensity).apply {

0 commit comments

Comments
 (0)