@@ -25,14 +25,14 @@ import timber.log.Timber
25
25
/* *
26
26
* Lazy intent parameters for saved state handle
27
27
*
28
- * @param key lookup key for the embedded item in the [SavedStateHandle.get]
29
28
* @param default default value to use when key does not exist
29
+ * @param key lookup key for the embedded item in the [SavedStateHandle.get]
30
30
*
31
31
* @return [Lazy] of the target type
32
32
*/
33
33
inline fun <reified T > SavedStateHandle.extra (
34
- key : String ,
35
34
default : T ,
35
+ key : String = T : :class.java.simpleName,
36
36
): Lazy <T > =
37
37
lazy(PUBLICATION ) {
38
38
try {
@@ -53,30 +53,21 @@ inline fun <reified T> SavedStateHandle.extra(
53
53
*
54
54
* @return [Lazy] of the target type
55
55
*/
56
- inline fun <reified T > SavedStateHandle.extra (key : String ): Lazy <T ?> =
57
- lazy(PUBLICATION ) {
58
- try {
59
- if (contains(key)) {
60
- get(key) as ? T
61
- } else {
62
- null
63
- }
64
- } catch (e: Exception ) {
65
- error(e)
66
- }
67
- }
56
+ inline fun <reified T > SavedStateHandle.extra (
57
+ key : String = T : :class.java.simpleName
58
+ ): Lazy <T ?> = extra(key = key, default = null )
68
59
69
60
/* *
70
61
* Lazy intent parameters for fragment activities
71
62
*
72
- * @param key lookup key for the embedded item in the [FragmentActivity.getIntent]
73
63
* @param default default value to use when key does not exist
64
+ * @param key lookup key for the embedded item in the [FragmentActivity.getIntent]
74
65
*
75
66
* @return [Lazy] of the target type
76
67
*/
77
68
inline fun <reified T > FragmentActivity.extra (
78
- key : String ,
79
69
default : T ,
70
+ key : String = T : :class.java.simpleName,
80
71
): Lazy <T > =
81
72
lazy(PUBLICATION ) {
82
73
try {
@@ -103,36 +94,21 @@ inline fun <reified T> FragmentActivity.extra(
103
94
*
104
95
* @return [Lazy] of the target type
105
96
*/
106
- inline fun <reified T > FragmentActivity.extra (key : String ): Lazy <T ?> =
107
- lazy(PUBLICATION ) {
108
- try {
109
- if (intent?.extras?.containsKey(key) == true ) {
110
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
111
- intent?.extras?.getParcelable(key, T ::class .java) as T
112
- } else {
113
- @Suppress(" DEPRECATION" )
114
- intent?.extras?.get(key) as T
115
- }
116
- } else {
117
- Timber .w(" $this does not have an argument with key: $key " )
118
- null
119
- }
120
- } catch (e: Exception ) {
121
- error(e)
122
- }
123
- }
97
+ inline fun <reified T > FragmentActivity.extra (
98
+ key : String = T : :class.java.simpleName
99
+ ): Lazy <T ?> = extra(key = key, default = null )
124
100
125
101
/* *
126
102
* Lazy intent parameters for fragments
127
103
*
128
- * @param key lookup key for the embedded item in the [Fragment.getArguments]
129
104
* @param default default value to use when key does not exist
105
+ * @param key lookup key for the embedded item in the [Fragment.getArguments]
130
106
*
131
107
* @return [Lazy] of the target type
132
108
*/
133
109
inline fun <reified T > Fragment.argument (
134
- key : String ,
135
110
default : T ,
111
+ key : String = T : :class.java.simpleName,
136
112
): Lazy <T > =
137
113
lazy(PUBLICATION ) {
138
114
try {
@@ -159,21 +135,6 @@ inline fun <reified T> Fragment.argument(
159
135
*
160
136
* @return [Lazy] of the target type
161
137
*/
162
- inline fun <reified T > Fragment.argument (key : String ): Lazy <T ?> =
163
- lazy(PUBLICATION ) {
164
- try {
165
- if (arguments?.containsKey(key) == true ) {
166
- if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
167
- arguments?.getParcelable(key, T ::class .java) as T
168
- } else {
169
- @Suppress(" DEPRECATION" )
170
- arguments?.get(key) as T
171
- }
172
- } else {
173
- Timber .w(" $this does not have an argument with key: $key " )
174
- null
175
- }
176
- } catch (e: Exception ) {
177
- error(e)
178
- }
179
- }
138
+ inline fun <reified T > Fragment.argument (
139
+ key : String = T : :class.java.simpleName
140
+ ): Lazy <T ?> = argument(key = key, default = null )
0 commit comments