Skip to content

Commit c1f21ed

Browse files
committed
Implement argument extension for initializing parcelable argument lazily
1 parent 494d3e1 commit c1f21ed

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

app/src/main/java/com/skydoves/pokedex/extensions/ActivityExtensions.kt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,17 @@
1616

1717
package com.skydoves.pokedex.extensions
1818

19-
import androidx.appcompat.app.AppCompatActivity
19+
import android.os.Parcelable
20+
import androidx.activity.ComponentActivity
21+
import com.skydoves.transformationlayout.TransformationLayout
2022
import com.skydoves.transformationlayout.onTransformationEndContainer
2123

22-
fun AppCompatActivity.onTransformationEndContainerApplyParams() {
24+
/** apply [TransformationLayout.Params] to an activity. */
25+
fun ComponentActivity.onTransformationEndContainerApplyParams() {
2326
onTransformationEndContainer(intent.getParcelableExtra("com.skydoves.transformationlayout"))
2427
}
28+
29+
/** initialize a parcelable argument lazily. */
30+
fun <T : Parcelable> ComponentActivity.argument(key: String): Lazy<T> {
31+
return lazy { requireNotNull(intent.getParcelableExtra<T>(key)) }
32+
}

0 commit comments

Comments
 (0)