aboutsummaryrefslogtreecommitdiff
path: root/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt')
-rw-r--r--core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt25
1 files changed, 23 insertions, 2 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 54aeaff..5631e70 100644
--- a/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt
+++ b/core/src/main/kotlin/ca/allanwang/kau/utils/ActivityUtils.kt
@@ -2,11 +2,11 @@ package ca.allanwang.kau.utils
import android.annotation.SuppressLint
import android.app.Activity
+import android.app.ActivityOptions
import android.content.Intent
import android.graphics.Color
-import android.os.Build
+import android.os.Bundle
import android.support.annotation.ColorInt
-import android.support.annotation.RequiresApi
import android.support.annotation.StringRes
import android.support.design.widget.Snackbar
import android.view.Menu
@@ -20,6 +20,27 @@ import org.jetbrains.anko.contentView
*/
/**
+ * Helper class to launch an activity for result
+ * Counterpart of [Activity.startActivityForResult]
+ * For starting activities without result, see [startActivity]
+ */
+@SuppressLint("NewApi")
+fun Activity.startActivityForResult(
+ clazz: Class<out Activity>,
+ requestCode: Int,
+ transition: Boolean = false,
+ bundle: Bundle? = null,
+ intentBuilder: Intent.() -> Unit = {}) {
+ val intent = Intent(this, clazz)
+ val fullBundle = if (transition && buildIsLollipopAndUp)
+ ActivityOptions.makeSceneTransitionAnimation(this).toBundle()
+ else Bundle()
+ if (bundle != null) fullBundle.putAll(bundle)
+ intent.intentBuilder()
+ startActivityForResult(intent, requestCode, if (fullBundle.isEmpty) null else fullBundle)
+}
+
+/**
* Restarts an activity from itself with a fade animation
* Keeps its existing extra bundles and has a builder to accept other parameters
*/