diff options
Diffstat (limited to 'core/src')
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt | 17 | ||||
-rw-r--r-- | core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 20 |
2 files changed, 17 insertions, 20 deletions
diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt index 3484353..f8643db 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt @@ -31,23 +31,22 @@ annotation class KauActivity inline fun <reified T : Activity> Activity.startActivityForResult( requestCode: Int, bundleBuilder: Bundle.() -> Unit = {}, - intentBuilder: Intent.() -> Unit = {}) { - val intent = Intent(this, T::class.java) - intent.intentBuilder() - val bundle = Bundle() - bundle.bundleBuilder() - startActivityForResult(intent, requestCode, bundle) -} + intentBuilder: Intent.() -> Unit = {} +) = startActivityForResult(T::class.java, requestCode, bundleBuilder, intentBuilder) @Deprecated("Use reified generic instead of passing class", ReplaceWith("startActivityForResult<T>(requestCode, bundleBuilder, intentBuilder)"), DeprecationLevel.WARNING) -inline fun <reified T : Activity> Activity.startActivityForResult( +inline fun <T : Activity> Activity.startActivityForResult( clazz: Class<T>, requestCode: Int, bundleBuilder: Bundle.() -> Unit = {}, intentBuilder: Intent.() -> Unit = {}) { - startActivityForResult<T>(requestCode, bundleBuilder, intentBuilder) + val intent = Intent(this, clazz) + intent.intentBuilder() + val bundle = Bundle() + bundle.bundleBuilder() + startActivityForResult(intent, requestCode, bundle) } /** diff --git a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt index db54282..0e4b5f1 100644 --- a/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt +++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt @@ -35,25 +35,23 @@ inline fun <reified T : Activity> Context.startActivity( clearStack: Boolean = false, bundleBuilder: Bundle.() -> Unit = {}, intentBuilder: Intent.() -> Unit = {} -) { - val intent = Intent(this, T::class.java) - if (clearStack) intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK) - intent.intentBuilder() - val bundle = Bundle() - bundle.bundleBuilder() - startActivity(intent, bundle) - if (clearStack && this is Activity) finish() -} +) = startActivity(T::class.java, clearStack, bundleBuilder, intentBuilder) @Deprecated("Use reified generic instead of passing class", ReplaceWith("startActivity<T>(clearStack, bundleBuilder, intentBuilder)"), DeprecationLevel.WARNING) -inline fun <reified T : Activity> Context.startActivity( +inline fun <T : Activity> Context.startActivity( clazz: Class<T>, clearStack: Boolean = false, bundleBuilder: Bundle.() -> Unit = {}, intentBuilder: Intent.() -> Unit = {}) { - startActivity<T>(clearStack, bundleBuilder, intentBuilder) + val intent = Intent(this, clazz) + if (clearStack) intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK) + intent.intentBuilder() + val bundle = Bundle() + bundle.bundleBuilder() + startActivity(intent, bundle) + if (clearStack && this is Activity) finish() } |