Skip to content

Instantly share code, notes, and snippets.

Avatar

Rado radoyankov

View GitHub Profile
@radoyankov
radoyankov / Example.kt
Last active Apr 4, 2021
Easy Spannable on Kotlin
View Example.kt
val spanned = spannable{ bold("some") + italic(" formatted") + color(Color.RED, " text") }
val nested = spannable{ bold(italic("nested ")) + url("www.google.com", "text") }
val noWrapping = bold("no ") + sub("wrapping ) + sup("also ") + "works"
text_view.text = spanned + nested + noWrapping
@radoyankov
radoyankov / Do.kt
Last active Jan 11, 2020
Delayed Handler implementation on Kotlin
View Do.kt
class Do {
enum class duration {
SECONDS, MILLISECONDS
}
infix fun seconds(function: () -> Unit) {
Do.mFormat = duration.SECONDS
Do.handle(function)
}
infix fun milliseconds(function: () -> Unit) {
Do.mFormat = duration.MILLISECONDS
@radoyankov
radoyankov / Locally.kt
Last active Jan 11, 2020
Shared Preferences implementation in Android on Kotlin
View Locally.kt
class Locally(val variable: Any) {
infix fun into(location: Any) {
val sharedPref = Locally.context?.getSharedPreferences("locallyPrefs", Context.MODE_PRIVATE)
val editor = sharedPref?.edit()
editor?.let {
when (this.variable) {
is Boolean -> it.putBoolean(location as String, this.variable)
is Float -> it.putFloat(location as String, this.variable)
is Double -> it.putFloat(location as String, this.variable.toFloat())
is Long -> it.putLong(location as String, this.variable)