From 85b7caa887cecce3464369344f1eb64acf8162a0 Mon Sep 17 00:00:00 2001 From: Konrad Pozniak Date: Sun, 11 Jun 2023 12:58:55 +0200 Subject: [PATCH] Replace deprecated getParcelable* methods with compat versions (#3633) --- app/lint-baseline.xml | 331 +++++++----------- .../keylesspalace/tusky/ViewMediaActivity.kt | 3 +- .../components/compose/ComposeActivity.kt | 10 +- .../compose/dialog/CaptionDialog.kt | 3 +- .../components/compose/dialog/FocusDialog.kt | 4 +- .../components/filters/EditFilterActivity.kt | 3 +- .../components/login/LoginWebViewActivity.kt | 7 +- .../tusky/fragment/ViewImageFragment.kt | 3 +- .../tusky/service/SendStatusService.kt | 3 +- 9 files changed, 148 insertions(+), 219 deletions(-) diff --git a/app/lint-baseline.xml b/app/lint-baseline.xml index a02d2c01c..e01146f54 100644 --- a/app/lint-baseline.xml +++ b/app/lint-baseline.xml @@ -1,39 +1,6 @@ - - - - - - - - - - - - - - - - @@ -1697,7 +1653,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2258,7 +2214,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2269,7 +2225,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -2973,7 +2929,7 @@ errorLine2=" ~~~~~~~~~~~~~"> @@ -3160,7 +3116,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~"> @@ -3171,7 +3127,7 @@ errorLine2=" ~~~~~~~~~"> @@ -3182,7 +3138,7 @@ errorLine2=" ~~~~~~~~~"> @@ -3270,7 +3226,7 @@ errorLine2=" ~~~~~~~~~"> @@ -3281,7 +3237,7 @@ errorLine2=" ~~~~~~~~~"> @@ -3292,7 +3248,7 @@ errorLine2=" ~~~~~~~~~"> @@ -3303,7 +3259,7 @@ errorLine2=" ~~~~~~~~~"> @@ -3666,7 +3622,7 @@ errorLine2=" ~~~~~~~"> @@ -3677,7 +3633,7 @@ errorLine2=" ~~~~~~~"> @@ -3688,7 +3644,7 @@ errorLine2=" ~~~~~~~~~~"> @@ -3699,7 +3655,7 @@ errorLine2=" ~~~~~~~~~~"> @@ -3710,7 +3666,7 @@ errorLine2=" ~~~~~~~~~~"> @@ -3719,17 +3675,6 @@ message="Access to `private` method `sendResult` of class `LoginWebViewActivity` requires synthetic accessor" errorLine1=" sendResult(LoginResult.Err(error))" errorLine2=" ~~~~~~~~~~"> - - - - + + + + @@ -4469,7 +4425,7 @@ errorLine2=" ~~~~~~~~~"> @@ -4480,7 +4436,7 @@ errorLine2=" ~~~~~~~"> @@ -4491,7 +4447,7 @@ errorLine2=" ~~~~~~~"> @@ -4579,7 +4535,7 @@ errorLine2=" ~~~~~~~"> @@ -4590,7 +4546,7 @@ errorLine2=" ~~~~~~~"> @@ -4601,7 +4557,7 @@ errorLine2=" ~~~~~~~"> @@ -4612,7 +4568,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"> @@ -4638,50 +4594,6 @@ column="29"/> - - - - - - - - - - - - - - - - @@ -4700,7 +4612,7 @@ errorLine2=" ~~~~~~~"> @@ -4711,7 +4623,7 @@ errorLine2=" ~~~~~~~"> @@ -4722,7 +4634,7 @@ errorLine2=" ~~~~~~~"> @@ -4733,7 +4645,7 @@ errorLine2=" ~~~~~~~"> @@ -4744,7 +4656,7 @@ errorLine2=" ~~~~~~~~~~~~"> @@ -4755,7 +4667,7 @@ errorLine2=" ~~~~~~~~~~~~"> @@ -4766,7 +4678,7 @@ errorLine2=" ~~~~~~~"> @@ -4777,7 +4689,7 @@ errorLine2=" ~~~~~~~"> @@ -5188,6 +5100,13 @@ column="55"/> + + + + @@ -6845,7 +6764,7 @@ errorLine2=" ~~~~~~~~~~~"> @@ -6856,7 +6775,7 @@ errorLine2=" ~~~~~~~~~~~~~~~~"> @@ -6867,7 +6786,7 @@ errorLine2=" ~~~~~~~~~~~"> @@ -6878,7 +6797,7 @@ errorLine2=" ~~~~~~~~"> @@ -6889,7 +6808,7 @@ errorLine2=" ~~~~"> @@ -6977,7 +6896,7 @@ errorLine2=" ~~~~~~~~"> @@ -6988,41 +6907,85 @@ errorLine2=" ~~~~~~~~~~~~~~~~~~~"> + errorLine1=" public static android.app.Notification make(final Context context, NotificationManager notificationManager, Notification body, AccountEntity account, boolean isFirstOfBatch) {" + errorLine2=" ~~~~~~~"> + line="151" + column="55"/> + errorLine1=" public static android.app.Notification make(final Context context, NotificationManager notificationManager, Notification body, AccountEntity account, boolean isFirstOfBatch) {" + errorLine2=" ~~~~~~~~~~~~~~~~~~~"> + line="151" + column="72"/> + errorLine1=" public static android.app.Notification make(final Context context, NotificationManager notificationManager, Notification body, AccountEntity account, boolean isFirstOfBatch) {" + errorLine2=" ~~~~~~~~~~~~"> + line="151" + column="113"/> + + + + + + + + + + + + + + + + @@ -7043,74 +7006,30 @@ errorLine2=" ~~~~~~~"> + errorLine1=" public static boolean filterNotification(NotificationManager notificationManager, AccountEntity account, @NonNull Notification notification) {" + errorLine2=" ~~~~~~~~~~~~~~~~~~~"> + errorLine1=" public static boolean filterNotification(NotificationManager notificationManager, AccountEntity account, @NonNull Notification notification) {" + errorLine2=" ~~~~~~~~~~~~~"> - - - - - - - - - - - - - - - - + line="620" + column="87"/> { - intent.getParcelableExtra(Intent.EXTRA_STREAM)?.let { uri -> + IntentCompat.getParcelableExtra(intent, Intent.EXTRA_STREAM, Uri::class.java)?.let { uri -> pickMedia(uri) } } Intent.ACTION_SEND_MULTIPLE -> { - intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM)?.forEach { uri -> + IntentCompat.getParcelableArrayListExtra(intent, Intent.EXTRA_STREAM, Uri::class.java)?.forEach { uri -> pickMedia(uri) } } diff --git a/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/CaptionDialog.kt b/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/CaptionDialog.kt index f6f8a495e..a1dc032cd 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/CaptionDialog.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/CaptionDialog.kt @@ -27,6 +27,7 @@ import android.view.ViewGroup import android.view.WindowManager import android.widget.EditText import androidx.appcompat.app.AlertDialog +import androidx.core.os.BundleCompat import androidx.core.os.bundleOf import androidx.fragment.app.DialogFragment import com.bumptech.glide.Glide @@ -73,7 +74,7 @@ class CaptionDialog : DialogFragment() { val window = dialog.window window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) - val previewUri = arguments?.getParcelable(PREVIEW_URI_ARG) ?: error("Preview Uri is null") + val previewUri = BundleCompat.getParcelable(requireArguments(), PREVIEW_URI_ARG, Uri::class.java) ?: error("Preview Uri is null") // Load the image and manually set it into the ImageView because it doesn't have a fixed size. Glide.with(this) .load(previewUri) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/FocusDialog.kt b/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/FocusDialog.kt index c159c41d6..93c99ee6f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/FocusDialog.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/compose/dialog/FocusDialog.kt @@ -15,13 +15,13 @@ package com.keylesspalace.tusky.components.compose.dialog -import android.app.Activity import android.content.DialogInterface import android.graphics.drawable.Drawable import android.net.Uri import android.view.WindowManager import android.widget.FrameLayout import androidx.appcompat.app.AlertDialog +import androidx.appcompat.app.AppCompatActivity import androidx.lifecycle.LifecycleOwner import androidx.lifecycle.lifecycleScope import com.bumptech.glide.Glide @@ -38,7 +38,7 @@ fun T.makeFocusDialog( existingFocus: Focus?, previewUri: Uri, onUpdateFocus: suspend (Focus) -> Unit -) where T : Activity, T : LifecycleOwner { +) where T : AppCompatActivity, T : LifecycleOwner { val focus = existingFocus ?: Focus(0.0f, 0.0f) // Default to center val dialogBinding = DialogFocusBinding.inflate(layoutInflater) diff --git a/app/src/main/java/com/keylesspalace/tusky/components/filters/EditFilterActivity.kt b/app/src/main/java/com/keylesspalace/tusky/components/filters/EditFilterActivity.kt index 3150d8d5d..664073949 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/filters/EditFilterActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/filters/EditFilterActivity.kt @@ -7,6 +7,7 @@ import android.widget.AdapterView import android.widget.ArrayAdapter import androidx.activity.viewModels import androidx.appcompat.app.AlertDialog +import androidx.core.content.IntentCompat import androidx.core.view.size import androidx.core.widget.doAfterTextChanged import androidx.lifecycle.lifecycleScope @@ -47,7 +48,7 @@ class EditFilterActivity : BaseActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - originalFilter = intent?.getParcelableExtra(FILTER_TO_EDIT) + originalFilter = IntentCompat.getParcelableExtra(intent, FILTER_TO_EDIT, Filter::class.java) filter = originalFilter ?: Filter("", "", listOf(), null, Filter.Action.WARN.action, listOf()) binding.apply { contextSwitches = mapOf( diff --git a/app/src/main/java/com/keylesspalace/tusky/components/login/LoginWebViewActivity.kt b/app/src/main/java/com/keylesspalace/tusky/components/login/LoginWebViewActivity.kt index 367eab5b8..be7e323ad 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/login/LoginWebViewActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/login/LoginWebViewActivity.kt @@ -33,6 +33,7 @@ import android.webkit.WebViewClient import androidx.activity.result.contract.ActivityResultContract import androidx.activity.viewModels import androidx.appcompat.app.AlertDialog +import androidx.core.content.IntentCompat import androidx.core.net.toUri import androidx.lifecycle.lifecycleScope import com.keylesspalace.tusky.BaseActivity @@ -61,7 +62,9 @@ class OauthLogin : ActivityResultContract() { return if (resultCode == Activity.RESULT_CANCELED) { LoginResult.Cancel } else { - intent!!.getParcelableExtra(RESULT_EXTRA)!! + intent?.let { + IntentCompat.getParcelableExtra(it, RESULT_EXTRA, LoginResult::class.java) + } ?: LoginResult.Err("failed parsing LoginWebViewActivity result") } } @@ -70,7 +73,7 @@ class OauthLogin : ActivityResultContract() { private const val DATA_EXTRA = "data" fun parseData(intent: Intent): LoginData { - return intent.getParcelableExtra(DATA_EXTRA)!! + return IntentCompat.getParcelableExtra(intent, DATA_EXTRA, LoginData::class.java)!! } fun makeResultIntent(result: LoginResult): Intent { diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/ViewImageFragment.kt b/app/src/main/java/com/keylesspalace/tusky/fragment/ViewImageFragment.kt index 688ce7c58..24c8feb03 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/ViewImageFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/ViewImageFragment.kt @@ -26,6 +26,7 @@ import android.view.MotionEvent import android.view.View import android.view.ViewGroup import android.widget.ImageView +import androidx.core.os.BundleCompat import com.bumptech.glide.Glide import com.bumptech.glide.load.DataSource import com.bumptech.glide.load.engine.GlideException @@ -92,7 +93,7 @@ class ViewImageFragment : ViewMediaFragment() { super.onViewCreated(view, savedInstanceState) val arguments = this.requireArguments() - val attachment = arguments.getParcelable(ARG_ATTACHMENT) + val attachment = BundleCompat.getParcelable(arguments, ARG_ATTACHMENT, Attachment::class.java) this.shouldStartTransition = arguments.getBoolean(ARG_START_POSTPONED_TRANSITION) val url: String? var description: String? = null diff --git a/app/src/main/java/com/keylesspalace/tusky/service/SendStatusService.kt b/app/src/main/java/com/keylesspalace/tusky/service/SendStatusService.kt index b34c3221e..cf03115b3 100644 --- a/app/src/main/java/com/keylesspalace/tusky/service/SendStatusService.kt +++ b/app/src/main/java/com/keylesspalace/tusky/service/SendStatusService.kt @@ -16,6 +16,7 @@ import android.util.Log import androidx.annotation.StringRes import androidx.core.app.NotificationCompat import androidx.core.app.ServiceCompat +import androidx.core.content.IntentCompat import at.connyduck.calladapter.networkresult.fold import com.keylesspalace.tusky.MainActivity import com.keylesspalace.tusky.R @@ -83,7 +84,7 @@ class SendStatusService : Service(), Injectable { override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { if (intent.hasExtra(KEY_STATUS)) { - val statusToSend: StatusToSend = intent.getParcelableExtra(KEY_STATUS) + val statusToSend: StatusToSend = IntentCompat.getParcelableExtra(intent, KEY_STATUS, StatusToSend::class.java) ?: throw IllegalStateException("SendStatusService started without $KEY_STATUS extra") if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {