1
1
package com.whyranoid.presentation.util
2
2
3
+ import android.content.Intent
4
+ import android.os.Build
5
+ import android.os.Bundle
6
+ import android.os.Parcelable
3
7
import androidx.lifecycle.Lifecycle
4
8
import androidx.lifecycle.LifecycleOwner
5
9
import androidx.lifecycle.lifecycleScope
6
10
import androidx.lifecycle.repeatOnLifecycle
7
11
import kotlinx.coroutines.launch
12
+ import java.io.Serializable
8
13
import java.text.SimpleDateFormat
9
- import java.util.Date
10
- import java.util.Locale
14
+ import java.util.*
11
15
12
16
fun LifecycleOwner.repeatWhenUiStarted (block : suspend () -> Unit ) {
13
17
lifecycleScope.launch {
@@ -21,3 +25,26 @@ fun Date.dateToString(format: String): String {
21
25
val formatter = SimpleDateFormat (format, Locale .getDefault())
22
26
return formatter.format(this )
23
27
}
28
+
29
+ inline fun <reified T : Serializable > Intent.getSerializableData (key : String ): T ? = when {
30
+ Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU -> getSerializableExtra(
31
+ key,
32
+ T ::class .java
33
+ )
34
+ else -> @Suppress(" DEPRECATION" ) getSerializableExtra(key) as ? T
35
+ }
36
+
37
+ inline fun <reified T : Serializable > Bundle.getSerializableData (key : String ): T ? = when {
38
+ Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU -> getSerializable(key, T ::class .java)
39
+ else -> @Suppress(" DEPRECATION" ) getSerializable(key) as ? T
40
+ }
41
+
42
+ inline fun <reified T : Parcelable > Intent.getParcelableData (key : String ): T ? = when {
43
+ Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU -> getParcelableExtra(key, T ::class .java)
44
+ else -> @Suppress(" DEPRECATION" ) getSerializableExtra(key) as ? T
45
+ }
46
+
47
+ inline fun <reified T : Parcelable > Bundle.getParcelableData (key : String ): T ? = when {
48
+ Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU -> getParcelable(key, T ::class .java)
49
+ else -> @Suppress(" DEPRECATION" ) getSerializable(key) as ? T
50
+ }
0 commit comments