aboutsummaryrefslogtreecommitdiff
path: root/library/src/main/kotlin/ca
diff options
context:
space:
mode:
authorAllan Wang <me@allanwang.ca>2017-06-12 16:24:29 -0700
committerAllan Wang <me@allanwang.ca>2017-06-12 16:24:29 -0700
commita429a5e0dbc96ae67bc68e27527239a43390e3f1 (patch)
treee16fe0790a7500d051df0319a7b613cdff400996 /library/src/main/kotlin/ca
parentdcdf008c1e83af4ba0509736a389522a71797264 (diff)
downloadkau-a429a5e0dbc96ae67bc68e27527239a43390e3f1.tar.gz
kau-a429a5e0dbc96ae67bc68e27527239a43390e3f1.tar.bz2
kau-a429a5e0dbc96ae67bc68e27527239a43390e3f1.zip
Add fragment bundler
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