From 0fee37ced7cde0da3ef496d8d7ce2ee9fb479e46 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 27 Sep 2022 18:13:36 +0200 Subject: [PATCH 01/80] API 33 --- dependencies.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dependencies.gradle b/dependencies.gradle index ab2a5b4a6f..dc901bfb98 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -1,8 +1,8 @@ ext.versions = [ 'minSdk' : 21, - 'compileSdk' : 32, - 'targetSdk' : 32, + 'compileSdk' : 33, + 'targetSdk' : 33, 'sourceCompat' : JavaVersion.VERSION_11, 'targetCompat' : JavaVersion.VERSION_11, ] From 4677c474ebf3282de9c1bdfdfe459708145bc982 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 28 Sep 2022 10:05:56 +0200 Subject: [PATCH 02/80] androidx.core:core-ktx:1.9.0 --- dependencies.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies.gradle b/dependencies.gradle index dc901bfb98..41a2ffc4bb 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -54,7 +54,7 @@ ext.libs = [ 'activity' : "androidx.activity:activity:1.5.1", 'appCompat' : "androidx.appcompat:appcompat:1.5.1", 'biometric' : "androidx.biometric:biometric:1.1.0", - 'core' : "androidx.core:core-ktx:1.8.0", + 'core' : "androidx.core:core-ktx:1.9.0", 'recyclerview' : "androidx.recyclerview:recyclerview:1.2.1", 'exifinterface' : "androidx.exifinterface:exifinterface:1.3.3", 'fragmentKtx' : "androidx.fragment:fragment-ktx:$fragment", From 933d84a23091d6ad2df7f0e07450d0e9257ac20e Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 28 Sep 2022 10:06:30 +0200 Subject: [PATCH 03/80] androidx.activity:activity:1.6.0 --- dependencies.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies.gradle b/dependencies.gradle index 41a2ffc4bb..ae66f81ffa 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -51,7 +51,7 @@ ext.libs = [ 'coroutinesTest' : "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinCoroutines" ], androidx : [ - 'activity' : "androidx.activity:activity:1.5.1", + 'activity' : "androidx.activity:activity:1.6.0", 'appCompat' : "androidx.appcompat:appcompat:1.5.1", 'biometric' : "androidx.biometric:biometric:1.1.0", 'core' : "androidx.core:core-ktx:1.9.0", From 9d02072ad91abea1d2e8cafb50af0c8d08e4a1e1 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 28 Sep 2022 10:11:15 +0200 Subject: [PATCH 04/80] Formatting --- .../org/billcarsonfr/jsonviewer/JSonViewerDialog.kt | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/library/external/jsonviewer/src/main/java/org/billcarsonfr/jsonviewer/JSonViewerDialog.kt b/library/external/jsonviewer/src/main/java/org/billcarsonfr/jsonviewer/JSonViewerDialog.kt index 0ebf539d4d..d1d8126c5a 100644 --- a/library/external/jsonviewer/src/main/java/org/billcarsonfr/jsonviewer/JSonViewerDialog.kt +++ b/library/external/jsonviewer/src/main/java/org/billcarsonfr/jsonviewer/JSonViewerDialog.kt @@ -40,12 +40,13 @@ class JSonViewerDialog : DialogFragment() { if (savedInstanceState == null) { childFragmentManager.beginTransaction() .replace( - R.id.fragmentContainer, JSonViewerFragment.newInstance( - args.jsonString, - args.defaultOpenDepth, - true, - args.styleProvider - ) + R.id.fragmentContainer, + JSonViewerFragment.newInstance( + args.jsonString, + args.defaultOpenDepth, + true, + args.styleProvider + ) ) .commitNow() } From 2d905247631b8eb5e6139a7eb6ed107b9c10d6ba Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 28 Sep 2022 10:23:10 +0200 Subject: [PATCH 05/80] activity-ktx --- dependencies.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dependencies.gradle b/dependencies.gradle index ae66f81ffa..88e7e53646 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -51,7 +51,7 @@ ext.libs = [ 'coroutinesTest' : "org.jetbrains.kotlinx:kotlinx-coroutines-test:$kotlinCoroutines" ], androidx : [ - 'activity' : "androidx.activity:activity:1.6.0", + 'activity' : "androidx.activity:activity-ktx:1.6.0", 'appCompat' : "androidx.appcompat:appcompat:1.5.1", 'biometric' : "androidx.biometric:biometric:1.1.0", 'core' : "androidx.core:core-ktx:1.9.0", From 61a4dd2128755dfef34d74736e5081f20e8faa73 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 28 Sep 2022 10:57:37 +0200 Subject: [PATCH 06/80] Avoid using deprecated `readList`. Serialize and deserialize a String instead of a char array. --- .../app/features/pin/lockscreen/views/LockScreenCodeView.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/pin/lockscreen/views/LockScreenCodeView.kt b/vector/src/main/java/im/vector/app/features/pin/lockscreen/views/LockScreenCodeView.kt index eb72d86bf4..d9d6d56737 100644 --- a/vector/src/main/java/im/vector/app/features/pin/lockscreen/views/LockScreenCodeView.kt +++ b/vector/src/main/java/im/vector/app/features/pin/lockscreen/views/LockScreenCodeView.kt @@ -142,7 +142,8 @@ class LockScreenCodeView @JvmOverloads constructor( var codeLength: Int = 0 constructor(source: Parcel) : super(source) { - source.readList(code, null) + val codeStr = source.readString().orEmpty() + code = codeStr.toMutableList() codeLength = source.readInt() } @@ -150,7 +151,7 @@ class LockScreenCodeView @JvmOverloads constructor( override fun writeToParcel(out: Parcel, flags: Int) { super.writeToParcel(out, flags) - out.writeList(code) + out.writeString(String(code.toCharArray())) out.writeInt(codeLength) } From f2bbdc3906a0291dae98e37015e3edbf4909e122 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 28 Sep 2022 14:37:59 +0200 Subject: [PATCH 07/80] API 33: fix compilation warnings --- .../AttachmentViewerActivity.kt | 4 -- .../attachmentviewer/SwipeToDismissHandler.kt | 4 +- .../im/vector/lib/core/utils/compat/Compat.kt | 70 +++++++++++++++++++ .../jsonviewer/JSonViewerDialog.kt | 3 +- .../jsonviewer/JSonViewerFragment.kt | 3 +- library/multipicker/build.gradle | 5 ++ .../java/im/vector/lib/multipicker/Picker.kt | 10 ++- .../org/matrix/android/sdk/api/util/Compat.kt | 42 +++++++++++ .../network/ComputeUserAgentUseCase.kt | 3 +- .../network/ComputeUserAgentUseCaseTest.kt | 3 +- .../core/animations/SimpleAnimatorListener.kt | 8 +-- .../core/epoxy/LayoutManagerStateRestorer.kt | 3 +- .../app/core/extensions/MavericksViewModel.kt | 1 + .../vector/app/core/extensions/ViewPager2.kt | 10 ++- .../app/core/resources/VersionCodeProvider.kt | 3 +- .../core/services/BluetoothHeadsetReceiver.kt | 3 +- .../app/core/services/CallAndroidService.kt | 10 +-- .../app/core/services/VectorAndroidService.kt | 10 +++ .../im/vector/app/core/utils/SystemUtils.kt | 3 +- .../im/vector/app/features/MainActivity.kt | 5 +- .../features/attachments/AttachmentsHelper.kt | 6 +- .../preview/AttachmentsPreviewActivity.kt | 6 +- .../app/features/call/VectorCallActivity.kt | 3 +- .../call/conference/VectorJitsiActivity.kt | 3 +- .../call/transfer/CallTransferActivity.kt | 3 +- .../IncomingVerificationRequestHandler.kt | 3 +- .../VerificationQRWaitingFragment.kt | 3 +- .../vector/app/features/home/HomeActivity.kt | 7 +- .../features/home/HomeActivityViewModel.kt | 3 +- .../home/room/detail/RoomDetailActivity.kt | 3 +- .../home/room/detail/TimelineFragment.kt | 18 ++--- .../home/room/detail/search/SearchActivity.kt | 3 +- .../home/room/threads/ThreadsActivity.kt | 5 +- .../threads/list/views/ThreadListFragment.kt | 4 +- .../VectorActivityLifecycleCallbacks.kt | 7 +- .../location/LocationSharingActivity.kt | 3 +- .../live/map/LiveLocationMapViewActivity.kt | 3 +- .../tracking/LocationSharingAndroidService.kt | 5 +- .../app/features/login/LoginActivity.kt | 3 +- .../media/VectorAttachmentViewerActivity.kt | 8 ++- .../onboarding/ftueauth/FtueAuthVariant.kt | 3 +- .../im/vector/app/features/pin/PinActivity.kt | 3 +- .../poll/create/CreatePollActivity.kt | 3 +- .../features/rageshake/BugReportActivity.kt | 2 +- .../reactions/EmojiReactionPickerActivity.kt | 4 +- .../createroom/CreateRoomActivity.kt | 3 +- .../roompreview/RoomPreviewActivity.kt | 3 +- .../RoomMemberProfileActivity.kt | 3 +- .../roomprofile/RoomProfileActivity.kt | 3 +- .../settings/joinrule/RoomJoinRuleActivity.kt | 3 +- .../settings/VectorSettingsActivity.kt | 5 +- .../VectorSettingsVoiceVideoFragment.kt | 3 +- .../v2/details/SessionDetailsActivity.kt | 3 +- .../v2/othersessions/OtherSessionsActivity.kt | 3 +- .../v2/overview/SessionOverviewActivity.kt | 3 +- .../v2/rename/RenameSessionActivity.kt | 3 +- ...rSettingsNotificationPreferenceFragment.kt | 3 +- .../features/spaces/SpaceExploreActivity.kt | 3 +- .../features/spaces/SpacePreviewActivity.kt | 3 +- .../leave/SpaceLeaveAdvancedActivity.kt | 3 +- .../leave/SpaceLeaveAdvancedFragment.kt | 4 +- .../spaces/manage/SpaceManageActivity.kt | 3 +- .../spaces/people/SpacePeopleActivity.kt | 3 +- .../app/features/terms/ReviewTermsActivity.kt | 3 +- .../features/webview/VectorWebViewActivity.kt | 3 +- .../app/features/widgets/WidgetActivity.kt | 8 ++- .../app/features/widgets/WidgetFragment.kt | 3 +- 67 files changed, 287 insertions(+), 104 deletions(-) create mode 100644 library/core-utils/src/main/java/im/vector/lib/core/utils/compat/Compat.kt create mode 100644 matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/Compat.kt diff --git a/library/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentViewerActivity.kt b/library/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentViewerActivity.kt index 98398760d1..21d96afb77 100644 --- a/library/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentViewerActivity.kt +++ b/library/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/AttachmentViewerActivity.kt @@ -316,10 +316,6 @@ abstract class AttachmentViewerActivity : AppCompatActivity(), AttachmentEventLi } return false } - - override fun onDoubleTap(e: MotionEvent?): Boolean { - return super.onDoubleTap(e) - } }) override fun onEvent(event: AttachmentEvents) { diff --git a/library/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/SwipeToDismissHandler.kt b/library/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/SwipeToDismissHandler.kt index 7a83ee28d4..54cd34ecba 100644 --- a/library/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/SwipeToDismissHandler.kt +++ b/library/attachment-viewer/src/main/java/im/vector/lib/attachmentviewer/SwipeToDismissHandler.kt @@ -113,11 +113,11 @@ internal fun ViewPropertyAnimator.setAnimatorListener( onAnimationStart: ((Animator?) -> Unit)? = null ) = this.setListener( object : AnimatorListenerAdapter() { - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { onAnimationEnd?.invoke(animation) } - override fun onAnimationStart(animation: Animator?) { + override fun onAnimationStart(animation: Animator) { onAnimationStart?.invoke(animation) } }) diff --git a/library/core-utils/src/main/java/im/vector/lib/core/utils/compat/Compat.kt b/library/core-utils/src/main/java/im/vector/lib/core/utils/compat/Compat.kt new file mode 100644 index 0000000000..8b0ad7767b --- /dev/null +++ b/library/core-utils/src/main/java/im/vector/lib/core/utils/compat/Compat.kt @@ -0,0 +1,70 @@ +/* + * 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.content.Intent +import android.content.pm.PackageManager +import android.content.pm.ResolveInfo +import android.os.Build +import android.os.Bundle +import android.os.Parcelable +import java.io.Serializable + +inline fun Intent.getParcelableExtraCompat(key: String): T? = when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getParcelableExtra(key, T::class.java) + else -> @Suppress("DEPRECATION") getParcelableExtra(key) as? T? +} + +inline fun Intent.getParcelableArrayListExtraCompat(key: String): ArrayList? = when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getParcelableArrayListExtra(key, T::class.java) + else -> @Suppress("DEPRECATION") getParcelableArrayListExtra(key) +} + +inline fun Bundle.getParcelableCompat(key: String): T? = when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getParcelable(key, T::class.java) + else -> @Suppress("DEPRECATION") getParcelable(key) as? T? +} + +inline fun Bundle.getSerializableCompat(key: String): T? = when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getSerializable(key, T::class.java) + else -> @Suppress("DEPRECATION") getSerializable(key) as? T? +} + +inline fun Intent.getSerializableExtraCompat(key: String): T? = when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getSerializableExtra(key, T::class.java) + else -> @Suppress("DEPRECATION") getSerializableExtra(key) as? T? +} + +fun PackageManager.queryIntentActivitiesCompat(data: Intent, flags: Int): List { + return when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> queryIntentActivities( + data, + PackageManager.ResolveInfoFlags.of(flags.toLong()) + ) + else -> @Suppress("DEPRECATION") queryIntentActivities(data, flags) + } +} + +fun PackageManager.resolveActivityCompat(data: Intent, flags: Int): ResolveInfo? { + return when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> resolveActivity( + data, + PackageManager.ResolveInfoFlags.of(flags.toLong()) + ) + else -> @Suppress("DEPRECATION") resolveActivity(data, flags) + } +} diff --git a/library/external/jsonviewer/src/main/java/org/billcarsonfr/jsonviewer/JSonViewerDialog.kt b/library/external/jsonviewer/src/main/java/org/billcarsonfr/jsonviewer/JSonViewerDialog.kt index d1d8126c5a..696655a19f 100644 --- a/library/external/jsonviewer/src/main/java/org/billcarsonfr/jsonviewer/JSonViewerDialog.kt +++ b/library/external/jsonviewer/src/main/java/org/billcarsonfr/jsonviewer/JSonViewerDialog.kt @@ -23,6 +23,7 @@ import android.view.ViewGroup import android.view.WindowManager import androidx.fragment.app.DialogFragment import com.airbnb.mvrx.Mavericks +import im.vector.lib.core.utils.compat.getParcelableCompat class JSonViewerDialog : DialogFragment() { @@ -36,7 +37,7 @@ class JSonViewerDialog : DialogFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val args: JSonViewerFragmentArgs = arguments?.getParcelable(Mavericks.KEY_ARG) ?: return + val args: JSonViewerFragmentArgs = arguments?.getParcelableCompat(Mavericks.KEY_ARG) ?: return if (savedInstanceState == null) { childFragmentManager.beginTransaction() .replace( diff --git a/library/external/jsonviewer/src/main/java/org/billcarsonfr/jsonviewer/JSonViewerFragment.kt b/library/external/jsonviewer/src/main/java/org/billcarsonfr/jsonviewer/JSonViewerFragment.kt index 719ce29045..f7c7f4d7bc 100644 --- a/library/external/jsonviewer/src/main/java/org/billcarsonfr/jsonviewer/JSonViewerFragment.kt +++ b/library/external/jsonviewer/src/main/java/org/billcarsonfr/jsonviewer/JSonViewerFragment.kt @@ -28,6 +28,7 @@ import com.airbnb.mvrx.Mavericks import com.airbnb.mvrx.MavericksView import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState +import im.vector.lib.core.utils.compat.getParcelableCompat import kotlinx.parcelize.Parcelize @Parcelize @@ -53,7 +54,7 @@ class JSonViewerFragment : Fragment(), MavericksView { container: ViewGroup?, savedInstanceState: Bundle? ): View? { - val args: JSonViewerFragmentArgs? = arguments?.getParcelable(Mavericks.KEY_ARG) + val args: JSonViewerFragmentArgs? = arguments?.getParcelableCompat(Mavericks.KEY_ARG) val inflate = if (args?.wrap == true) { inflater.inflate(R.layout.fragment_jv_recycler_view_wrap, container, false) diff --git a/library/multipicker/build.gradle b/library/multipicker/build.gradle index 2de99d5c20..58edfcdd5c 100644 --- a/library/multipicker/build.gradle +++ b/library/multipicker/build.gradle @@ -35,9 +35,14 @@ android { } } + kotlinOptions { + jvmTarget = "11" + } } dependencies { + implementation project(":library:core-utils") + api libs.androidx.activity implementation libs.androidx.exifinterface implementation libs.androidx.core diff --git a/library/multipicker/src/main/java/im/vector/lib/multipicker/Picker.kt b/library/multipicker/src/main/java/im/vector/lib/multipicker/Picker.kt index 8960f3228b..1cfcba505f 100644 --- a/library/multipicker/src/main/java/im/vector/lib/multipicker/Picker.kt +++ b/library/multipicker/src/main/java/im/vector/lib/multipicker/Picker.kt @@ -22,6 +22,9 @@ import android.content.pm.PackageManager import android.content.pm.ResolveInfo import android.net.Uri import androidx.activity.result.ActivityResultLauncher +import im.vector.lib.core.utils.compat.getParcelableArrayListExtraCompat +import im.vector.lib.core.utils.compat.getParcelableExtraCompat +import im.vector.lib.core.utils.compat.queryIntentActivitiesCompat /** * Abstract class to provide all types of Pickers. @@ -45,13 +48,13 @@ abstract class Picker { val uriList = mutableListOf() if (data.action == Intent.ACTION_SEND) { - (data.getParcelableExtra(Intent.EXTRA_STREAM) as? Uri)?.let { uriList.add(it) } + data.getParcelableExtraCompat(Intent.EXTRA_STREAM)?.let { uriList.add(it) } } else if (data.action == Intent.ACTION_SEND_MULTIPLE) { - val extraUriList: List? = data.getParcelableArrayListExtra(Intent.EXTRA_STREAM) + val extraUriList: List? = data.getParcelableArrayListExtraCompat(Intent.EXTRA_STREAM) extraUriList?.let { uriList.addAll(it) } } - val resInfoList: List = context.packageManager.queryIntentActivities(data, PackageManager.MATCH_DEFAULT_ONLY) + val resInfoList: List = context.packageManager.queryIntentActivitiesCompat(data, PackageManager.MATCH_DEFAULT_ONLY) uriList.forEach { for (resolveInfo in resInfoList) { val packageName: String = resolveInfo.activityInfo.packageName @@ -91,6 +94,7 @@ abstract class Picker { } else if (dataUri != null) { selectedUriList.add(dataUri) } else { + @Suppress("DEPRECATION") data?.extras?.get(Intent.EXTRA_STREAM)?.let { (it as? List<*>)?.filterIsInstance()?.let { uriList -> selectedUriList.addAll(uriList) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/Compat.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/Compat.kt new file mode 100644 index 0000000000..b685c49713 --- /dev/null +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/api/util/Compat.kt @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2022 The Matrix.org Foundation C.I.C. + * + * 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 org.matrix.android.sdk.api.util + +import android.content.pm.ApplicationInfo +import android.content.pm.PackageInfo +import android.content.pm.PackageManager +import android.os.Build + +fun PackageManager.getApplicationInfoCompat(packageName: String, flags: Int): ApplicationInfo { + return when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getApplicationInfo( + packageName, + PackageManager.ApplicationInfoFlags.of(flags.toLong()) + ) + else -> @Suppress("DEPRECATION") getApplicationInfo(packageName, flags) + } +} + +fun PackageManager.getPackageInfoCompat(packageName: String, flags: Int): PackageInfo { + return when { + Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getPackageInfo( + packageName, + PackageManager.PackageInfoFlags.of(flags.toLong()) + ) + else -> @Suppress("DEPRECATION") getPackageInfo(packageName, flags) + } +} diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCase.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCase.kt index 6eb4d5b104..6611bd7865 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCase.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCase.kt @@ -20,6 +20,7 @@ import android.content.Context import android.os.Build import org.matrix.android.sdk.BuildConfig import org.matrix.android.sdk.api.extensions.tryOrNull +import org.matrix.android.sdk.api.util.getPackageInfoCompat import javax.inject.Inject class ComputeUserAgentUseCase @Inject constructor( @@ -44,7 +45,7 @@ class ComputeUserAgentUseCase @Inject constructor( // Use appPackageName instead of appName if appName is null or contains any non-ASCII character appPackageName } - val appVersion = tryOrNull { pm.getPackageInfo(context.applicationContext.packageName, 0).versionName } ?: FALLBACK_APP_VERSION + val appVersion = tryOrNull { pm.getPackageInfoCompat(context.applicationContext.packageName, 0).versionName } ?: FALLBACK_APP_VERSION val deviceManufacturer = Build.MANUFACTURER val deviceModel = Build.MODEL diff --git a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCaseTest.kt b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCaseTest.kt index 9ed6f28d7e..0e7dc5dd32 100644 --- a/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCaseTest.kt +++ b/matrix-sdk-android/src/test/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCaseTest.kt @@ -27,6 +27,7 @@ import org.amshove.kluent.shouldBeEqualTo import org.junit.Before import org.junit.Test import org.matrix.android.sdk.BuildConfig +import org.matrix.android.sdk.api.util.getPackageInfoCompat import java.lang.Exception private const val A_PACKAGE_NAME = "org.matrix.sdk" @@ -50,7 +51,7 @@ class ComputeUserAgentUseCaseTest { every { context.packageName } returns A_PACKAGE_NAME every { context.packageManager } returns packageManager every { packageManager.getApplicationInfo(any(), any()) } returns applicationInfo - every { packageManager.getPackageInfo(any(), any()) } returns packageInfo + every { packageManager.getPackageInfoCompat(any(), any()) } returns packageInfo } @Test diff --git a/vector/src/main/java/im/vector/app/core/animations/SimpleAnimatorListener.kt b/vector/src/main/java/im/vector/app/core/animations/SimpleAnimatorListener.kt index d8ffde20ef..ec20de5914 100644 --- a/vector/src/main/java/im/vector/app/core/animations/SimpleAnimatorListener.kt +++ b/vector/src/main/java/im/vector/app/core/animations/SimpleAnimatorListener.kt @@ -19,19 +19,19 @@ package im.vector.app.core.animations import android.animation.Animator open class SimpleAnimatorListener : Animator.AnimatorListener { - override fun onAnimationRepeat(animation: Animator?) { + override fun onAnimationRepeat(animation: Animator) { // No op } - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { // No op } - override fun onAnimationCancel(animation: Animator?) { + override fun onAnimationCancel(animation: Animator) { // No op } - override fun onAnimationStart(animation: Animator?) { + override fun onAnimationStart(animation: Animator) { // No op } } diff --git a/vector/src/main/java/im/vector/app/core/epoxy/LayoutManagerStateRestorer.kt b/vector/src/main/java/im/vector/app/core/epoxy/LayoutManagerStateRestorer.kt index dfbdfff2b8..b1d641826e 100644 --- a/vector/src/main/java/im/vector/app/core/epoxy/LayoutManagerStateRestorer.kt +++ b/vector/src/main/java/im/vector/app/core/epoxy/LayoutManagerStateRestorer.kt @@ -21,6 +21,7 @@ import android.os.Parcelable import androidx.recyclerview.widget.RecyclerView import im.vector.app.core.platform.DefaultListUpdateCallback import im.vector.app.core.platform.Restorable +import im.vector.lib.core.utils.compat.getParcelableCompat import java.util.concurrent.atomic.AtomicReference private const val LAYOUT_MANAGER_STATE = "LAYOUT_MANAGER_STATE" @@ -44,7 +45,7 @@ class LayoutManagerStateRestorer(layoutManager: RecyclerView.LayoutManager) : Re } override fun onRestoreInstanceState(savedInstanceState: Bundle?) { - val parcelable = savedInstanceState?.getParcelable(LAYOUT_MANAGER_STATE) + val parcelable = savedInstanceState?.getParcelableCompat(LAYOUT_MANAGER_STATE) layoutManagerState.set(parcelable) } diff --git a/vector/src/main/java/im/vector/app/core/extensions/MavericksViewModel.kt b/vector/src/main/java/im/vector/app/core/extensions/MavericksViewModel.kt index 6120a84d7c..8201a1b5e8 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/MavericksViewModel.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/MavericksViewModel.kt @@ -25,6 +25,7 @@ import com.airbnb.mvrx.MavericksViewModelProvider inline fun , reified S : MavericksState> ComponentActivity.lazyViewModel(): Lazy { return lazy(mode = LazyThreadSafetyMode.NONE) { + @Suppress("DEPRECATION") MavericksViewModelProvider.get( viewModelClass = VM::class.java, stateClass = S::class.java, diff --git a/vector/src/main/java/im/vector/app/core/extensions/ViewPager2.kt b/vector/src/main/java/im/vector/app/core/extensions/ViewPager2.kt index 7d3a678af1..c94352b998 100644 --- a/vector/src/main/java/im/vector/app/core/extensions/ViewPager2.kt +++ b/vector/src/main/java/im/vector/app/core/extensions/ViewPager2.kt @@ -22,6 +22,7 @@ import android.animation.ValueAnimator import android.view.View import android.view.animation.AccelerateDecelerateInterpolator import androidx.viewpager2.widget.ViewPager2 +import im.vector.app.core.animations.SimpleAnimatorListener fun ViewPager2.setCurrentItem( item: Int, @@ -45,19 +46,16 @@ fun ViewPager2.setCurrentItem( previousValue = currentValue }.onFailure { animator.cancel() } } - animator.addListener(object : Animator.AnimatorListener { - override fun onAnimationStart(animation: Animator?) { + animator.addListener(object : SimpleAnimatorListener() { + override fun onAnimationStart(animation: Animator) { isUserInputEnabled = false beginFakeDrag() } - override fun onAnimationEnd(animation: Animator?) { + override fun onAnimationEnd(animation: Animator) { isUserInputEnabled = true endFakeDrag() } - - override fun onAnimationCancel(animation: Animator?) = Unit - override fun onAnimationRepeat(animation: Animator?) = Unit }) animator.interpolator = interpolator animator.duration = duration diff --git a/vector/src/main/java/im/vector/app/core/resources/VersionCodeProvider.kt b/vector/src/main/java/im/vector/app/core/resources/VersionCodeProvider.kt index 1e136bbcc2..edb99d472f 100644 --- a/vector/src/main/java/im/vector/app/core/resources/VersionCodeProvider.kt +++ b/vector/src/main/java/im/vector/app/core/resources/VersionCodeProvider.kt @@ -19,6 +19,7 @@ package im.vector.app.core.resources import android.content.Context import android.os.Build import androidx.annotation.NonNull +import org.matrix.android.sdk.api.util.getPackageInfoCompat import javax.inject.Inject class VersionCodeProvider @Inject constructor(private val context: Context) { @@ -28,7 +29,7 @@ class VersionCodeProvider @Inject constructor(private val context: Context) { */ @NonNull fun getVersionCode(): Long { - val packageInfo = context.packageManager.getPackageInfo(context.packageName, 0) + val packageInfo = context.packageManager.getPackageInfoCompat(context.packageName, 0) return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { packageInfo.longVersionCode diff --git a/vector/src/main/java/im/vector/app/core/services/BluetoothHeadsetReceiver.kt b/vector/src/main/java/im/vector/app/core/services/BluetoothHeadsetReceiver.kt index 829fec1652..4925adf69d 100644 --- a/vector/src/main/java/im/vector/app/core/services/BluetoothHeadsetReceiver.kt +++ b/vector/src/main/java/im/vector/app/core/services/BluetoothHeadsetReceiver.kt @@ -23,6 +23,7 @@ import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter +import im.vector.lib.core.utils.compat.getParcelableExtraCompat import java.lang.ref.WeakReference class BluetoothHeadsetReceiver : BroadcastReceiver() { @@ -59,7 +60,7 @@ class BluetoothHeadsetReceiver : BroadcastReceiver() { else -> return // ignore intermediate states } - val device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE) + val device = intent.getParcelableExtraCompat(BluetoothDevice.EXTRA_DEVICE) val deviceName = device?.name when (device?.bluetoothClass?.deviceClass) { BluetoothClass.Device.AUDIO_VIDEO_HANDSFREE, diff --git a/vector/src/main/java/im/vector/app/core/services/CallAndroidService.kt b/vector/src/main/java/im/vector/app/core/services/CallAndroidService.kt index 7a078ce1c8..85ea7f1a1b 100644 --- a/vector/src/main/java/im/vector/app/core/services/CallAndroidService.kt +++ b/vector/src/main/java/im/vector/app/core/services/CallAndroidService.kt @@ -39,6 +39,8 @@ import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.notifications.NotificationUtils import im.vector.app.features.popup.IncomingCallAlert import im.vector.app.features.popup.PopupAlertManager +import im.vector.lib.core.utils.compat.getParcelableExtraCompat +import im.vector.lib.core.utils.compat.getSerializableExtraCompat import org.matrix.android.sdk.api.logger.LoggerTag import org.matrix.android.sdk.api.session.room.model.call.EndCallReason import org.matrix.android.sdk.api.util.MatrixItem @@ -71,7 +73,7 @@ class CallAndroidService : VectorAndroidService() { private var mediaSession: MediaSessionCompat? = null private val mediaSessionButtonCallback = object : MediaSessionCompat.Callback() { override fun onMediaButtonEvent(mediaButtonEvent: Intent?): Boolean { - val keyEvent = mediaButtonEvent?.getParcelableExtra(Intent.EXTRA_KEY_EVENT) ?: return false + val keyEvent = mediaButtonEvent?.getParcelableExtraCompat(Intent.EXTRA_KEY_EVENT) ?: return false if (keyEvent.keyCode == KeyEvent.KEYCODE_HEADSETHOOK) { callManager.headSetButtonTapped() return true @@ -158,7 +160,7 @@ class CallAndroidService : VectorAndroidService() { val incomingCallAlert = IncomingCallAlert(callId, shouldBeDisplayedIn = { activity -> if (activity is VectorCallActivity) { - activity.intent.getParcelableExtra(Mavericks.KEY_ARG)?.callId != call.callId + activity.intent.getParcelableExtraCompat(Mavericks.KEY_ARG)?.callId != call.callId } else true } ).apply { @@ -188,7 +190,7 @@ class CallAndroidService : VectorAndroidService() { private fun handleCallTerminated(intent: Intent) { val callId = intent.getStringExtra(EXTRA_CALL_ID) ?: "" - val endCallReason = intent.getSerializableExtra(EXTRA_END_CALL_REASON) as EndCallReason + val endCallReason = intent.getSerializableExtraCompat(EXTRA_END_CALL_REASON) val rejected = intent.getBooleanExtra(EXTRA_END_CALL_REJECTED, false) alertManager.cancelAlert(callId) val terminatedCall = knownCalls.remove(callId) @@ -202,7 +204,7 @@ class CallAndroidService : VectorAndroidService() { startForeground(notificationId, notification) if (knownCalls.isEmpty()) { Timber.tag(loggerTag.value).v("No more call, stop the service") - stopForeground(true) + stopForegroundCompat() mediaSession?.isActive = false myStopSelf() } diff --git a/vector/src/main/java/im/vector/app/core/services/VectorAndroidService.kt b/vector/src/main/java/im/vector/app/core/services/VectorAndroidService.kt index f30a74e9de..04fc746b14 100644 --- a/vector/src/main/java/im/vector/app/core/services/VectorAndroidService.kt +++ b/vector/src/main/java/im/vector/app/core/services/VectorAndroidService.kt @@ -18,6 +18,7 @@ package im.vector.app.core.services import android.app.Service import android.content.Intent +import android.os.Build import android.os.IBinder import timber.log.Timber @@ -55,4 +56,13 @@ abstract class VectorAndroidService : Service() { override fun onBind(intent: Intent?): IBinder? { return null } + + protected fun stopForegroundCompat() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + stopForeground(STOP_FOREGROUND_REMOVE) + } else { + @Suppress("DEPRECATION") + stopForeground(true) + } + } } diff --git a/vector/src/main/java/im/vector/app/core/utils/SystemUtils.kt b/vector/src/main/java/im/vector/app/core/utils/SystemUtils.kt index cde4fe2a35..20eda102e2 100644 --- a/vector/src/main/java/im/vector/app/core/utils/SystemUtils.kt +++ b/vector/src/main/java/im/vector/app/core/utils/SystemUtils.kt @@ -34,6 +34,7 @@ import androidx.core.content.getSystemService import androidx.fragment.app.Fragment import im.vector.app.R import im.vector.app.features.notifications.NotificationUtils +import org.matrix.android.sdk.api.util.getApplicationInfoCompat /** * Tells if the application ignores battery optimizations. @@ -63,7 +64,7 @@ fun Context.isAnimationEnabled(): Boolean { */ fun Context.getApplicationLabel(packageName: String): String { return try { - val ai = packageManager.getApplicationInfo(packageName, 0) + val ai = packageManager.getApplicationInfoCompat(packageName, 0) packageManager.getApplicationLabel(ai).toString() } catch (e: PackageManager.NameNotFoundException) { packageName diff --git a/vector/src/main/java/im/vector/app/features/MainActivity.kt b/vector/src/main/java/im/vector/app/features/MainActivity.kt index 1b3a9eb142..0040962b73 100644 --- a/vector/src/main/java/im/vector/app/features/MainActivity.kt +++ b/vector/src/main/java/im/vector/app/features/MainActivity.kt @@ -57,6 +57,7 @@ import im.vector.app.features.start.StartAppViewModel import im.vector.app.features.start.StartAppViewState import im.vector.app.features.themes.ActivityOtherThemes import im.vector.app.features.ui.UiStateRepository +import im.vector.lib.core.utils.compat.getParcelableExtraCompat import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -181,7 +182,7 @@ class MainActivity : VectorBaseActivity(), UnlockedActivity private fun handleAppStarted() { if (intent.hasExtra(EXTRA_NEXT_INTENT)) { // Start the next Activity - val nextIntent = intent.getParcelableExtra(EXTRA_NEXT_INTENT) + val nextIntent = intent.getParcelableExtraCompat(EXTRA_NEXT_INTENT) startIntentAndFinish(nextIntent) } else if (intent.hasExtra(EXTRA_INIT_SESSION)) { setResult(RESULT_OK) @@ -218,7 +219,7 @@ class MainActivity : VectorBaseActivity(), UnlockedActivity } private fun parseArgs(): MainActivityArgs { - val argsFromIntent: MainActivityArgs? = intent.getParcelableExtra(EXTRA_ARGS) + val argsFromIntent: MainActivityArgs? = intent.getParcelableExtraCompat(EXTRA_ARGS) Timber.w("Starting MainActivity with $argsFromIntent") return MainActivityArgs( diff --git a/vector/src/main/java/im/vector/app/features/attachments/AttachmentsHelper.kt b/vector/src/main/java/im/vector/app/features/attachments/AttachmentsHelper.kt index 646758654f..1a8e10d102 100644 --- a/vector/src/main/java/im/vector/app/features/attachments/AttachmentsHelper.kt +++ b/vector/src/main/java/im/vector/app/features/attachments/AttachmentsHelper.kt @@ -26,6 +26,8 @@ import im.vector.app.core.dialogs.PhotoOrVideoDialog import im.vector.app.core.platform.Restorable import im.vector.app.core.resources.BuildMeta import im.vector.app.features.settings.VectorPreferences +import im.vector.lib.core.utils.compat.getParcelableCompat +import im.vector.lib.core.utils.compat.getSerializableCompat import im.vector.lib.multipicker.MultiPicker import org.matrix.android.sdk.api.session.content.ContentAttachmentData import timber.log.Timber @@ -66,8 +68,8 @@ class AttachmentsHelper( } override fun onRestoreInstanceState(savedInstanceState: Bundle?) { - captureUri = savedInstanceState?.getParcelable(CAPTURE_PATH_KEY) as? Uri - pendingType = savedInstanceState?.getSerializable(PENDING_TYPE_KEY) as? AttachmentTypeSelectorView.Type + captureUri = savedInstanceState?.getParcelableCompat(CAPTURE_PATH_KEY) + pendingType = savedInstanceState?.getSerializableCompat(PENDING_TYPE_KEY) } // Public Methods diff --git a/vector/src/main/java/im/vector/app/features/attachments/preview/AttachmentsPreviewActivity.kt b/vector/src/main/java/im/vector/app/features/attachments/preview/AttachmentsPreviewActivity.kt index 7ddba0d229..4a965022b8 100644 --- a/vector/src/main/java/im/vector/app/features/attachments/preview/AttachmentsPreviewActivity.kt +++ b/vector/src/main/java/im/vector/app/features/attachments/preview/AttachmentsPreviewActivity.kt @@ -24,6 +24,8 @@ import im.vector.app.core.extensions.addFragment import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivitySimpleBinding import im.vector.app.features.themes.ActivityOtherThemes +import im.vector.lib.core.utils.compat.getParcelableArrayListExtraCompat +import im.vector.lib.core.utils.compat.getParcelableCompat import org.matrix.android.sdk.api.session.content.ContentAttachmentData @AndroidEntryPoint @@ -41,7 +43,7 @@ class AttachmentsPreviewActivity : VectorBaseActivity() { } fun getOutput(intent: Intent): List { - return intent.getParcelableArrayListExtra(ATTACHMENTS_PREVIEW_RESULT).orEmpty() + return intent.getParcelableArrayListExtraCompat(ATTACHMENTS_PREVIEW_RESULT).orEmpty() } fun getKeepOriginalSize(intent: Intent): Boolean { @@ -57,7 +59,7 @@ class AttachmentsPreviewActivity : VectorBaseActivity() { override fun initUiAndData() { if (isFirstCreation()) { - val fragmentArgs: AttachmentsPreviewArgs = intent?.extras?.getParcelable(EXTRA_FRAGMENT_ARGS) ?: return + val fragmentArgs: AttachmentsPreviewArgs = intent?.extras?.getParcelableCompat(EXTRA_FRAGMENT_ARGS) ?: return addFragment(views.simpleFragmentContainer, AttachmentsPreviewFragment::class.java, fragmentArgs) } } diff --git a/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt b/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt index aa46feeea6..7e226304c1 100644 --- a/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt +++ b/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt @@ -69,6 +69,7 @@ import im.vector.app.features.displayname.getBestName import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.detail.RoomDetailActivity import im.vector.app.features.home.room.detail.arguments.TimelineArgs +import im.vector.lib.core.utils.compat.getParcelableExtraCompat import io.github.hyuwah.draggableviewlib.DraggableView import io.github.hyuwah.draggableviewlib.setupDraggable import kotlinx.parcelize.Parcelize @@ -178,7 +179,7 @@ class VectorCallActivity : override fun onNewIntent(intent: Intent?) { super.onNewIntent(intent) intent?.takeIf { it.hasExtra(Mavericks.KEY_ARG) } - ?.let { intent.getParcelableExtra(Mavericks.KEY_ARG) } + ?.let { intent.getParcelableExtraCompat(Mavericks.KEY_ARG) } ?.let { callViewModel.handle(VectorCallViewActions.SwitchCall(it)) } diff --git a/vector/src/main/java/im/vector/app/features/call/conference/VectorJitsiActivity.kt b/vector/src/main/java/im/vector/app/features/call/conference/VectorJitsiActivity.kt index 5bf05d353c..4d107ac414 100644 --- a/vector/src/main/java/im/vector/app/features/call/conference/VectorJitsiActivity.kt +++ b/vector/src/main/java/im/vector/app/features/call/conference/VectorJitsiActivity.kt @@ -38,6 +38,7 @@ import dagger.hilt.android.AndroidEntryPoint import im.vector.app.R import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivityJitsiBinding +import im.vector.lib.core.utils.compat.getParcelableExtraCompat import kotlinx.parcelize.Parcelize import org.jitsi.meet.sdk.JitsiMeet import org.jitsi.meet.sdk.JitsiMeetActivityDelegate @@ -200,7 +201,7 @@ class VectorJitsiActivity : VectorBaseActivity(), JitsiMee // Is it a switch to another conf? intent?.takeIf { it.hasExtra(Mavericks.KEY_ARG) } - ?.let { intent.getParcelableExtra(Mavericks.KEY_ARG) } + ?.let { intent.getParcelableExtraCompat(Mavericks.KEY_ARG) } ?.let { jitsiViewModel.handle(JitsiCallViewActions.SwitchTo(it, true)) } diff --git a/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferActivity.kt b/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferActivity.kt index ccda4871ef..25bfb6c0e9 100644 --- a/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferActivity.kt +++ b/vector/src/main/java/im/vector/app/features/call/transfer/CallTransferActivity.kt @@ -28,6 +28,7 @@ import im.vector.app.R import im.vector.app.core.error.ErrorFormatter import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivityCallTransferBinding +import im.vector.lib.core.utils.compat.getParcelableCompat import kotlinx.parcelize.Parcelize import javax.inject.Inject @@ -112,7 +113,7 @@ class CallTransferActivity : VectorBaseActivity() { } fun getCallTransferResult(intent: Intent?): CallTransferResult? { - return intent?.extras?.getParcelable(EXTRA_TRANSFER_RESULT) + return intent?.extras?.getParcelableCompat(EXTRA_TRANSFER_RESULT) } } } diff --git a/vector/src/main/java/im/vector/app/features/crypto/verification/IncomingVerificationRequestHandler.kt b/vector/src/main/java/im/vector/app/features/crypto/verification/IncomingVerificationRequestHandler.kt index 3406a86d1e..3a5c7e7eb8 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/verification/IncomingVerificationRequestHandler.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/verification/IncomingVerificationRequestHandler.kt @@ -26,6 +26,7 @@ import im.vector.app.features.home.room.detail.RoomDetailActivity import im.vector.app.features.home.room.detail.arguments.TimelineArgs import im.vector.app.features.popup.PopupAlertManager import im.vector.app.features.popup.VerificationVectorAlert +import im.vector.lib.core.utils.compat.getParcelableCompat import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.crypto.verification.PendingVerificationRequest import org.matrix.android.sdk.api.session.crypto.verification.VerificationService @@ -147,7 +148,7 @@ class IncomingVerificationRequestHandler @Inject constructor( R.drawable.ic_shield_black, shouldBeDisplayedIn = { activity -> if (activity is RoomDetailActivity) { - activity.intent?.extras?.getParcelable(RoomDetailActivity.EXTRA_ROOM_DETAIL_ARGS)?.let { + activity.intent?.extras?.getParcelableCompat(RoomDetailActivity.EXTRA_ROOM_DETAIL_ARGS)?.let { it.roomId != pr.roomId } ?: true } else true diff --git a/vector/src/main/java/im/vector/app/features/crypto/verification/qrconfirmation/VerificationQRWaitingFragment.kt b/vector/src/main/java/im/vector/app/features/crypto/verification/qrconfirmation/VerificationQRWaitingFragment.kt index e5402424d0..dc538597db 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/verification/qrconfirmation/VerificationQRWaitingFragment.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/verification/qrconfirmation/VerificationQRWaitingFragment.kt @@ -27,6 +27,7 @@ import im.vector.app.core.extensions.cleanup import im.vector.app.core.extensions.configureWith import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.databinding.BottomSheetVerificationChildFragmentBinding +import im.vector.lib.core.utils.compat.getParcelableCompat import kotlinx.parcelize.Parcelize import javax.inject.Inject @@ -49,7 +50,7 @@ class VerificationQRWaitingFragment : override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) setupRecyclerView() - (arguments?.getParcelable(Mavericks.KEY_ARG) as? Args)?.let { + (arguments?.getParcelableCompat(Mavericks.KEY_ARG))?.let { controller.update(it) } } diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt index 10e8447a2b..689d141023 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt @@ -86,6 +86,7 @@ import im.vector.app.features.spaces.share.ShareSpaceBottomSheet import im.vector.app.features.themes.ThemeUtils import im.vector.app.features.usercode.UserCodeActivity import im.vector.app.features.workers.signout.ServerBackupStatusViewModel +import im.vector.lib.core.utils.compat.getParcelableExtraCompat import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.launch @@ -245,7 +246,7 @@ class HomeActivity : } .launchIn(lifecycleScope) - val args = intent.getParcelableExtra(Mavericks.KEY_ARG) + val args = intent.getParcelableExtraCompat(Mavericks.KEY_ARG) if (args?.clearNotification == true) { notificationDrawerManager.clearAllEvents() @@ -327,7 +328,7 @@ class HomeActivity : private fun migrateThreadsIfNeeded(checkSession: Boolean) { if (checkSession) { // We should check session to ensure we will only clear cache if needed - val args = intent.getParcelableExtra(Mavericks.KEY_ARG) + val args = intent.getParcelableExtraCompat(Mavericks.KEY_ARG) if (args?.hasExistingSession == true) { // existingSession --> Will be true only if we came from an existing active session Timber.i("----> Migrating threads from an existing session..") @@ -538,7 +539,7 @@ class HomeActivity : override fun onNewIntent(intent: Intent?) { super.onNewIntent(intent) - val parcelableExtra = intent?.getParcelableExtra(Mavericks.KEY_ARG) + val parcelableExtra = intent?.getParcelableExtraCompat(Mavericks.KEY_ARG) if (parcelableExtra?.clearNotification == true) { notificationDrawerManager.clearAllEvents() } diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt index a08298e402..9157d81333 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivityViewModel.kt @@ -41,6 +41,7 @@ import im.vector.app.features.raw.wellknown.isSecureBackupRequired import im.vector.app.features.raw.wellknown.withElementWellKnown import im.vector.app.features.session.coroutineScope import im.vector.app.features.settings.VectorPreferences +import im.vector.lib.core.utils.compat.getParcelableExtraCompat import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.delay import kotlinx.coroutines.flow.collect @@ -96,7 +97,7 @@ class HomeActivityViewModel @AssistedInject constructor( companion object : MavericksViewModelFactory by hiltMavericksViewModelFactory() { override fun initialState(viewModelContext: ViewModelContext): HomeActivityViewState? { val activity: HomeActivity = viewModelContext.activity() - val args: HomeActivityArgs? = activity.intent.getParcelableExtra(Mavericks.KEY_ARG) + val args: HomeActivityArgs? = activity.intent.getParcelableExtraCompat(Mavericks.KEY_ARG) return args?.let { HomeActivityViewState(authenticationDescription = it.authenticationDescription) } ?: super.initialState(viewModelContext) } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailActivity.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailActivity.kt index 75cda67ce6..6b66d0ec47 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailActivity.kt @@ -46,6 +46,7 @@ import im.vector.app.features.navigation.Navigator import im.vector.app.features.room.RequireActiveMembershipAction import im.vector.app.features.room.RequireActiveMembershipViewEvents import im.vector.app.features.room.RequireActiveMembershipViewModel +import im.vector.lib.core.utils.compat.getParcelableCompat import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import javax.inject.Inject @@ -99,7 +100,7 @@ class RoomDetailActivity : super.onCreate(savedInstanceState) supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false) waitingView = views.waitingView.waitingView - val timelineArgs: TimelineArgs = intent?.extras?.getParcelable(EXTRA_ROOM_DETAIL_ARGS) ?: return + val timelineArgs: TimelineArgs = intent?.extras?.getParcelableCompat(EXTRA_ROOM_DETAIL_ARGS) ?: return intent.putExtra(Mavericks.KEY_ARG, timelineArgs) currentRoomId = timelineArgs.roomId diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt index 7ea837c035..4288ea148d 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/TimelineFragment.kt @@ -774,7 +774,7 @@ class TimelineFragment : } // We use a custom layout for this menu item, so we need to set a ClickListener menu.findItem(R.id.open_matrix_apps)?.let { menuItem -> - menuItem.actionView.debouncedClicks { + menuItem.actionView?.debouncedClicks { handleMenuItemSelected(menuItem) } } @@ -785,7 +785,7 @@ class TimelineFragment : // Custom thread notification menu item menu.findItem(R.id.menu_timeline_thread_list)?.let { menuItem -> - menuItem.actionView.debouncedClicks { + menuItem.actionView?.debouncedClicks { handleMenuItemSelected(menuItem) } } @@ -814,16 +814,16 @@ class TimelineFragment : // icon should be default color no badge val actionView = matrixAppsMenuItem.actionView actionView - .findViewById(R.id.action_view_icon_image) - .setColorFilter(ThemeUtils.getColor(requireContext(), R.attr.vctr_content_secondary)) - actionView.findViewById(R.id.cart_badge).isVisible = false + ?.findViewById(R.id.action_view_icon_image) + ?.setColorFilter(ThemeUtils.getColor(requireContext(), R.attr.vctr_content_secondary)) + actionView?.findViewById(R.id.cart_badge)?.isVisible = false matrixAppsMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER) } else { val actionView = matrixAppsMenuItem.actionView actionView - .findViewById(R.id.action_view_icon_image) - .setColorFilter(colorProvider.getColorFromAttribute(R.attr.colorPrimary)) - actionView.findViewById(R.id.cart_badge).setTextOrHide("$widgetsCount") + ?.findViewById(R.id.action_view_icon_image) + ?.setColorFilter(colorProvider.getColorFromAttribute(R.attr.colorPrimary)) + actionView?.findViewById(R.id.cart_badge)?.setTextOrHide("$widgetsCount") @Suppress("AlwaysShowAction") matrixAppsMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS) } @@ -895,7 +895,7 @@ class TimelineFragment : */ private fun updateMenuThreadNotificationBadge(menu: Menu, state: RoomDetailViewState) { val menuThreadList = menu.findItem(R.id.menu_timeline_thread_list).actionView - val badgeFrameLayout = menuThreadList.findViewById(R.id.threadNotificationBadgeFrameLayout) + val badgeFrameLayout = menuThreadList?.findViewById(R.id.threadNotificationBadgeFrameLayout) ?: return val badgeTextView = menuThreadList.findViewById(R.id.threadNotificationBadgeTextView) val unreadThreadMessages = state.threadNotificationBadgeState.numberOfLocalUnreadThreads diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchActivity.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchActivity.kt index eed596cda0..06f438d78e 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/search/SearchActivity.kt @@ -25,6 +25,7 @@ import dagger.hilt.android.AndroidEntryPoint import im.vector.app.core.extensions.addFragment import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivitySearchBinding +import im.vector.lib.core.utils.compat.getParcelableCompat @AndroidEntryPoint class SearchActivity : VectorBaseActivity() { @@ -46,7 +47,7 @@ class SearchActivity : VectorBaseActivity() { override fun initUiAndData() { if (isFirstCreation()) { - val fragmentArgs: SearchArgs = intent?.extras?.getParcelable(Mavericks.KEY_ARG) ?: return + val fragmentArgs: SearchArgs = intent?.extras?.getParcelableCompat(Mavericks.KEY_ARG) ?: return addFragment(views.searchFragmentContainer, SearchFragment::class.java, fragmentArgs, FRAGMENT_TAG) } views.searchView.setOnQueryTextListener(object : SearchView.OnQueryTextListener { diff --git a/vector/src/main/java/im/vector/app/features/home/room/threads/ThreadsActivity.kt b/vector/src/main/java/im/vector/app/features/home/room/threads/ThreadsActivity.kt index 71a24da5ae..0ee0beb2e6 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/threads/ThreadsActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/threads/ThreadsActivity.kt @@ -34,6 +34,7 @@ import im.vector.app.features.home.room.detail.arguments.TimelineArgs import im.vector.app.features.home.room.threads.arguments.ThreadListArgs import im.vector.app.features.home.room.threads.arguments.ThreadTimelineArgs import im.vector.app.features.home.room.threads.list.views.ThreadListFragment +import im.vector.lib.core.utils.compat.getParcelableCompat import javax.inject.Inject @AndroidEntryPoint @@ -129,8 +130,8 @@ class ThreadsActivity : VectorBaseActivity() { return DisplayFragment.ErrorFragment } - private fun getThreadTimelineArgs(): ThreadTimelineArgs? = intent?.extras?.getParcelable(THREAD_TIMELINE_ARGS) - private fun getThreadListArgs(): ThreadListArgs? = intent?.extras?.getParcelable(THREAD_LIST_ARGS) + private fun getThreadTimelineArgs(): ThreadTimelineArgs? = intent?.extras?.getParcelableCompat(THREAD_TIMELINE_ARGS) + private fun getThreadListArgs(): ThreadListArgs? = intent?.extras?.getParcelableCompat(THREAD_LIST_ARGS) private fun getEventIdToNavigate(): String? = intent?.extras?.getString(THREAD_EVENT_ID_TO_NAVIGATE) companion object { diff --git a/vector/src/main/java/im/vector/app/features/home/room/threads/list/views/ThreadListFragment.kt b/vector/src/main/java/im/vector/app/features/home/room/threads/list/views/ThreadListFragment.kt index ef07067bac..f91fe9bd91 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/threads/list/views/ThreadListFragment.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/threads/list/views/ThreadListFragment.kt @@ -78,7 +78,7 @@ class ThreadListFragment : override fun handlePostCreateMenu(menu: Menu) { // We use a custom layout for this menu item, so we need to set a ClickListener menu.findItem(R.id.menu_thread_list_filter)?.let { menuItem -> - menuItem.actionView.debouncedClicks { + menuItem.actionView?.debouncedClicks { handleMenuItemSelected(menuItem) } } @@ -96,7 +96,7 @@ class ThreadListFragment : override fun handlePrepareMenu(menu: Menu) { withState(threadListViewModel) { state -> - val filterIcon = menu.findItem(R.id.menu_thread_list_filter).actionView + val filterIcon = menu.findItem(R.id.menu_thread_list_filter).actionView ?: return@withState val filterBadge = filterIcon.findViewById(R.id.threadListFilterBadge) filterBadge.isVisible = state.shouldFilterThreads when (threadListViewModel.canHomeserverUseThreading()) { diff --git a/vector/src/main/java/im/vector/app/features/lifecycle/VectorActivityLifecycleCallbacks.kt b/vector/src/main/java/im/vector/app/features/lifecycle/VectorActivityLifecycleCallbacks.kt index 5bdd92dcf4..26024148f4 100644 --- a/vector/src/main/java/im/vector/app/features/lifecycle/VectorActivityLifecycleCallbacks.kt +++ b/vector/src/main/java/im/vector/app/features/lifecycle/VectorActivityLifecycleCallbacks.kt @@ -34,6 +34,7 @@ import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.launch import kotlinx.coroutines.withContext import org.matrix.android.sdk.api.extensions.tryOrNull +import org.matrix.android.sdk.api.util.getPackageInfoCompat import timber.log.Timber class VectorActivityLifecycleCallbacks constructor(private val popupAlertManager: PopupAlertManager) : Application.ActivityLifecycleCallbacks { @@ -64,16 +65,16 @@ class VectorActivityLifecycleCallbacks constructor(private val popupAlertManager val packageManager: PackageManager = context.packageManager // Get all activities from element android - activitiesInfo = packageManager.getPackageInfo(context.packageName, PackageManager.GET_ACTIVITIES).activities + activitiesInfo = packageManager.getPackageInfoCompat(context.packageName, PackageManager.GET_ACTIVITIES).activities // Get all activities from PermissionController module // See https://source.android.com/docs/core/architecture/modular-system/permissioncontroller#package-format if (Build.VERSION.SDK_INT > Build.VERSION_CODES.S_V2) { activitiesInfo += tryOrNull { - packageManager.getPackageInfo("com.google.android.permissioncontroller", PackageManager.GET_ACTIVITIES).activities + packageManager.getPackageInfoCompat("com.google.android.permissioncontroller", PackageManager.GET_ACTIVITIES).activities } ?: tryOrNull { packageManager.getModuleInfo("com.google.android.permission", 1).packageName?.let { - packageManager.getPackageInfo(it, PackageManager.GET_ACTIVITIES or PackageManager.MATCH_APEX).activities + packageManager.getPackageInfoCompat(it, PackageManager.GET_ACTIVITIES or PackageManager.MATCH_APEX).activities } }.orEmpty() } diff --git a/vector/src/main/java/im/vector/app/features/location/LocationSharingActivity.kt b/vector/src/main/java/im/vector/app/features/location/LocationSharingActivity.kt index 9eddcad649..b4d2a1a565 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationSharingActivity.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationSharingActivity.kt @@ -24,6 +24,7 @@ import im.vector.app.core.extensions.addFragment import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivityLocationSharingBinding import im.vector.app.features.location.preview.LocationPreviewFragment +import im.vector.lib.core.utils.compat.getParcelableCompat import kotlinx.parcelize.Parcelize @Parcelize @@ -40,7 +41,7 @@ class LocationSharingActivity : VectorBaseActivity(), UnlockedA loginViewModel.observeViewEvents { handleLoginViewEvents(it) } // Get config extra - val loginConfig = intent.getParcelableExtra(EXTRA_CONFIG) + val loginConfig = intent.getParcelableExtraCompat(EXTRA_CONFIG) if (isFirstCreation()) { loginViewModel.handle(LoginAction.InitWith(loginConfig)) } diff --git a/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt index 08d87b528c..6177fb5857 100644 --- a/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt +++ b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt @@ -47,6 +47,8 @@ import im.vector.app.features.themes.ActivityOtherThemes import im.vector.app.features.themes.ThemeUtils import im.vector.lib.attachmentviewer.AttachmentCommands import im.vector.lib.attachmentviewer.AttachmentViewerActivity +import im.vector.lib.core.utils.compat.getParcelableArrayListExtraCompat +import im.vector.lib.core.utils.compat.getParcelableExtraCompat import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -105,7 +107,7 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt transitionImageContainer.isVisible = true // Postpone transaction a bit until thumbnail is loaded - val mediaData: Parcelable? = intent.getParcelableExtra(EXTRA_IMAGE_DATA) + val mediaData: Parcelable? = intent.getParcelableExtraCompat(EXTRA_IMAGE_DATA) if (mediaData is ImageContentRenderer.Data) { // will be shown at end of transition pager2.isInvisible = true @@ -130,7 +132,7 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt val room = args.roomId?.let { session.getRoom(it) } - val inMemoryData = intent.getParcelableArrayListExtra(EXTRA_IN_MEMORY_DATA) + val inMemoryData = intent.getParcelableArrayListExtraCompat(EXTRA_IN_MEMORY_DATA) val sourceProvider = if (inMemoryData != null) { initialIndex = inMemoryData.indexOfFirst { it.eventId == args.eventId }.coerceAtLeast(0) dataSourceFactory.createProvider(inMemoryData, room, lifecycleScope) @@ -227,7 +229,7 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt return false } - private fun args() = intent.getParcelableExtra(EXTRA_ARGS) + private fun args() = intent.getParcelableExtraCompat(EXTRA_ARGS) private fun scheduleStartPostponedTransition(sharedElement: View) { sharedElement.viewTreeObserver.addOnPreDrawListener( diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt index 6fe1b5b7bb..7467104da1 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/FtueAuthVariant.kt @@ -54,6 +54,7 @@ import im.vector.app.features.onboarding.OnboardingViewState import im.vector.app.features.onboarding.ftueauth.terms.FtueAuthLegacyStyleTermsFragment import im.vector.app.features.onboarding.ftueauth.terms.FtueAuthTermsFragment import im.vector.app.features.onboarding.ftueauth.terms.FtueAuthTermsLegacyStyleFragmentArgument +import im.vector.lib.core.utils.compat.getParcelableExtraCompat import org.matrix.android.sdk.api.auth.registration.Stage import org.matrix.android.sdk.api.auth.toLocalizedLoginTerms import org.matrix.android.sdk.api.extensions.tryOrNull @@ -107,7 +108,7 @@ class FtueAuthVariant( } // Get config extra - val loginConfig = activity.intent.getParcelableExtra(OnboardingActivity.EXTRA_CONFIG) + val loginConfig = activity.intent.getParcelableExtraCompat(OnboardingActivity.EXTRA_CONFIG) if (isFirstCreation) { onboardingViewModel.handle(OnboardingAction.InitWith(loginConfig)) } diff --git a/vector/src/main/java/im/vector/app/features/pin/PinActivity.kt b/vector/src/main/java/im/vector/app/features/pin/PinActivity.kt index faf15d8006..cef0064fd0 100644 --- a/vector/src/main/java/im/vector/app/features/pin/PinActivity.kt +++ b/vector/src/main/java/im/vector/app/features/pin/PinActivity.kt @@ -23,6 +23,7 @@ import dagger.hilt.android.AndroidEntryPoint import im.vector.app.core.extensions.addFragment import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivitySimpleBinding +import im.vector.lib.core.utils.compat.getParcelableCompat @AndroidEntryPoint class PinActivity : VectorBaseActivity(), UnlockedActivity { @@ -41,7 +42,7 @@ class PinActivity : VectorBaseActivity(), UnlockedActivit override fun initUiAndData() { if (isFirstCreation()) { - val fragmentArgs: PinArgs = intent?.extras?.getParcelable(Mavericks.KEY_ARG) ?: return + val fragmentArgs: PinArgs = intent?.extras?.getParcelableCompat(Mavericks.KEY_ARG) ?: return addFragment(views.simpleFragmentContainer, PinFragment::class.java, fragmentArgs) } } diff --git a/vector/src/main/java/im/vector/app/features/poll/create/CreatePollActivity.kt b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollActivity.kt index 5a93e19b1a..3dfec3c255 100644 --- a/vector/src/main/java/im/vector/app/features/poll/create/CreatePollActivity.kt +++ b/vector/src/main/java/im/vector/app/features/poll/create/CreatePollActivity.kt @@ -23,6 +23,7 @@ import android.view.View import dagger.hilt.android.AndroidEntryPoint import im.vector.app.core.extensions.addFragment import im.vector.app.core.platform.SimpleFragmentActivity +import im.vector.lib.core.utils.compat.getParcelableCompat @AndroidEntryPoint class CreatePollActivity : SimpleFragmentActivity() { @@ -31,7 +32,7 @@ class CreatePollActivity : SimpleFragmentActivity() { super.onCreate(savedInstanceState) views.toolbar.visibility = View.GONE - val createPollArgs: CreatePollArgs? = intent?.extras?.getParcelable(EXTRA_CREATE_POLL_ARGS) + val createPollArgs: CreatePollArgs? = intent?.extras?.getParcelableCompat(EXTRA_CREATE_POLL_ARGS) if (isFirstCreation()) { addFragment( diff --git a/vector/src/main/java/im/vector/app/features/rageshake/BugReportActivity.kt b/vector/src/main/java/im/vector/app/features/rageshake/BugReportActivity.kt index c7f549c5cb..b19a98b3ce 100755 --- a/vector/src/main/java/im/vector/app/features/rageshake/BugReportActivity.kt +++ b/vector/src/main/java/im/vector/app/features/rageshake/BugReportActivity.kt @@ -128,7 +128,7 @@ class BugReportActivity : val isValid = !views.bugReportMaskView.isVisible it.isEnabled = isValid - it.icon.alpha = if (isValid) 255 else 100 + it.icon?.alpha = if (isValid) 255 else 100 } } diff --git a/vector/src/main/java/im/vector/app/features/reactions/EmojiReactionPickerActivity.kt b/vector/src/main/java/im/vector/app/features/reactions/EmojiReactionPickerActivity.kt index f9be57b13f..24a45872d5 100644 --- a/vector/src/main/java/im/vector/app/features/reactions/EmojiReactionPickerActivity.kt +++ b/vector/src/main/java/im/vector/app/features/reactions/EmojiReactionPickerActivity.kt @@ -146,7 +146,7 @@ class EmojiReactionPickerActivity : val searchItem = menu.findItem(R.id.search) (searchItem.actionView as? SearchView)?.let { searchView -> searchItem.setOnActionExpandListener(object : MenuItem.OnActionExpandListener { - override fun onMenuItemActionExpand(p0: MenuItem?): Boolean { + override fun onMenuItemActionExpand(p0: MenuItem): Boolean { searchView.isIconified = false searchView.requestFocusFromTouch() // we want to force the tool bar as visible even if hidden with scroll flags @@ -154,7 +154,7 @@ class EmojiReactionPickerActivity : return true } - override fun onMenuItemActionCollapse(p0: MenuItem?): Boolean { + override fun onMenuItemActionCollapse(p0: MenuItem): Boolean { // when back, clear all search views.emojiPickerToolbar.minimumHeight = 0 searchView.setQuery("", true) diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomActivity.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomActivity.kt index d2b9b16086..171d51e811 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomActivity.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomActivity.kt @@ -29,6 +29,7 @@ import im.vector.app.databinding.ActivitySimpleBinding import im.vector.app.features.analytics.plan.MobileScreen import im.vector.app.features.roomdirectory.RoomDirectorySharedAction import im.vector.app.features.roomdirectory.RoomDirectorySharedActionViewModel +import im.vector.lib.core.utils.compat.getParcelableCompat import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -46,7 +47,7 @@ class CreateRoomActivity : VectorBaseActivity() { override fun initUiAndData() { if (isFirstCreation()) { - val fragmentArgs: CreateRoomArgs = intent?.extras?.getParcelable(Mavericks.KEY_ARG) ?: return + val fragmentArgs: CreateRoomArgs = intent?.extras?.getParcelableCompat(Mavericks.KEY_ARG) ?: return addFragment( views.simpleFragmentContainer, CreateRoomFragment::class.java, diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewActivity.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewActivity.kt index b69788b1ed..a70fd5ef23 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewActivity.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/roompreview/RoomPreviewActivity.kt @@ -24,6 +24,7 @@ import im.vector.app.core.extensions.addFragment import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivitySimpleBinding import im.vector.app.features.roomdirectory.RoomDirectoryData +import im.vector.lib.core.utils.compat.getParcelableExtraCompat import kotlinx.parcelize.Parcelize import org.matrix.android.sdk.api.session.permalinks.PermalinkData import org.matrix.android.sdk.api.session.room.model.roomdirectory.PublicRoom @@ -83,7 +84,7 @@ class RoomPreviewActivity : VectorBaseActivity() { override fun initUiAndData() { if (isFirstCreation()) { - val args = intent.getParcelableExtra(ARG) + val args = intent.getParcelableExtraCompat(ARG) if (args?.worldReadable == true) { // TODO Room preview: Note: M does not recommend to use /events anymore, so for now we just display the room preview diff --git a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileActivity.kt b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileActivity.kt index 1b55207743..26a2a7de22 100644 --- a/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileActivity.kt +++ b/vector/src/main/java/im/vector/app/features/roommemberprofile/RoomMemberProfileActivity.kt @@ -28,6 +28,7 @@ import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivitySimpleBinding import im.vector.app.features.room.RequireActiveMembershipViewEvents import im.vector.app.features.room.RequireActiveMembershipViewModel +import im.vector.lib.core.utils.compat.getParcelableCompat @AndroidEntryPoint class RoomMemberProfileActivity : VectorBaseActivity() { @@ -48,7 +49,7 @@ class RoomMemberProfileActivity : VectorBaseActivity() { override fun initUiAndData() { if (isFirstCreation()) { - val fragmentArgs: RoomMemberProfileArgs = intent?.extras?.getParcelable(Mavericks.KEY_ARG) ?: return + val fragmentArgs: RoomMemberProfileArgs = intent?.extras?.getParcelableCompat(Mavericks.KEY_ARG) ?: return addFragment(views.simpleFragmentContainer, RoomMemberProfileFragment::class.java, fragmentArgs) } diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileActivity.kt b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileActivity.kt index 12f1db1366..2bb3e26384 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileActivity.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/RoomProfileActivity.kt @@ -38,6 +38,7 @@ import im.vector.app.features.roomprofile.notifications.RoomNotificationSettings import im.vector.app.features.roomprofile.permissions.RoomPermissionsFragment import im.vector.app.features.roomprofile.settings.RoomSettingsFragment import im.vector.app.features.roomprofile.uploads.RoomUploadsFragment +import im.vector.lib.core.utils.compat.getParcelableCompat import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import javax.inject.Inject @@ -77,7 +78,7 @@ class RoomProfileActivity : override fun initUiAndData() { sharedActionViewModel = viewModelProvider.get(RoomProfileSharedActionViewModel::class.java) - roomProfileArgs = intent?.extras?.getParcelable(Mavericks.KEY_ARG) ?: return + roomProfileArgs = intent?.extras?.getParcelableCompat(Mavericks.KEY_ARG) ?: return if (isFirstCreation()) { when (intent?.extras?.getInt(EXTRA_DIRECT_ACCESS, EXTRA_DIRECT_ACCESS_ROOM_ROOT)) { EXTRA_DIRECT_ACCESS_ROOM_SETTINGS -> { diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/settings/joinrule/RoomJoinRuleActivity.kt b/vector/src/main/java/im/vector/app/features/roomprofile/settings/joinrule/RoomJoinRuleActivity.kt index e7b0087755..205fb86377 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/settings/joinrule/RoomJoinRuleActivity.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/settings/joinrule/RoomJoinRuleActivity.kt @@ -43,6 +43,7 @@ import im.vector.app.features.roomprofile.settings.joinrule.advanced.RoomJoinRul import im.vector.app.features.roomprofile.settings.joinrule.advanced.RoomJoinRuleChooseRestrictedFragment import im.vector.app.features.roomprofile.settings.joinrule.advanced.RoomJoinRuleChooseRestrictedState import im.vector.app.features.roomprofile.settings.joinrule.advanced.RoomJoinRuleChooseRestrictedViewModel +import im.vector.lib.core.utils.compat.getParcelableCompat import javax.inject.Inject @AndroidEntryPoint @@ -58,7 +59,7 @@ class RoomJoinRuleActivity : VectorBaseActivity() { val viewModel: RoomJoinRuleChooseRestrictedViewModel by viewModel() override fun initUiAndData() { - roomProfileArgs = intent?.extras?.getParcelable(Mavericks.KEY_ARG) ?: return + roomProfileArgs = intent?.extras?.getParcelableCompat(Mavericks.KEY_ARG) ?: return if (isFirstCreation()) { addFragment( views.simpleFragmentContainer, diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsActivity.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsActivity.kt index 261f30ebe3..9a84412482 100755 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsActivity.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsActivity.kt @@ -34,6 +34,7 @@ import im.vector.app.features.navigation.SettingsActivityPayload import im.vector.app.features.settings.devices.VectorSettingsDevicesFragment import im.vector.app.features.settings.notifications.VectorSettingsNotificationPreferenceFragment import im.vector.app.features.settings.threepids.ThreePidsSettingsFragment +import im.vector.lib.core.utils.compat.getParcelableExtraCompat import org.matrix.android.sdk.api.failure.GlobalError import org.matrix.android.sdk.api.session.Session import timber.log.Timber @@ -194,8 +195,8 @@ class VectorSettingsActivity : VectorBaseActivity } } -private fun Activity.readPayload(default: T): T { - return intent.getParcelableExtra(KEY_ACTIVITY_PAYLOAD) ?: default +private inline fun Activity.readPayload(default: T): T { + return intent.getParcelableExtraCompat(KEY_ACTIVITY_PAYLOAD) ?: default } private fun Intent.applyPayload(payload: T): Intent { diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsVoiceVideoFragment.kt b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsVoiceVideoFragment.kt index 28e167779d..1cb7dcbf28 100644 --- a/vector/src/main/java/im/vector/app/features/settings/VectorSettingsVoiceVideoFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorSettingsVoiceVideoFragment.kt @@ -29,6 +29,7 @@ import im.vector.app.core.extensions.registerStartForActivityResult import im.vector.app.core.preference.VectorPreference import im.vector.app.core.utils.RingtoneUtils import im.vector.app.features.analytics.plan.MobileScreen +import im.vector.lib.core.utils.compat.getParcelableExtraCompat import javax.inject.Inject @AndroidEntryPoint @@ -69,7 +70,7 @@ class VectorSettingsVoiceVideoFragment : VectorSettingsBaseFragment() { private val ringtoneStartForActivityResult = registerStartForActivityResult { activityResult -> if (activityResult.resultCode == Activity.RESULT_OK) { - val callRingtoneUri: Uri? = activityResult.data?.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) + val callRingtoneUri: Uri? = activityResult.data?.getParcelableExtraCompat(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) if (callRingtoneUri != null) { ringtoneUtils.setCallRingtoneUri(callRingtoneUri) mCallRingtonePreference.summary = ringtoneUtils.getCallRingtoneName() diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/details/SessionDetailsActivity.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/details/SessionDetailsActivity.kt index 101bf1da2e..fb4e94b630 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/details/SessionDetailsActivity.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/details/SessionDetailsActivity.kt @@ -23,6 +23,7 @@ import com.airbnb.mvrx.Mavericks import dagger.hilt.android.AndroidEntryPoint import im.vector.app.core.extensions.addFragment import im.vector.app.core.platform.SimpleFragmentActivity +import im.vector.lib.core.utils.compat.getParcelableExtraCompat /** * Display the details info about a Session. @@ -37,7 +38,7 @@ class SessionDetailsActivity : SimpleFragmentActivity() { addFragment( container = views.container, fragmentClass = SessionDetailsFragment::class.java, - params = intent.getParcelableExtra(Mavericks.KEY_ARG) + params = intent.getParcelableExtraCompat(Mavericks.KEY_ARG) ) } } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsActivity.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsActivity.kt index f146f77690..81e38e0e9d 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsActivity.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsActivity.kt @@ -26,6 +26,7 @@ import dagger.hilt.android.AndroidEntryPoint import im.vector.app.core.extensions.addFragment import im.vector.app.core.platform.SimpleFragmentActivity import im.vector.app.features.settings.devices.v2.filter.DeviceManagerFilterType +import im.vector.lib.core.utils.compat.getParcelableExtraCompat @AndroidEntryPoint class OtherSessionsActivity : SimpleFragmentActivity() { @@ -39,7 +40,7 @@ class OtherSessionsActivity : SimpleFragmentActivity() { addFragment( container = views.container, fragmentClass = OtherSessionsFragment::class.java, - params = intent.getParcelableExtra(Mavericks.KEY_ARG) + params = intent.getParcelableExtraCompat(Mavericks.KEY_ARG) ) } } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewActivity.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewActivity.kt index 015fcccf51..5695d02ae9 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewActivity.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewActivity.kt @@ -23,6 +23,7 @@ import com.airbnb.mvrx.Mavericks import dagger.hilt.android.AndroidEntryPoint import im.vector.app.core.extensions.addFragment import im.vector.app.core.platform.SimpleFragmentActivity +import im.vector.lib.core.utils.compat.getParcelableExtraCompat /** * Display the overview info about a Session. @@ -37,7 +38,7 @@ class SessionOverviewActivity : SimpleFragmentActivity() { addFragment( container = views.container, fragmentClass = SessionOverviewFragment::class.java, - params = intent.getParcelableExtra(Mavericks.KEY_ARG) + params = intent.getParcelableExtraCompat(Mavericks.KEY_ARG) ) } } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/rename/RenameSessionActivity.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/rename/RenameSessionActivity.kt index eb0d994ce3..44bc251382 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/rename/RenameSessionActivity.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/rename/RenameSessionActivity.kt @@ -25,6 +25,7 @@ import dagger.hilt.android.AndroidEntryPoint import im.vector.app.core.extensions.addFragment import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivitySimpleBinding +import im.vector.lib.core.utils.compat.getParcelableExtraCompat /** * Display the screen to rename a Session. @@ -42,7 +43,7 @@ class RenameSessionActivity : VectorBaseActivity() { addFragment( container = views.simpleFragmentContainer, fragmentClass = RenameSessionFragment::class.java, - params = intent.getParcelableExtra(Mavericks.KEY_ARG) + params = intent.getParcelableExtraCompat(Mavericks.KEY_ARG) ) } } diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt index 37d09d02c9..ad12ca1be0 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt @@ -53,6 +53,7 @@ import im.vector.app.features.settings.BackgroundSyncModeChooserDialog import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.VectorSettingsBaseFragment import im.vector.app.features.settings.VectorSettingsFragmentInteractionListener +import im.vector.lib.core.utils.compat.getParcelableExtraCompat import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch import org.matrix.android.sdk.api.extensions.tryOrNull @@ -342,7 +343,7 @@ class VectorSettingsNotificationPreferenceFragment : private val ringtoneStartForActivityResult = registerStartForActivityResult { activityResult -> if (activityResult.resultCode == Activity.RESULT_OK) { - vectorPreferences.setNotificationRingTone(activityResult.data?.getParcelableExtra(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) as Uri?) + vectorPreferences.setNotificationRingTone(activityResult.data?.getParcelableExtraCompat(RingtoneManager.EXTRA_RINGTONE_PICKED_URI)) // test if the selected ring tone can be played val notificationRingToneName = vectorPreferences.getNotificationRingToneName() diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpaceExploreActivity.kt b/vector/src/main/java/im/vector/app/features/spaces/SpaceExploreActivity.kt index 6463f6b022..b36dd2df4d 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpaceExploreActivity.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpaceExploreActivity.kt @@ -40,6 +40,7 @@ import im.vector.app.features.spaces.explore.SpaceDirectoryFragment import im.vector.app.features.spaces.explore.SpaceDirectoryViewAction import im.vector.app.features.spaces.explore.SpaceDirectoryViewEvents import im.vector.app.features.spaces.explore.SpaceDirectoryViewModel +import im.vector.lib.core.utils.compat.getParcelableExtraCompat @AndroidEntryPoint class SpaceExploreActivity : VectorBaseActivity(), MatrixToBottomSheet.InteractionListener { @@ -80,7 +81,7 @@ class SpaceExploreActivity : VectorBaseActivity(), Matrix supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentLifecycleCallbacks, false) if (isFirstCreation()) { - val args = intent?.getParcelableExtra(Mavericks.KEY_ARG) + val args = intent?.getParcelableExtraCompat(Mavericks.KEY_ARG) replaceFragment( views.simpleFragmentContainer, SpaceDirectoryFragment::class.java, diff --git a/vector/src/main/java/im/vector/app/features/spaces/SpacePreviewActivity.kt b/vector/src/main/java/im/vector/app/features/spaces/SpacePreviewActivity.kt index db4c2cbe65..06d413e0b2 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/SpacePreviewActivity.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/SpacePreviewActivity.kt @@ -27,6 +27,7 @@ import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivitySimpleBinding import im.vector.app.features.spaces.preview.SpacePreviewArgs import im.vector.app.features.spaces.preview.SpacePreviewFragment +import im.vector.lib.core.utils.compat.getParcelableExtraCompat import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -53,7 +54,7 @@ class SpacePreviewActivity : VectorBaseActivity() { .launchIn(lifecycleScope) if (isFirstCreation()) { - val args = intent?.getParcelableExtra(Mavericks.KEY_ARG) + val args = intent?.getParcelableExtraCompat(Mavericks.KEY_ARG) replaceFragment( views.simpleFragmentContainer, SpacePreviewFragment::class.java, diff --git a/vector/src/main/java/im/vector/app/features/spaces/leave/SpaceLeaveAdvancedActivity.kt b/vector/src/main/java/im/vector/app/features/spaces/leave/SpaceLeaveAdvancedActivity.kt index f661b92dac..80959c61a1 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/leave/SpaceLeaveAdvancedActivity.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/leave/SpaceLeaveAdvancedActivity.kt @@ -36,6 +36,7 @@ import im.vector.app.core.extensions.setTextOrHide import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivitySimpleLoadingBinding import im.vector.app.features.spaces.SpaceBottomSheetSettingsArgs +import im.vector.lib.core.utils.compat.getParcelableExtraCompat import javax.inject.Inject @AndroidEntryPoint @@ -63,7 +64,7 @@ class SpaceLeaveAdvancedActivity : VectorBaseActivity(Mavericks.KEY_ARG) + val args = intent?.getParcelableExtraCompat(Mavericks.KEY_ARG) if (isFirstCreation()) { replaceFragment( diff --git a/vector/src/main/java/im/vector/app/features/spaces/leave/SpaceLeaveAdvancedFragment.kt b/vector/src/main/java/im/vector/app/features/spaces/leave/SpaceLeaveAdvancedFragment.kt index ea06a12f08..da6b43aede 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/leave/SpaceLeaveAdvancedFragment.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/leave/SpaceLeaveAdvancedFragment.kt @@ -150,12 +150,12 @@ class SpaceLeaveAdvancedFragment : onTextChanged: (String) -> Unit ) { setOnActionExpandListener(object : MenuItem.OnActionExpandListener { - override fun onMenuItemActionExpand(item: MenuItem?): Boolean { + override fun onMenuItemActionExpand(item: MenuItem): Boolean { onExpanded() return true } - override fun onMenuItemActionCollapse(item: MenuItem?): Boolean { + override fun onMenuItemActionCollapse(item: MenuItem): Boolean { onCollapsed() return true } diff --git a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageActivity.kt b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageActivity.kt index d5d4c86563..a246bd29aa 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageActivity.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceManageActivity.kt @@ -40,6 +40,7 @@ import im.vector.app.features.roomdirectory.createroom.CreateRoomFragment import im.vector.app.features.roomprofile.RoomProfileArgs import im.vector.app.features.roomprofile.alias.RoomAliasFragment import im.vector.app.features.roomprofile.permissions.RoomPermissionsFragment +import im.vector.lib.core.utils.compat.getParcelableExtraCompat import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import kotlinx.parcelize.Parcelize @@ -90,7 +91,7 @@ class SpaceManageActivity : VectorBaseActivity() { } .launchIn(lifecycleScope) - val args = intent?.getParcelableExtra(Mavericks.KEY_ARG) + val args = intent?.getParcelableExtraCompat(Mavericks.KEY_ARG) if (isFirstCreation()) { withState(sharedViewModel) { when (it.manageType) { diff --git a/vector/src/main/java/im/vector/app/features/spaces/people/SpacePeopleActivity.kt b/vector/src/main/java/im/vector/app/features/spaces/people/SpacePeopleActivity.kt index f214f77724..0e7a9e4edf 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/people/SpacePeopleActivity.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/people/SpacePeopleActivity.kt @@ -32,6 +32,7 @@ import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivitySimpleLoadingBinding import im.vector.app.features.analytics.plan.ViewRoom import im.vector.app.features.spaces.share.ShareSpaceBottomSheet +import im.vector.lib.core.utils.compat.getParcelableExtraCompat import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -63,7 +64,7 @@ class SpacePeopleActivity : VectorBaseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - val args = intent?.getParcelableExtra(Mavericks.KEY_ARG) + val args = intent?.getParcelableExtraCompat(Mavericks.KEY_ARG) if (isFirstCreation()) { replaceFragment( views.simpleFragmentContainer, diff --git a/vector/src/main/java/im/vector/app/features/terms/ReviewTermsActivity.kt b/vector/src/main/java/im/vector/app/features/terms/ReviewTermsActivity.kt index 5466ef2339..d261a8d160 100644 --- a/vector/src/main/java/im/vector/app/features/terms/ReviewTermsActivity.kt +++ b/vector/src/main/java/im/vector/app/features/terms/ReviewTermsActivity.kt @@ -25,6 +25,7 @@ import im.vector.app.R import im.vector.app.core.error.ErrorFormatter import im.vector.app.core.extensions.replaceFragment import im.vector.app.core.platform.SimpleFragmentActivity +import im.vector.lib.core.utils.compat.getParcelableExtraCompat import org.matrix.android.sdk.api.session.terms.TermsService import javax.inject.Inject @@ -42,7 +43,7 @@ class ReviewTermsActivity : SimpleFragmentActivity() { replaceFragment(views.container, ReviewTermsFragment::class.java) } - reviewTermsViewModel.termsArgs = intent.getParcelableExtra(EXTRA_INFO) ?: error("Missing parameter") + reviewTermsViewModel.termsArgs = intent.getParcelableExtraCompat(EXTRA_INFO) ?: error("Missing parameter") reviewTermsViewModel.observeViewEvents { when (it) { diff --git a/vector/src/main/java/im/vector/app/features/webview/VectorWebViewActivity.kt b/vector/src/main/java/im/vector/app/features/webview/VectorWebViewActivity.kt index 0678d5143d..e21bef193f 100644 --- a/vector/src/main/java/im/vector/app/features/webview/VectorWebViewActivity.kt +++ b/vector/src/main/java/im/vector/app/features/webview/VectorWebViewActivity.kt @@ -24,6 +24,7 @@ import dagger.hilt.android.AndroidEntryPoint import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.databinding.ActivityVectorWebViewBinding +import im.vector.lib.core.utils.compat.getSerializableCompat import org.matrix.android.sdk.api.session.Session import javax.inject.Inject @@ -79,7 +80,7 @@ class VectorWebViewActivity : VectorBaseActivity() setTitle(title) } - val webViewMode = intent.extras?.getSerializable(EXTRA_MODE) as WebViewMode + val webViewMode = intent.extras?.getSerializableCompat(EXTRA_MODE)!! val eventListener = webViewMode.eventListener(this, session) views.simpleWebview.webViewClient = VectorWebViewClient(eventListener) views.simpleWebview.webChromeClient = object : WebChromeClient() { diff --git a/vector/src/main/java/im/vector/app/features/widgets/WidgetActivity.kt b/vector/src/main/java/im/vector/app/features/widgets/WidgetActivity.kt index 91aa3a4e6a..586e4dcc6e 100644 --- a/vector/src/main/java/im/vector/app/features/widgets/WidgetActivity.kt +++ b/vector/src/main/java/im/vector/app/features/widgets/WidgetActivity.kt @@ -43,6 +43,8 @@ import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.widgets.permissions.RoomWidgetPermissionBottomSheet import im.vector.app.features.widgets.permissions.RoomWidgetPermissionViewEvents import im.vector.app.features.widgets.permissions.RoomWidgetPermissionViewModel +import im.vector.lib.core.utils.compat.getParcelableCompat +import im.vector.lib.core.utils.compat.getSerializableCompat import org.matrix.android.sdk.api.extensions.orFalse import org.matrix.android.sdk.api.session.events.model.Content import java.io.Serializable @@ -68,7 +70,7 @@ class WidgetActivity : VectorBaseActivity() { @Suppress("UNCHECKED_CAST") fun getOutput(intent: Intent): Content? { - return intent.extras?.getSerializable(EXTRA_RESULT) as? Content + return intent.extras?.getSerializableCompat(EXTRA_RESULT) as? Content } private fun createResultIntent(content: Content): Intent { @@ -88,7 +90,7 @@ class WidgetActivity : VectorBaseActivity() { override fun getTitleRes() = R.string.room_widget_activity_title override fun initUiAndData() { - val widgetArgs: WidgetArgs? = intent?.extras?.getParcelable(Mavericks.KEY_ARG) + val widgetArgs: WidgetArgs? = intent?.extras?.getParcelableCompat(Mavericks.KEY_ARG) if (widgetArgs == null) { finish() return @@ -150,7 +152,7 @@ class WidgetActivity : VectorBaseActivity() { override fun onUserLeaveHint() { super.onUserLeaveHint() - val widgetArgs: WidgetArgs? = intent?.extras?.getParcelable(Mavericks.KEY_ARG) + val widgetArgs: WidgetArgs? = intent?.extras?.getParcelableCompat(Mavericks.KEY_ARG) if (widgetArgs?.kind?.supportsPictureInPictureMode().orFalse()) { enterPictureInPicture() } diff --git a/vector/src/main/java/im/vector/app/features/widgets/WidgetFragment.kt b/vector/src/main/java/im/vector/app/features/widgets/WidgetFragment.kt index 4d94493d17..944ee627d7 100644 --- a/vector/src/main/java/im/vector/app/features/widgets/WidgetFragment.kt +++ b/vector/src/main/java/im/vector/app/features/widgets/WidgetFragment.kt @@ -52,6 +52,7 @@ import im.vector.app.features.webview.WebEventListener import im.vector.app.features.widgets.webview.WebviewPermissionUtils import im.vector.app.features.widgets.webview.clearAfterWidget import im.vector.app.features.widgets.webview.setupForWidget +import im.vector.lib.core.utils.compat.resolveActivityCompat import kotlinx.parcelize.Parcelize import org.matrix.android.sdk.api.session.terms.TermsService import timber.log.Timber @@ -264,7 +265,7 @@ class WidgetFragment : val intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME) if (intent != null) { val packageManager: PackageManager = context.packageManager - val info = packageManager.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY) + val info = packageManager.resolveActivityCompat(intent, PackageManager.MATCH_DEFAULT_ONLY) if (info != null) { context.startActivity(intent) } else { From e76b2d7c61e190cc73844f348367743e2acd89e1 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 28 Sep 2022 14:43:00 +0200 Subject: [PATCH 08/80] Suppress deprecation warning for `onBackPressed()`. The required change are too big, this will be handled separately. --- .../im/vector/app/core/platform/SimpleFragmentActivity.kt | 1 + .../java/im/vector/app/core/platform/VectorBaseActivity.kt | 1 + .../java/im/vector/app/features/call/VectorCallActivity.kt | 2 ++ .../app/features/createdirect/CreateDirectRoomActivity.kt | 1 + .../crypto/keysbackup/restore/KeysBackupRestoreActivity.kt | 1 + .../crypto/keysbackup/settings/KeysBackupManageActivity.kt | 1 + .../crypto/keysbackup/setup/KeysBackupSetupActivity.kt | 1 + .../main/java/im/vector/app/features/home/HomeActivity.kt | 5 ++++- .../app/features/home/room/detail/RoomDetailActivity.kt | 1 + .../vector/app/features/invite/InviteUsersToRoomActivity.kt | 1 + .../im/vector/app/features/login/AbstractLoginFragment.kt | 2 ++ .../main/java/im/vector/app/features/login/LoginActivity.kt | 5 ++++- .../app/features/media/VectorAttachmentViewerActivity.kt | 1 + .../im/vector/app/features/onboarding/OnboardingActivity.kt | 5 ++++- .../features/onboarding/ftueauth/AbstractFtueAuthFragment.kt | 2 ++ .../im/vector/app/features/rageshake/BugReportActivity.kt | 1 + .../features/roomdirectory/createroom/CreateRoomFragment.kt | 5 ++++- .../features/roomprofile/settings/RoomSettingsFragment.kt | 1 + .../app/features/spaces/manage/SpaceSettingsFragment.kt | 1 + .../java/im/vector/app/features/usercode/UserCodeActivity.kt | 5 ++++- .../im/vector/app/features/webview/VectorWebViewActivity.kt | 1 + 21 files changed, 39 insertions(+), 5 deletions(-) diff --git a/vector/src/main/java/im/vector/app/core/platform/SimpleFragmentActivity.kt b/vector/src/main/java/im/vector/app/core/platform/SimpleFragmentActivity.kt index 4cd7da2a4f..794d5c7886 100644 --- a/vector/src/main/java/im/vector/app/core/platform/SimpleFragmentActivity.kt +++ b/vector/src/main/java/im/vector/app/core/platform/SimpleFragmentActivity.kt @@ -83,6 +83,7 @@ abstract class SimpleFragmentActivity : VectorBaseActivity() { // ignore return } + @Suppress("DEPRECATION") super.onBackPressed() } } diff --git a/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt b/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt index 0b8d6698d2..7e61958565 100644 --- a/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt +++ b/vector/src/main/java/im/vector/app/core/platform/VectorBaseActivity.kt @@ -505,6 +505,7 @@ abstract class VectorBaseActivity : AppCompatActivity(), Maver private fun onBackPressed(fromToolbar: Boolean) { val handled = recursivelyDispatchOnBackPressed(supportFragmentManager, fromToolbar) if (!handled) { + @Suppress("DEPRECATION") super.onBackPressed() } } diff --git a/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt b/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt index 7e226304c1..a96097a830 100644 --- a/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt +++ b/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt @@ -194,6 +194,7 @@ class VectorCallActivity : override fun onBackPressed() { if (!enterPictureInPictureIfRequired()) { + @Suppress("DEPRECATION") super.onBackPressed() } } @@ -231,6 +232,7 @@ class VectorCallActivity : } android.R.id.home -> { // We check here as we want PiP in some cases + @Suppress("DEPRECATION") onBackPressed() true } diff --git a/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomActivity.kt b/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomActivity.kt index 707b78d328..fd28235a51 100644 --- a/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomActivity.kt +++ b/vector/src/main/java/im/vector/app/features/createdirect/CreateDirectRoomActivity.kt @@ -78,6 +78,7 @@ class CreateDirectRoomActivity : SimpleFragmentActivity() { sharedActionViewModel .stream() .onEach { action -> + @Suppress("DEPRECATION") when (action) { UserListSharedAction.Close -> finish() UserListSharedAction.GoBack -> onBackPressed() diff --git a/vector/src/main/java/im/vector/app/features/crypto/keysbackup/restore/KeysBackupRestoreActivity.kt b/vector/src/main/java/im/vector/app/features/crypto/keysbackup/restore/KeysBackupRestoreActivity.kt index c6e86f6f6b..f7964cf0ed 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/keysbackup/restore/KeysBackupRestoreActivity.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/keysbackup/restore/KeysBackupRestoreActivity.kt @@ -52,6 +52,7 @@ class KeysBackupRestoreActivity : SimpleFragmentActivity() { override fun onBackPressed() { hideWaitingView() + @Suppress("DEPRECATION") super.onBackPressed() } diff --git a/vector/src/main/java/im/vector/app/features/crypto/keysbackup/settings/KeysBackupManageActivity.kt b/vector/src/main/java/im/vector/app/features/crypto/keysbackup/settings/KeysBackupManageActivity.kt index aabd05d913..32826d013f 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/keysbackup/settings/KeysBackupManageActivity.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/keysbackup/settings/KeysBackupManageActivity.kt @@ -114,6 +114,7 @@ class KeysBackupManageActivity : SimpleFragmentActivity() { finish() return } + @Suppress("DEPRECATION") super.onBackPressed() } } diff --git a/vector/src/main/java/im/vector/app/features/crypto/keysbackup/setup/KeysBackupSetupActivity.kt b/vector/src/main/java/im/vector/app/features/crypto/keysbackup/setup/KeysBackupSetupActivity.kt index 077bcc2cf3..8238da8245 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/keysbackup/setup/KeysBackupSetupActivity.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/keysbackup/setup/KeysBackupSetupActivity.kt @@ -183,6 +183,7 @@ class KeysBackupSetupActivity : SimpleFragmentActivity() { } .show() } else { + @Suppress("DEPRECATION") super.onBackPressed() } } diff --git a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt index 689d141023..18c9e7e3b9 100644 --- a/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/HomeActivity.kt @@ -668,7 +668,10 @@ class HomeActivity : if (views.drawerLayout.isDrawerOpen(GravityCompat.START)) { views.drawerLayout.closeDrawer(GravityCompat.START) } else { - validateBackPressed { super.onBackPressed() } + validateBackPressed { + @Suppress("DEPRECATION") + super.onBackPressed() + } } } diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailActivity.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailActivity.kt index 6b66d0ec47..ecbea133df 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailActivity.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/RoomDetailActivity.kt @@ -178,6 +178,7 @@ class RoomDetailActivity : if (views.drawerLayout.isDrawerOpen(GravityCompat.START)) { views.drawerLayout.closeDrawer(GravityCompat.START) } else { + @Suppress("DEPRECATION") super.onBackPressed() } } diff --git a/vector/src/main/java/im/vector/app/features/invite/InviteUsersToRoomActivity.kt b/vector/src/main/java/im/vector/app/features/invite/InviteUsersToRoomActivity.kt index 883c879e90..86f061849b 100644 --- a/vector/src/main/java/im/vector/app/features/invite/InviteUsersToRoomActivity.kt +++ b/vector/src/main/java/im/vector/app/features/invite/InviteUsersToRoomActivity.kt @@ -68,6 +68,7 @@ class InviteUsersToRoomActivity : SimpleFragmentActivity() { sharedActionViewModel .stream() .onEach { sharedAction -> + @Suppress("DEPRECATION") when (sharedAction) { UserListSharedAction.Close -> finish() UserListSharedAction.GoBack -> onBackPressed() diff --git a/vector/src/main/java/im/vector/app/features/login/AbstractLoginFragment.kt b/vector/src/main/java/im/vector/app/features/login/AbstractLoginFragment.kt index 9512a518e8..6ee276342c 100644 --- a/vector/src/main/java/im/vector/app/features/login/AbstractLoginFragment.kt +++ b/vector/src/main/java/im/vector/app/features/login/AbstractLoginFragment.kt @@ -133,6 +133,7 @@ abstract class AbstractLoginFragment : VectorBaseFragment( .setMessage(R.string.login_signup_cancel_confirmation_content) .setPositiveButton(R.string.yes) { _, _ -> displayCancelDialog = false + @Suppress("DEPRECATION") vectorBaseActivity.onBackPressed() } .setNegativeButton(R.string.no, null) @@ -147,6 +148,7 @@ abstract class AbstractLoginFragment : VectorBaseFragment( .setMessage(R.string.login_reset_password_cancel_confirmation_content) .setPositiveButton(R.string.yes) { _, _ -> displayCancelDialog = false + @Suppress("DEPRECATION") vectorBaseActivity.onBackPressed() } .setNegativeButton(R.string.no, null) diff --git a/vector/src/main/java/im/vector/app/features/login/LoginActivity.kt b/vector/src/main/java/im/vector/app/features/login/LoginActivity.kt index 90917dfecb..4e4df5d1aa 100644 --- a/vector/src/main/java/im/vector/app/features/login/LoginActivity.kt +++ b/vector/src/main/java/im/vector/app/features/login/LoginActivity.kt @@ -317,7 +317,10 @@ open class LoginActivity : VectorBaseActivity(), UnlockedA } override fun onBackPressed() { - validateBackPressed { super.onBackPressed() } + validateBackPressed { + @Suppress("DEPRECATION") + super.onBackPressed() + } } private fun onRegistrationStageNotSupported() { diff --git a/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt index 6177fb5857..d523d99d76 100644 --- a/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt +++ b/vector/src/main/java/im/vector/app/features/media/VectorAttachmentViewerActivity.kt @@ -175,6 +175,7 @@ class VectorAttachmentViewerActivity : AttachmentViewerActivity(), AttachmentInt transitionImageContainer.isVisible = true } isAnimatingOut = true + @Suppress("DEPRECATION") super.onBackPressed() } diff --git a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingActivity.kt b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingActivity.kt index 060472a2da..e79250d39d 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/OnboardingActivity.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/OnboardingActivity.kt @@ -48,7 +48,10 @@ class OnboardingActivity : VectorBaseActivity(), UnlockedA } override fun onBackPressed() { - validateBackPressed { super.onBackPressed() } + validateBackPressed { + @Suppress("DEPRECATION") + super.onBackPressed() + } } override fun initUiAndData() { diff --git a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/AbstractFtueAuthFragment.kt b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/AbstractFtueAuthFragment.kt index f3cb326221..9fd0bd08ed 100644 --- a/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/AbstractFtueAuthFragment.kt +++ b/vector/src/main/java/im/vector/app/features/onboarding/ftueauth/AbstractFtueAuthFragment.kt @@ -123,6 +123,7 @@ abstract class AbstractFtueAuthFragment : VectorBaseFragment displayCancelDialog = false + @Suppress("DEPRECATION") vectorBaseActivity.onBackPressed() } .setNegativeButton(R.string.no, null) @@ -137,6 +138,7 @@ abstract class AbstractFtueAuthFragment : VectorBaseFragment displayCancelDialog = false + @Suppress("DEPRECATION") vectorBaseActivity.onBackPressed() } .setNegativeButton(R.string.no, null) diff --git a/vector/src/main/java/im/vector/app/features/rageshake/BugReportActivity.kt b/vector/src/main/java/im/vector/app/features/rageshake/BugReportActivity.kt index b19a98b3ce..78d3347cbe 100755 --- a/vector/src/main/java/im/vector/app/features/rageshake/BugReportActivity.kt +++ b/vector/src/main/java/im/vector/app/features/rageshake/BugReportActivity.kt @@ -267,6 +267,7 @@ class BugReportActivity : // Ensure there is no crash status remaining, which will be sent later on by mistake bugReporter.deleteCrashFile() + @Suppress("DEPRECATION") super.onBackPressed() } diff --git a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomFragment.kt b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomFragment.kt index f4c3e515c5..59657aae35 100644 --- a/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomdirectory/createroom/CreateRoomFragment.kt @@ -100,7 +100,10 @@ class CreateRoomFragment : .allowBack(useCross = true) viewModel.observeViewEvents { when (it) { - CreateRoomViewEvents.Quit -> vectorBaseActivity.onBackPressed() + CreateRoomViewEvents.Quit -> { + @Suppress("DEPRECATION") + vectorBaseActivity.onBackPressed() + } is CreateRoomViewEvents.Failure -> showFailure(it.throwable) } } diff --git a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsFragment.kt b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsFragment.kt index ba50890db3..26da1a45d2 100644 --- a/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/roomprofile/settings/RoomSettingsFragment.kt @@ -106,6 +106,7 @@ class RoomSettingsFragment : RoomSettingsViewEvents.Success -> showSuccess() RoomSettingsViewEvents.GoBack -> { ignoreChanges = true + @Suppress("DEPRECATION") vectorBaseActivity.onBackPressed() } } diff --git a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceSettingsFragment.kt b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceSettingsFragment.kt index ac3e5e4d05..98c81b19bc 100644 --- a/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceSettingsFragment.kt +++ b/vector/src/main/java/im/vector/app/features/spaces/manage/SpaceSettingsFragment.kt @@ -107,6 +107,7 @@ class SpaceSettingsFragment : RoomSettingsViewEvents.Success -> showSuccess() RoomSettingsViewEvents.GoBack -> { ignoreChanges = true + @Suppress("DEPRECATION") vectorBaseActivity.onBackPressed() } } diff --git a/vector/src/main/java/im/vector/app/features/usercode/UserCodeActivity.kt b/vector/src/main/java/im/vector/app/features/usercode/UserCodeActivity.kt index cf7d9c6ddb..4fd8305f29 100644 --- a/vector/src/main/java/im/vector/app/features/usercode/UserCodeActivity.kt +++ b/vector/src/main/java/im/vector/app/features/usercode/UserCodeActivity.kt @@ -151,7 +151,10 @@ class UserCodeActivity : VectorBaseActivity(), override fun onBackPressed() = withState(sharedViewModel) { when (it.mode) { - UserCodeState.Mode.SHOW -> super.onBackPressed() + UserCodeState.Mode.SHOW -> { + @Suppress("DEPRECATION") + super.onBackPressed() + } is UserCodeState.Mode.RESULT, UserCodeState.Mode.SCAN -> sharedViewModel.handle(UserCodeActions.SwitchMode(UserCodeState.Mode.SHOW)) } diff --git a/vector/src/main/java/im/vector/app/features/webview/VectorWebViewActivity.kt b/vector/src/main/java/im/vector/app/features/webview/VectorWebViewActivity.kt index e21bef193f..c97f87972e 100644 --- a/vector/src/main/java/im/vector/app/features/webview/VectorWebViewActivity.kt +++ b/vector/src/main/java/im/vector/app/features/webview/VectorWebViewActivity.kt @@ -101,6 +101,7 @@ class VectorWebViewActivity : VectorBaseActivity() if (views.simpleWebview.canGoBack()) { views.simpleWebview.goBack() } else { + @Suppress("DEPRECATION") super.onBackPressed() } } From 15616ecc7cc39b2e447b99ee48d872b3371c4c30 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 5 Oct 2022 11:35:46 +0200 Subject: [PATCH 09/80] Fix compilation issue after rebase --- .../android/sdk/internal/network/ComputeUserAgentUseCase.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCase.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCase.kt index 6611bd7865..04e8cf8a29 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCase.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/network/ComputeUserAgentUseCase.kt @@ -20,6 +20,7 @@ import android.content.Context import android.os.Build import org.matrix.android.sdk.BuildConfig import org.matrix.android.sdk.api.extensions.tryOrNull +import org.matrix.android.sdk.api.util.getApplicationInfoCompat import org.matrix.android.sdk.api.util.getPackageInfoCompat import javax.inject.Inject @@ -37,7 +38,7 @@ class ComputeUserAgentUseCase @Inject constructor( val appPackageName = context.applicationContext.packageName val pm = context.packageManager - val appName = tryOrNull { pm.getApplicationLabel(pm.getApplicationInfo(appPackageName, 0)).toString() } + val appName = tryOrNull { pm.getApplicationLabel(pm.getApplicationInfoCompat(appPackageName, 0)).toString() } ?.takeIf { it.matches("\\A\\p{ASCII}*\\z".toRegex()) } From 70383130f56e66aa35f4cd23383472bc02c6a958 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 5 Oct 2022 11:37:43 +0200 Subject: [PATCH 10/80] Fix compilation warning: `'compileDebugJavaWithJavac' task (current target is 1.8) and 'compileDebugKotlin' task (current target is 11) jvm target compatibility should be set to the same Java version.` --- library/multipicker/build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/library/multipicker/build.gradle b/library/multipicker/build.gradle index 58edfcdd5c..09fc2a7b50 100644 --- a/library/multipicker/build.gradle +++ b/library/multipicker/build.gradle @@ -35,6 +35,11 @@ android { } } + compileOptions { + sourceCompatibility versions.sourceCompat + targetCompatibility versions.targetCompat + } + kotlinOptions { jvmTarget = "11" } From 84223a221cae0fd8ad108940eb7335940967db38 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 5 Oct 2022 11:38:47 +0200 Subject: [PATCH 11/80] Call super method. --- .../main/java/com/android/dialer/dialpadview/DialpadView.java | 1 + 1 file changed, 1 insertion(+) diff --git a/library/external/dialpad/src/main/java/com/android/dialer/dialpadview/DialpadView.java b/library/external/dialpad/src/main/java/com/android/dialer/dialpadview/DialpadView.java index 5c6ce46257..dbb53cbdca 100644 --- a/library/external/dialpad/src/main/java/com/android/dialer/dialpadview/DialpadView.java +++ b/library/external/dialpad/src/main/java/com/android/dialer/dialpadview/DialpadView.java @@ -103,6 +103,7 @@ public class DialpadView extends LinearLayout { @Override protected void onFinishInflate() { + super.onFinishInflate(); setupKeypad(); mDigits = (EditText) findViewById(R.id.digits); mDelete = (ImageButton) findViewById(R.id.deleteButton); From 05a1f17e8300ed0650057df7bc882a66219da294 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 5 Oct 2022 14:03:27 +0200 Subject: [PATCH 12/80] Remove unused import --- .../VectorSettingsNotificationPreferenceFragment.kt | 1 - 1 file changed, 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt index ad12ca1be0..b1e32c05d1 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/VectorSettingsNotificationPreferenceFragment.kt @@ -22,7 +22,6 @@ import android.content.Intent import android.media.RingtoneManager import android.net.Uri import android.os.Bundle -import android.os.Parcelable import android.widget.Toast import androidx.lifecycle.LiveData import androidx.lifecycle.distinctUntilChanged From 3952f732dd94594660021809376e9db8a521ffef Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Wed, 5 Oct 2022 14:23:31 +0200 Subject: [PATCH 13/80] Paparazzi have some trouble with Android 13, try to workaround it. OK locally, but on the CI? --- .../app/screenshot/PaparazziExampleScreenshotTest.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/vector/src/test/java/im/vector/app/screenshot/PaparazziExampleScreenshotTest.kt b/vector/src/test/java/im/vector/app/screenshot/PaparazziExampleScreenshotTest.kt index fb8bed0034..65f89dcc6a 100644 --- a/vector/src/test/java/im/vector/app/screenshot/PaparazziExampleScreenshotTest.kt +++ b/vector/src/test/java/im/vector/app/screenshot/PaparazziExampleScreenshotTest.kt @@ -16,11 +16,14 @@ package im.vector.app.screenshot +import android.os.Build import android.widget.ImageView import android.widget.TextView import androidx.constraintlayout.widget.ConstraintLayout import app.cash.paparazzi.DeviceConfig.Companion.PIXEL_3 import app.cash.paparazzi.Paparazzi +import app.cash.paparazzi.androidHome +import app.cash.paparazzi.detectEnvironment import im.vector.app.R import org.junit.Rule import org.junit.Test @@ -29,6 +32,11 @@ class PaparazziExampleScreenshotTest { @get:Rule val paparazzi = Paparazzi( + // Apply trick from https://github.com/cashapp/paparazzi/issues/489#issuecomment-1195674603 + environment = detectEnvironment().copy( + platformDir = "${androidHome()}/platforms/android-32", + compileSdkVersion = Build.VERSION_CODES.S_V2 /* 32 */ + ), deviceConfig = PIXEL_3, theme = "Theme.Vector.Light", maxPercentDifference = 0.0, From 4bb60e162841113fa95b0c4e48f2e7afa934e9b0 Mon Sep 17 00:00:00 2001 From: ByeongsuPark Date: Thu, 6 Oct 2022 23:43:40 +0900 Subject: [PATCH 14/80] Fix wrong mic button direction to cancel on RTL languages --- .../home/room/detail/composer/voice/DraggableStateProcessor.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/voice/DraggableStateProcessor.kt b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/voice/DraggableStateProcessor.kt index 1355c89006..1ff937add5 100644 --- a/vector/src/main/java/im/vector/app/features/home/room/detail/composer/voice/DraggableStateProcessor.kt +++ b/vector/src/main/java/im/vector/app/features/home/room/detail/composer/voice/DraggableStateProcessor.kt @@ -21,6 +21,7 @@ import android.view.MotionEvent import im.vector.app.R import im.vector.app.core.utils.DimensionConverter import im.vector.app.features.home.room.detail.composer.voice.VoiceMessageRecorderView.DraggingState +import kotlin.math.absoluteValue class DraggableStateProcessor( resources: Resources, @@ -46,7 +47,7 @@ class DraggableStateProcessor( fun process(event: MotionEvent, draggingState: DraggingState): DraggingState { val currentX = event.rawX val currentY = event.rawY - val distanceX = firstX - currentX + val distanceX = (firstX - currentX).absoluteValue val distanceY = firstY - currentY return draggingState.nextDragState(currentX, currentY, distanceX, distanceY).also { lastDistanceX = distanceX From 652069d520869f655245c5cf1894b7de52410cfc Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Thu, 6 Oct 2022 18:00:33 +0200 Subject: [PATCH 15/80] Manage new Android 13 notification permission. --- .../src/main/res/values/strings.xml | 4 ++ tools/adb/notification.sh | 25 +++++++ .../features/debug/DebugPermissionActivity.kt | 19 ++++- .../res/layout/activity_debug_permission.xml | 24 +++---- .../troubleshoot/TestAutoStartBoot.kt | 6 +- .../TestBackgroundRestrictions.kt | 4 +- .../troubleshoot/TestBatteryOptimization.kt | 6 +- .../troubleshoot/TestFirebaseToken.kt | 6 +- .../settings/troubleshoot/TestPlayServices.kt | 4 +- .../troubleshoot/TestTokenRegistration.kt | 8 +-- vector/src/main/AndroidManifest.xml | 3 + .../vector/app/features/home/HomeActivity.kt | 11 +++ .../features/home/HomeActivityViewEvents.kt | 1 + .../features/home/HomeActivityViewModel.kt | 4 ++ .../home/NotificationPermissionManager.kt | 71 +++++++++++++++++++ ...rSettingsNotificationPreferenceFragment.kt | 21 ++++++ ...ttingsNotificationsTroubleshootFragment.kt | 17 ++++- .../NotificationTroubleshootTestManager.kt | 12 ++-- .../troubleshoot/TestAccountSettings.kt | 6 +- .../TestAvailableUnifiedPushDistributors.kt | 4 +- .../TestCurrentUnifiedPushDistributor.kt | 4 +- .../troubleshoot/TestDeviceSettings.kt | 6 +- .../TestEndpointAsTokenRegistration.kt | 8 +-- .../settings/troubleshoot/TestNotification.kt | 6 +- .../troubleshoot/TestPushFromPushGateway.kt | 4 +- .../troubleshoot/TestPushRulesSettings.kt | 4 +- .../troubleshoot/TestSystemSettings.kt | 30 +++++--- .../troubleshoot/TestUnifiedPushEndpoint.kt | 4 +- .../troubleshoot/TestUnifiedPushGateway.kt | 4 +- .../settings/troubleshoot/TroubleshootTest.kt | 7 +- 30 files changed, 241 insertions(+), 92 deletions(-) create mode 100755 tools/adb/notification.sh create mode 100644 vector/src/main/java/im/vector/app/features/home/NotificationPermissionManager.kt diff --git a/library/ui-strings/src/main/res/values/strings.xml b/library/ui-strings/src/main/res/values/strings.xml index 71ccf5b234..ef71c10dd5 100644 --- a/library/ui-strings/src/main/res/values/strings.xml +++ b/library/ui-strings/src/main/res/values/strings.xml @@ -635,6 +635,8 @@ ${app_name} needs permission to access your microphone to perform audio calls. ${app_name} needs permission to access your camera and your microphone to perform video calls.\n\nPlease allow access on the next pop-ups to be able to make the call. + + ${app_name} needs permission to display notifications. Notifications can display your messages, your invitations, etc.\n\nPlease allow access on the next pop-ups to be able to view notification. To scan a QR code, you need to allow camera access. Allow permission to access your contacts. @@ -854,7 +856,9 @@ System Settings. Notifications are enabled in the system settings. Notifications are disabled in the system settings.\nPlease check system settings. + ${app_name} needs the permission to show notifications.\nPlease grant the permission. Open Settings + Grant Permission Account Settings. Notifications are enabled for your account. diff --git a/tools/adb/notification.sh b/tools/adb/notification.sh new file mode 100755 index 0000000000..3c3c76c787 --- /dev/null +++ b/tools/adb/notification.sh @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +## From https://developer.android.com/develop/ui/views/notifications/notification-permission#test + +PACKAGE_NAME=im.vector.app.debug + +# App is newly installed on a device that runs Android 13 or higher: + +adb shell pm revoke ${PACKAGE_NAME} android.permission.POST_NOTIFICATIONS +adb shell pm clear-permission-flags ${PACKAGE_NAME} android.permission.POST_NOTIFICATIONS user-set +adb shell pm clear-permission-flags ${PACKAGE_NAME} android.permission.POST_NOTIFICATIONS user-fixed + +# The user keeps notifications enabled when the app is installed on a device that runs 12L or lower, +# then the device upgrades to Android 13 or higher: + +# adb shell pm grant ${PACKAGE_NAME} android.permission.POST_NOTIFICATIONS +# adb shell pm set-permission-flags ${PACKAGE_NAME} android.permission.POST_NOTIFICATIONS user-set +# adb shell pm clear-permission-flags ${PACKAGE_NAME} android.permission.POST_NOTIFICATIONS user-fixed + +# The user manually disables notifications when the app is installed on a device that runs 12L or lower, +# then the device upgrades to Android 13 or higher: + +# adb shell pm revoke ${PACKAGE_NAME} android.permission.POST_NOTIFICATIONS +# adb shell pm set-permission-flags ${PACKAGE_NAME} android.permission.POST_NOTIFICATIONS user-set +# adb shell pm clear-permission-flags ${PACKAGE_NAME} android.permission.POST_NOTIFICATIONS user-fixed diff --git a/vector-app/src/debug/java/im/vector/app/features/debug/DebugPermissionActivity.kt b/vector-app/src/debug/java/im/vector/app/features/debug/DebugPermissionActivity.kt index a9be5512e4..2b1b66e672 100644 --- a/vector-app/src/debug/java/im/vector/app/features/debug/DebugPermissionActivity.kt +++ b/vector-app/src/debug/java/im/vector/app/features/debug/DebugPermissionActivity.kt @@ -22,6 +22,7 @@ import android.os.Build import android.widget.Toast import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat +import androidx.core.view.isVisible import dagger.hilt.android.AndroidEntryPoint import im.vector.app.core.platform.VectorBaseActivity import im.vector.app.core.utils.checkPermissions @@ -46,7 +47,15 @@ class DebugPermissionActivity : VectorBaseActivity { + return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + listOf(Manifest.permission.POST_NOTIFICATIONS) + } else { + emptyList() + } + } private var lastPermissions = emptyList() @@ -77,6 +86,14 @@ class DebugPermissionActivity : VectorBaseActivity= Build.VERSION_CODES.TIRAMISU) { + views.notification.setOnClickListener { + lastPermissions = listOf(Manifest.permission.POST_NOTIFICATIONS) + checkPerm() + } + } else { + views.notification.isVisible = false + } } private fun checkPerm() { diff --git a/vector-app/src/debug/res/layout/activity_debug_permission.xml b/vector-app/src/debug/res/layout/activity_debug_permission.xml index 6340d8faa7..0f1fef0b9b 100644 --- a/vector-app/src/debug/res/layout/activity_debug_permission.xml +++ b/vector-app/src/debug/res/layout/activity_debug_permission.xml @@ -30,43 +30,43 @@ android:id="@+id/camera" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="CAMERA" - android:textAllCaps="false" /> + android:text="CAMERA" />