diff --git a/vector/src/main/java/im/vector/app/core/utils/compat/MutableCollectionCompat.kt b/vector/src/main/java/im/vector/app/core/utils/compat/MutableCollectionCompat.kt new file mode 100644 index 0000000000..e131b5f328 --- /dev/null +++ b/vector/src/main/java/im/vector/app/core/utils/compat/MutableCollectionCompat.kt @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2022 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.core.utils.compat + +import android.os.Build + +fun MutableCollection.removeIfCompat(predicate: (E) -> Boolean) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + removeIf(predicate) + } else { + removeAll(filter(predicate).toSet()) + } +} diff --git a/vector/src/main/java/im/vector/app/features/analytics/DecryptionFailureTracker.kt b/vector/src/main/java/im/vector/app/features/analytics/DecryptionFailureTracker.kt index cd98356445..ec11702054 100644 --- a/vector/src/main/java/im/vector/app/features/analytics/DecryptionFailureTracker.kt +++ b/vector/src/main/java/im/vector/app/features/analytics/DecryptionFailureTracker.kt @@ -19,6 +19,7 @@ package im.vector.app.features.analytics import im.vector.app.core.flow.tickerFlow import im.vector.app.core.time.Clock import im.vector.app.features.analytics.plan.Error +import im.vector.app.core.utils.compat.removeIfCompat import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob @@ -89,7 +90,7 @@ class DecryptionFailureTracker @Inject constructor( fun onTimeLineDisposed(roomId: String) { scope.launch(Dispatchers.Default) { synchronized(failures) { - failures.removeIf { it.roomId == roomId } + failures.removeIfCompat { it.roomId == roomId } } } } @@ -105,7 +106,7 @@ class DecryptionFailureTracker @Inject constructor( private fun removeFailureForEventId(eventId: String) { synchronized(failures) { - failures.removeIf { it.failedEventId == eventId } + failures.removeIfCompat { it.failedEventId == eventId } } } diff --git a/vector/src/main/java/im/vector/app/features/reactions/EmojiRecyclerAdapter.kt b/vector/src/main/java/im/vector/app/features/reactions/EmojiRecyclerAdapter.kt index d64ee0f705..6abbbe29af 100644 --- a/vector/src/main/java/im/vector/app/features/reactions/EmojiRecyclerAdapter.kt +++ b/vector/src/main/java/im/vector/app/features/reactions/EmojiRecyclerAdapter.kt @@ -32,6 +32,7 @@ import androidx.transition.AutoTransition import androidx.transition.TransitionManager import im.vector.app.R import im.vector.app.features.reactions.data.EmojiData +import im.vector.app.core.utils.compat.removeIfCompat import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -215,14 +216,7 @@ class EmojiRecyclerAdapter @Inject constructor() : override fun onViewRecycled(holder: ViewHolder) { if (holder is EmojiViewHolder) { holder.data = null - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { - toUpdateWhenNotBusy.removeIf { it.second == holder } - } else { - val index = toUpdateWhenNotBusy.indexOfFirst { it.second == holder } - if (index != -1) { - toUpdateWhenNotBusy.removeAt(index) - } - } + toUpdateWhenNotBusy.removeIfCompat { it.second == holder } } super.onViewRecycled(holder) }