From 401e8db1e6d34f3fcb3b1b96d225f7aa6c17d292 Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Sat, 6 Jan 2018 17:12:06 -0500 Subject: Do not require reified generics for deprecated method --- .../kotlin/ca/allanwang/kau/utils/ActivityUtils.kt | 17 ++++++++--------- .../kotlin/ca/allanwang/kau/utils/ContextUtils.kt | 20 +++++++++----------- 2 files changed, 17 insertions(+), 20 deletions(-) (limited to 'core/src/main/kotlin') 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 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(requestCode, bundleBuilder, intentBuilder)"), DeprecationLevel.WARNING) -inline fun Activity.startActivityForResult( +inline fun Activity.startActivityForResult( clazz: Class, requestCode: Int, bundleBuilder: Bundle.() -> Unit = {}, intentBuilder: Intent.() -> Unit = {}) { - startActivityForResult(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 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(clearStack, bundleBuilder, intentBuilder)"), DeprecationLevel.WARNING) -inline fun Context.startActivity( +inline fun Context.startActivity( clazz: Class, clearStack: Boolean = false, bundleBuilder: Bundle.() -> Unit = {}, intentBuilder: Intent.() -> Unit = {}) { - startActivity(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() } -- cgit v1.2.3