Create and use removeIfCompat
(#4961)
This commit is contained in:
parent
13881a589a
commit
961f821ab9
@ -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 <E> MutableCollection<E>.removeIfCompat(predicate: (E) -> Boolean) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
removeIf(predicate)
|
||||
} else {
|
||||
removeAll(filter(predicate).toSet())
|
||||
}
|
||||
}
|
@ -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 }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user