Skip to content

Instantly share code, notes, and snippets.

View radoyankov's full-sized avatar

Rado radoyankov

  • Sofia, Bulgaria
View GitHub Profile
@radoyankov
radoyankov / Locally.kt
Last active January 11, 2020 10:29
Shared Preferences implementation in Android on Kotlin
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)
@radoyankov
radoyankov / Do.kt
Last active January 11, 2020 10:29
Delayed Handler implementation on Kotlin
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 / Example.kt
Last active January 27, 2023 08:59
Easy Spannable on Kotlin
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