Add a Parcelable helper to handle deprecation

This commit is contained in:
Abandoned Cart 2023-04-21 09:06:49 -04:00 committed by Billy Laws
parent 96c5b94429
commit 97694e639a
2 changed files with 30 additions and 1 deletions

View File

@ -14,13 +14,14 @@ import android.view.ViewGroup
import androidx.core.widget.doOnTextChanged import androidx.core.widget.doOnTextChanged
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import emu.skyline.databinding.KeyboardDialogBinding import emu.skyline.databinding.KeyboardDialogBinding
import emu.skyline.utils.parcelable
import emu.skyline.utils.stringFromChars import emu.skyline.utils.stringFromChars
import java.util.concurrent.FutureTask import java.util.concurrent.FutureTask
data class SoftwareKeyboardResult(val cancelled : Boolean, val text : String) data class SoftwareKeyboardResult(val cancelled : Boolean, val text : String)
class SoftwareKeyboardDialog : DialogFragment() { class SoftwareKeyboardDialog : DialogFragment() {
private val config by lazy { requireArguments().getParcelable<SoftwareKeyboardConfig>("config")!! } private val config by lazy { requireArguments().parcelable<SoftwareKeyboardConfig>("config")!! }
private val initialText by lazy { requireArguments().getString("initialText")!! } private val initialText by lazy { requireArguments().getString("initialText")!! }
private var stopped = false private var stopped = false

View File

@ -0,0 +1,28 @@
/*
* SPDX-License-Identifier: MPL-2.0
* Copyright © 2023 Skyline Team and Contributors (https://github.com/skyline-emu/)
*/
package emu.skyline.utils
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.os.Parcelable
inline fun <reified T : Parcelable> Bundle.parcelable(key: String): T? = when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getParcelable(key, T::class.java)
else -> @Suppress("DEPRECATION") getParcelable(key) as? T
}
@Suppress("unused")
inline fun <reified T : Parcelable> Intent.parcelable(key: String): T? = when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getParcelableExtra(key, T::class.java)
else -> @Suppress("DEPRECATION") getParcelableExtra(key) as? T
}
@Suppress("unused")
inline fun <reified T : Parcelable> Intent.parcelableArrayList(key: String): ArrayList<T>? = when {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU -> getParcelableArrayListExtra(key, T::class.java)
else -> @Suppress("DEPRECATION") getParcelableArrayListExtra(key)
}