diff --git a/app/src/main/java/com/keylesspalace/tusky/AccountListActivity.kt b/app/src/main/java/com/keylesspalace/tusky/AccountListActivity.kt index 723a35193..ca23f7912 100644 --- a/app/src/main/java/com/keylesspalace/tusky/AccountListActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/AccountListActivity.kt @@ -20,7 +20,6 @@ import android.content.Intent import android.os.Bundle import com.keylesspalace.tusky.databinding.ActivityAccountListBinding import com.keylesspalace.tusky.fragment.AccountListFragment -import com.keylesspalace.tusky.util.requireSerializableExtra import dagger.android.DispatchingAndroidInjector import dagger.android.HasAndroidInjector import javax.inject.Inject @@ -45,7 +44,7 @@ class AccountListActivity : BaseActivity(), HasAndroidInjector { val binding = ActivityAccountListBinding.inflate(layoutInflater) setContentView(binding.root) - val type: Type = intent.requireSerializableExtra(EXTRA_TYPE) + val type = intent.getSerializableExtra(EXTRA_TYPE) as Type val id: String? = intent.getStringExtra(EXTRA_ID) val accountLocked: Boolean = intent.getBooleanExtra(EXTRA_ACCOUNT_LOCKED, false) diff --git a/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt b/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt index 94bc288a8..2a96cb7fe 100644 --- a/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/ViewMediaActivity.kt @@ -54,7 +54,6 @@ import com.keylesspalace.tusky.fragment.ViewImageFragment import com.keylesspalace.tusky.pager.ImagePagerAdapter import com.keylesspalace.tusky.pager.SingleImagePagerAdapter import com.keylesspalace.tusky.util.getTemporaryMediaFilename -import com.keylesspalace.tusky.util.parcelableArrayListExtra import com.keylesspalace.tusky.util.viewBinding import com.keylesspalace.tusky.viewdata.AttachmentViewData import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers @@ -95,7 +94,7 @@ class ViewMediaActivity : BaseActivity(), ViewImageFragment.PhotoActionsListener supportPostponeEnterTransition() // Gather the parameters. - attachments = intent.parcelableArrayListExtra(EXTRA_ATTACHMENTS) + attachments = intent.getParcelableArrayListExtra(EXTRA_ATTACHMENTS) val initialPosition = intent.getIntExtra(EXTRA_ATTACHMENT_INDEX, 0) // Adapter is actually of existential type PageAdapter & SharedElementsTransitionListener diff --git a/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt b/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt index cb2c2130b..d8b1c204b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt +++ b/app/src/main/java/com/keylesspalace/tusky/components/compose/ComposeActivity.kt @@ -93,8 +93,6 @@ import com.keylesspalace.tusky.util.hide import com.keylesspalace.tusky.util.highlightSpans import com.keylesspalace.tusky.util.loadAvatar import com.keylesspalace.tusky.util.onTextChanged -import com.keylesspalace.tusky.util.parcelableArrayListExtra -import com.keylesspalace.tusky.util.parcelableExtra import com.keylesspalace.tusky.util.show import com.keylesspalace.tusky.util.viewBinding import com.keylesspalace.tusky.util.visible @@ -240,7 +238,7 @@ class ComposeActivity : /* If the composer is started up as a reply to another post, override the "starting" state * based on what the intent from the reply request passes. */ - val composeOptions: ComposeOptions? = intent.parcelableExtra(COMPOSE_OPTIONS_EXTRA) + val composeOptions: ComposeOptions? = intent.getParcelableExtra(COMPOSE_OPTIONS_EXTRA) viewModel.setup(composeOptions) @@ -301,12 +299,12 @@ class ComposeActivity : if (type.startsWith("image/") || type.startsWith("video/") || type.startsWith("audio/")) { when (intent.action) { Intent.ACTION_SEND -> { - intent.parcelableExtra(Intent.EXTRA_STREAM)?.let { uri -> + intent.getParcelableExtra(Intent.EXTRA_STREAM)?.let { uri -> pickMedia(uri) } } Intent.ACTION_SEND_MULTIPLE -> { - intent.parcelableArrayListExtra(Intent.EXTRA_STREAM)?.forEach { uri -> + intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM)?.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 54fb645d6..d5ece95f4 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 @@ -38,7 +38,6 @@ import com.bumptech.glide.request.target.CustomTarget import com.bumptech.glide.request.transition.Transition import com.github.chrisbanes.photoview.PhotoView import com.keylesspalace.tusky.R -import com.keylesspalace.tusky.util.parcelable // https://github.com/tootsuite/mastodon/blob/c6904c0d3766a2ea8a81ab025c127169ecb51373/app/models/media_attachment.rb#L32 private const val MEDIA_DESCRIPTION_CHARACTER_LIMIT = 1500 @@ -94,7 +93,7 @@ class CaptionDialog : DialogFragment() { val window = dialog.window window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) - val previewUri: Uri = arguments?.parcelable(PREVIEW_URI_ARG) ?: error("Preview Uri is null") + val previewUri = arguments?.getParcelable(PREVIEW_URI_ARG) ?: 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/login/LoginWebViewActivity.kt b/app/src/main/java/com/keylesspalace/tusky/components/login/LoginWebViewActivity.kt index a793a6b50..b69f81e76 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 @@ -42,7 +42,6 @@ import com.keylesspalace.tusky.databinding.ActivityLoginWebviewBinding import com.keylesspalace.tusky.di.Injectable import com.keylesspalace.tusky.di.ViewModelFactory import com.keylesspalace.tusky.util.hide -import com.keylesspalace.tusky.util.parcelableExtra import com.keylesspalace.tusky.util.viewBinding import com.keylesspalace.tusky.util.visible import kotlinx.coroutines.launch @@ -62,7 +61,7 @@ class OauthLogin : ActivityResultContract() { return if (resultCode == Activity.RESULT_CANCELED) { LoginResult.Cancel } else { - intent!!.parcelableExtra(RESULT_EXTRA)!! + intent!!.getParcelableExtra(RESULT_EXTRA)!! } } @@ -71,7 +70,7 @@ class OauthLogin : ActivityResultContract() { private const val DATA_EXTRA = "data" fun parseData(intent: Intent): LoginData { - return intent.parcelableExtra(DATA_EXTRA)!! + return intent.getParcelableExtra(DATA_EXTRA)!! } fun makeResultIntent(result: LoginResult): Intent { diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/AccountListFragment.kt b/app/src/main/java/com/keylesspalace/tusky/fragment/AccountListFragment.kt index 8cc855ce6..497239653 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/AccountListFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/AccountListFragment.kt @@ -49,7 +49,6 @@ import com.keylesspalace.tusky.network.MastodonApi import com.keylesspalace.tusky.settings.PrefKeys import com.keylesspalace.tusky.util.HttpHeaderLink import com.keylesspalace.tusky.util.hide -import com.keylesspalace.tusky.util.requireSerializable import com.keylesspalace.tusky.util.show import com.keylesspalace.tusky.util.viewBinding import com.keylesspalace.tusky.view.EndlessOnScrollListener @@ -79,7 +78,7 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) - type = requireArguments().requireSerializable(ARG_TYPE) + type = requireArguments().getSerializable(ARG_TYPE) as Type id = requireArguments().getString(ARG_ID) } 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 a70bc9a4c..28cf64ca3 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/ViewImageFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/ViewImageFragment.kt @@ -36,7 +36,6 @@ import com.keylesspalace.tusky.ViewMediaActivity import com.keylesspalace.tusky.databinding.FragmentViewImageBinding import com.keylesspalace.tusky.entity.Attachment import com.keylesspalace.tusky.util.hide -import com.keylesspalace.tusky.util.parcelable import com.keylesspalace.tusky.util.visible import io.reactivex.rxjava3.subjects.BehaviorSubject import kotlin.math.abs @@ -93,7 +92,7 @@ class ViewImageFragment : ViewMediaFragment() { super.onViewCreated(view, savedInstanceState) val arguments = this.requireArguments() - val attachment: Attachment? = arguments.parcelable(ARG_ATTACHMENT) + val attachment = arguments.getParcelable(ARG_ATTACHMENT) 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/fragment/ViewVideoFragment.kt b/app/src/main/java/com/keylesspalace/tusky/fragment/ViewVideoFragment.kt index 6ae334988..214741a8e 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/ViewVideoFragment.kt +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/ViewVideoFragment.kt @@ -31,7 +31,6 @@ import com.keylesspalace.tusky.ViewMediaActivity import com.keylesspalace.tusky.databinding.FragmentViewVideoBinding import com.keylesspalace.tusky.entity.Attachment import com.keylesspalace.tusky.util.hide -import com.keylesspalace.tusky.util.parcelable import com.keylesspalace.tusky.util.visible import com.keylesspalace.tusky.view.ExposedPlayPauseVideoView @@ -171,7 +170,7 @@ class ViewVideoFragment : ViewMediaFragment() { override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) - val attachment: Attachment? = requireArguments().parcelable(ARG_ATTACHMENT) + val attachment = arguments?.getParcelable(ARG_ATTACHMENT) if (attachment == null) { throw IllegalArgumentException("attachment has to be set") diff --git a/app/src/main/java/com/keylesspalace/tusky/receiver/SendStatusBroadcastReceiver.kt b/app/src/main/java/com/keylesspalace/tusky/receiver/SendStatusBroadcastReceiver.kt index 6ef027f2a..c1f5a2cca 100644 --- a/app/src/main/java/com/keylesspalace/tusky/receiver/SendStatusBroadcastReceiver.kt +++ b/app/src/main/java/com/keylesspalace/tusky/receiver/SendStatusBroadcastReceiver.kt @@ -29,7 +29,6 @@ import com.keylesspalace.tusky.entity.Status import com.keylesspalace.tusky.service.SendStatusService import com.keylesspalace.tusky.service.StatusToSend import com.keylesspalace.tusky.util.randomAlphanumericString -import com.keylesspalace.tusky.util.requireSerializableExtra import dagger.android.AndroidInjection import javax.inject.Inject @@ -49,7 +48,7 @@ class SendStatusBroadcastReceiver : BroadcastReceiver() { val senderIdentifier = intent.getStringExtra(NotificationHelper.KEY_SENDER_ACCOUNT_IDENTIFIER) val senderFullName = intent.getStringExtra(NotificationHelper.KEY_SENDER_ACCOUNT_FULL_NAME) val citedStatusId = intent.getStringExtra(NotificationHelper.KEY_CITED_STATUS_ID) - val visibility: Status.Visibility = intent.requireSerializableExtra(NotificationHelper.KEY_VISIBILITY)!! + val visibility = intent.getSerializableExtra(NotificationHelper.KEY_VISIBILITY) as Status.Visibility val spoiler = intent.getStringExtra(NotificationHelper.KEY_SPOILER) ?: "" val mentions = intent.getStringArrayExtra(NotificationHelper.KEY_MENTIONS) ?: emptyArray() 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 d47105525..3bcaf8778 100644 --- a/app/src/main/java/com/keylesspalace/tusky/service/SendStatusService.kt +++ b/app/src/main/java/com/keylesspalace/tusky/service/SendStatusService.kt @@ -31,7 +31,6 @@ import com.keylesspalace.tusky.entity.NewPoll import com.keylesspalace.tusky.entity.NewStatus import com.keylesspalace.tusky.entity.Status import com.keylesspalace.tusky.network.MastodonApi -import com.keylesspalace.tusky.util.parcelableExtra import dagger.android.AndroidInjection import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -73,7 +72,7 @@ class SendStatusService : Service(), Injectable { override fun onStartCommand(intent: Intent, flags: Int, startId: Int): Int { if (intent.hasExtra(KEY_STATUS)) { - val statusToSend: StatusToSend = intent.parcelableExtra(KEY_STATUS) + val statusToSend: StatusToSend = intent.getParcelableExtra(KEY_STATUS) ?: throw IllegalStateException("SendStatusService started without $KEY_STATUS extra") if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { diff --git a/app/src/main/java/com/keylesspalace/tusky/util/CompatExtensions.kt b/app/src/main/java/com/keylesspalace/tusky/util/CompatExtensions.kt deleted file mode 100644 index 55d2f44b4..000000000 --- a/app/src/main/java/com/keylesspalace/tusky/util/CompatExtensions.kt +++ /dev/null @@ -1,49 +0,0 @@ -@file:Suppress("DEPRECATION") - -package com.keylesspalace.tusky.util - -import android.content.Intent -import android.os.Build -import android.os.Bundle -import android.os.Parcelable -import java.io.Serializable - -inline fun Intent.requireSerializableExtra(name: String?): T { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - getSerializableExtra(name, T::class.java)!! - } else { - getSerializableExtra(name) as T - } -} - -inline fun Intent.parcelableArrayListExtra(name: String?): ArrayList? { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - getParcelableArrayListExtra(name, T::class.java) - } else { - getParcelableArrayListExtra(name) - } -} - -inline fun Bundle.parcelable(name: String?): T? { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - getParcelable(name, T::class.java) - } else { - getParcelable(name) - } -} - -inline fun Intent.parcelableExtra(name: String?): T? { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - getParcelableExtra(name, T::class.java) - } else { - getParcelableExtra(name) as T? - } -} - -inline fun Bundle.requireSerializable(name: String?): T { - return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - getSerializable(name, T::class.java)!! - } else { - getSerializable(name) as T - } -}