Created
January 7, 2017 13:35
-
-
Save bulwinkel/60f2d06314c0d43225204c00251f1f48 to your computer and use it in GitHub Desktop.
Partial implementation of converting a `Map<String, V>` to a Bundle.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.bulwinkel.android | |
import android.os.Bundle | |
import android.os.IBinder | |
import android.os.Parcelable | |
import java.io.Serializable | |
fun <V> Map<String, V>.toBundle(bundle: Bundle = Bundle()): Bundle = bundle.apply { | |
forEach { | |
val k = it.key | |
val v = it.value | |
when (v) { | |
is IBinder -> putBinder(k, v) | |
is Bundle -> putBundle(k, v) | |
is Byte -> putByte(k, v) | |
is ByteArray -> putByteArray(k, v) | |
is Char -> putChar(k, v) | |
is CharArray -> putCharArray(k, v) | |
is CharSequence -> putCharSequence(k, v) | |
is Float -> putFloat(k, v) | |
is FloatArray -> putFloatArray(k, v) | |
is Parcelable -> putParcelable(k, v) | |
is Serializable -> putSerializable(k, v) | |
is Short -> putShort(k, v) | |
is ShortArray -> putShortArray(k, v) | |
// is Size -> putSize(k, v) //api 21 | |
// is SizeF -> putSizeF(k, v) //api 21 | |
else -> throw IllegalArgumentException("$v is of a type that is not currently supported") | |
// is Array<*> -> TODO() | |
// is List<*> -> TODO() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where is java variant of it?