aboutsummaryrefslogtreecommitdiff
path: root/library/src/main/kotlin/ca
diff options
context:
space:
mode:
Diffstat (limited to 'library/src/main/kotlin/ca')
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt5
-rw-r--r--library/src/main/kotlin/ca/allanwang/kau/utils/FragmentUtils.kt17
2 files changed, 6 insertions, 16 deletions
diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
index a856ed2..e2c1eb8 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/utils/ContextUtils.kt
@@ -6,6 +6,7 @@ import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.net.ConnectivityManager
+import android.os.Bundle
import android.os.Handler
import android.support.annotation.*
import android.support.v4.content.ContextCompat
@@ -30,11 +31,11 @@ fun Activity.restart(extras: ((Intent) -> Unit)? = null) {
overridePendingTransition(0, 0)
}
-fun Context.startActivity(clazz: Class<out Activity>, clearStack: Boolean = false, intentBuilder: Intent.() -> Unit = {}) {
+fun Context.startActivity(clazz: Class<out Activity>, clearStack: Boolean = false, intentBuilder: Intent.() -> Unit = {}, bundle: Bundle? = null) {
val intent = (Intent(this, clazz))
if (clearStack) intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP or Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_NEW_TASK)
intent.intentBuilder()
- startActivity(intent)
+ ContextCompat.startActivity(this, intent, bundle)
if (this is Activity && clearStack) finish()
}
diff --git a/library/src/main/kotlin/ca/allanwang/kau/utils/FragmentUtils.kt b/library/src/main/kotlin/ca/allanwang/kau/utils/FragmentUtils.kt
index 2ef1232..f97b4d3 100644
--- a/library/src/main/kotlin/ca/allanwang/kau/utils/FragmentUtils.kt
+++ b/library/src/main/kotlin/ca/allanwang/kau/utils/FragmentUtils.kt
@@ -6,19 +6,8 @@ import android.support.v4.app.Fragment
/**
* Created by Allan Wang on 2017-05-29.
*/
-
-private fun Fragment.bundle(): Bundle {
- if (this.arguments == null)
- this.arguments = Bundle()
- return this.arguments
-}
-
-fun <T : Fragment> T.putString(key: String, value: String): T {
- this.bundle().putString(key, value)
- return this
-}
-
-fun <T : Fragment> T.putInt(key: String, value: Int): T {
- this.bundle().putInt(key, value)
+fun <T : Fragment> T.withBundle(builder: Bundle.() -> Unit = {}): T {
+ if (this.arguments == null) this.arguments = Bundle()
+ this.arguments.builder()
return this
} \ No newline at end of file