Improve serializable extra extension
This commit is contained in:
committed by
Koitharu
parent
522dfc2418
commit
c4355f16e8
@@ -24,11 +24,15 @@ inline fun <reified T : Parcelable> Intent.getParcelableExtraCompat(key: String)
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified T : Serializable> Intent.getSerializableExtraCompat(key: String): T? {
|
inline fun <reified T : Serializable> Intent.getSerializableExtraCompat(key: String): T? {
|
||||||
return getSerializableExtra(key) as T?
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
||||||
|
getSerializableExtra(key, T::class.java)
|
||||||
|
} else {
|
||||||
|
getSerializableExtra(key) as T?
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <reified T : Serializable> Bundle.getSerializableCompat(key: String): T? {
|
inline fun <reified T : Serializable> Bundle.getSerializableCompat(key: String): T? {
|
||||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
|
||||||
getSerializable(key, T::class.java)
|
getSerializable(key, T::class.java)
|
||||||
} else {
|
} else {
|
||||||
getSerializable(key) as T?
|
getSerializable(key) as T?
|
||||||
|
|||||||
@@ -68,10 +68,7 @@ class FavouritesCategoryEditActivity :
|
|||||||
|
|
||||||
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||||
super.onRestoreInstanceState(savedInstanceState)
|
super.onRestoreInstanceState(savedInstanceState)
|
||||||
val order = savedInstanceState.getSerializableCompat<ListSortOrder>(KEY_SORT_ORDER)
|
selectedSortOrder = savedInstanceState.getSerializableCompat(KEY_SORT_ORDER)
|
||||||
if (order != null) {
|
|
||||||
selectedSortOrder = order
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onClick(v: View) {
|
override fun onClick(v: View) {
|
||||||
|
|||||||
@@ -157,7 +157,7 @@ class SettingsActivity :
|
|||||||
ACTION_SOURCES -> SourcesSettingsFragment()
|
ACTION_SOURCES -> SourcesSettingsFragment()
|
||||||
ACTION_MANAGE_DOWNLOADS -> DownloadsSettingsFragment()
|
ACTION_MANAGE_DOWNLOADS -> DownloadsSettingsFragment()
|
||||||
ACTION_SOURCE -> SourceSettingsFragment.newInstance(
|
ACTION_SOURCE -> SourceSettingsFragment.newInstance(
|
||||||
intent.getSerializableExtraCompat(EXTRA_SOURCE) as? MangaSource ?: MangaSource.LOCAL,
|
intent.getSerializableExtraCompat(EXTRA_SOURCE) ?: MangaSource.LOCAL,
|
||||||
)
|
)
|
||||||
|
|
||||||
ACTION_MANAGE_SOURCES -> SourcesManageFragment()
|
ACTION_MANAGE_SOURCES -> SourcesManageFragment()
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class SourceAuthActivity : BaseActivity<ActivityBrowserBinding>(), BrowserCallba
|
|||||||
if (!catchingWebViewUnavailability { setContentView(ActivityBrowserBinding.inflate(layoutInflater)) }) {
|
if (!catchingWebViewUnavailability { setContentView(ActivityBrowserBinding.inflate(layoutInflater)) }) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val source = intent?.getSerializableExtraCompat(EXTRA_SOURCE) as? MangaSource
|
val source = intent?.getSerializableExtraCompat<MangaSource>(EXTRA_SOURCE)
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
finishAfterTransition()
|
finishAfterTransition()
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user