Created
August 17, 2018 12:23
-
-
Save Na0ki/68d4620f591fa8a626edb02f6eae13b6 to your computer and use it in GitHub Desktop.
This file contains 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
@Throws(ClassCastException::class, InvalidClassException::class) | |
inline fun <reified T : Any> get(id: Int): T { | |
return get(sApp.getString(id)) | |
} | |
@Throws(ClassCastException::class, InvalidClassException::class) | |
inline fun <reified T : Any> get(key: String): T { | |
return when (T::class) { | |
String::class -> sPrefs.getString(key, "") as T? ?: "" as T | |
Set::class -> sPrefs.getStringSet(key, emptySet()) as T? ?: emptySet<String>() as T | |
Int::class -> sPrefs.getInt(key, 0) as T | |
Long::class -> sPrefs.getLong(key, 0L) as T | |
Float::class -> sPrefs.getFloat(key, 0.toFloat()) as T | |
Boolean::class -> sPrefs.getBoolean(key, false) as T | |
else -> throw InvalidClassException("${T::class} is not supported") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment