From c15f90a0e744ac76191e4e9f76cfc41e32ff71f3 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 17 Jan 2022 11:48:58 +0100 Subject: [PATCH 1/3] Remove temporary change on the "NewApi" lint error. --- vector/lint.xml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/vector/lint.xml b/vector/lint.xml index 818349da240..f02090489c1 100644 --- a/vector/lint.xml +++ b/vector/lint.xml @@ -40,6 +40,7 @@ + @@ -82,10 +83,6 @@ - - - - From 414d871ad559081463d622340048c3dcc22d3f5f Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 17 Jan 2022 12:47:17 +0100 Subject: [PATCH 2/3] Create and use `removeIfCompat` (#4961) --- .../utils/compat/MutableCollectionCompat.kt | 27 +++++++++++++++++++ .../analytics/DecryptionFailureTracker.kt | 5 ++-- .../reactions/EmojiRecyclerAdapter.kt | 10 ++----- 3 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 library/core-utils/src/main/java/im/vector/lib/core/utils/compat/MutableCollectionCompat.kt diff --git a/library/core-utils/src/main/java/im/vector/lib/core/utils/compat/MutableCollectionCompat.kt b/library/core-utils/src/main/java/im/vector/lib/core/utils/compat/MutableCollectionCompat.kt new file mode 100644 index 00000000000..332ed27ca32 --- /dev/null +++ b/library/core-utils/src/main/java/im/vector/lib/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.lib.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 eb2a99fdd43..8b9dcc348bc 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 @@ -18,6 +18,7 @@ package im.vector.app.features.analytics import im.vector.app.core.time.Clock import im.vector.app.features.analytics.plan.Error +import im.vector.lib.core.utils.compat.removeIfCompat import im.vector.lib.core.utils.flow.tickerFlow import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -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 d64ee0f7054..5c0d2f36f5e 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.lib.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) } From 8f30e84c287151f2ee17c1c47f85babed1a5f41a Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Mon, 17 Jan 2022 12:50:44 +0100 Subject: [PATCH 3/3] Changelog --- changelog.d/4962.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/4962.bugfix diff --git a/changelog.d/4962.bugfix b/changelog.d/4962.bugfix new file mode 100644 index 00000000000..489f91cfc3b --- /dev/null +++ b/changelog.d/4962.bugfix @@ -0,0 +1 @@ +Fix crash on API <24 and make sure this error will not occur again. \ No newline at end of file