Twidere-App-Android-Twitter.../twidere/src/main/kotlin/org/mariotaku/ktextension/BundleExtensions.kt

42 lines
1.0 KiB
Kotlin
Raw Normal View History

2016-08-30 14:23:59 +02:00
package org.mariotaku.ktextension
import android.os.Bundle
import android.os.Parcelable
inline fun Bundle(action: Bundle.() -> Unit): Bundle {
val bundle = Bundle()
action(bundle)
return bundle
}
operator fun Bundle.set(key: String, value: Boolean) {
return putBoolean(key, value)
}
operator fun Bundle.set(key: String, value: Int) {
return putInt(key, value)
}
operator fun Bundle.set(key: String, value: Long) {
return putLong(key, value)
}
2016-12-03 06:48:40 +01:00
operator fun Bundle.set(key: String, value: String?) {
2016-08-30 14:23:59 +02:00
return putString(key, value)
}
operator fun Bundle.set(key: String, value: Parcelable?) {
return putParcelable(key, value)
}
operator fun Bundle.set(key: String, value: Array<out Parcelable>?) {
return putParcelableArray(key, value)
2016-12-13 04:06:07 +01:00
}
operator fun Bundle.set(key: String, value: Array<String>?) {
return putStringArray(key, value)
2017-02-02 16:50:30 +01:00
}
fun <T> Bundle.getTypedArray(key: String, creator: Parcelable.Creator<T>): Array<T> {
return getParcelableArray(key).toTypedArray(creator)
2016-08-30 14:23:59 +02:00
}