mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-12-25 23:05:29 +03:00
Add a Parcelable helper to handle deprecation
This commit is contained in:
parent
96c5b94429
commit
97694e639a
@ -14,13 +14,14 @@ import android.view.ViewGroup
|
||||
import androidx.core.widget.doOnTextChanged
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import emu.skyline.databinding.KeyboardDialogBinding
|
||||
import emu.skyline.utils.parcelable
|
||||
import emu.skyline.utils.stringFromChars
|
||||
import java.util.concurrent.FutureTask
|
||||
|
||||
data class SoftwareKeyboardResult(val cancelled : Boolean, val text : String)
|
||||
|
||||
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 var stopped = false
|
||||
|
||||
|
28
app/src/main/java/emu/skyline/utils/ParcelableHelper.kt
Normal file
28
app/src/main/java/emu/skyline/utils/ParcelableHelper.kt
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user