Android utilities for easier and faster Kotlin programming.
Download
Gradle
compile 'com.costular:kotlin-utils:0.1'
How to use
It depends on utilities. Some of them just work as function extensions and you don't have to do anything special, just call a method like another one.
API
Activity
setFullScreen() showToolbar() // Support and native hideToolbar() // Support and native
Context
getClipboardManager() copyTextToClipboard(value: String) copyUriToClipboard(uri: Uri) getTextFromClipboard(): CharSequence getUriFromClipboard(): Uri? getPreferences(): SharedPreferences getPreferences(name: String, mode: Int): SharedPreferences
SharedPreferences
SharedPreferences.use(lambda)
It automatically applies after lambda execution
val sharedPrefs = context.getPreferences() sharedPrefs.edit {
putBoolean("first_use", false) // This refers to sharedPrefs instance
}
Versions
These methods are static.
doWithVersion(version: Int, lambda) // == doWithAtLeastVersion(version: Int, lambda) // >= doWithHigherVersion(version: Int, lambda) // > doWithLowerVersion(version: Int, lambda) // <
Example
doWithAtLeastVersion(21) {
// Do something on Lollipop version or higher
}