Skip to content

Instantly share code, notes, and snippets.

View osrl's full-sized avatar

Osman Saral osrl

  • @bordobt
  • Trabzon, Turkey
View GitHub Profile
fun TextView.applySpanAnnotations() {
val annotations = (text as? SpannedString)
?.getSpans(0, text.length, Annotation::class.java) ?: return
text = SpannableString(text)
.apply {
loop@ for (annotation in annotations) {
when(annotation.key) {
"font" -> {
val fontName = annotation.value
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
PaymentConfiguration.init("my_key")
CustomerSession.initCustomerSession(MyEphemeralKeyProvider())
...
}
@osrl
osrl / Call.kt
Last active September 9, 2020 08:41
A Kotlin extension function to Retrofit Call class
inline fun <T> Call<T>.enqueue(crossinline onResult: Result<T>.() -> Unit) {
enqueue(object : Callback<T> {
override fun onFailure(call: Call<T>?, t: Throwable?) {
onResult(Result.Error(ApiError("Network error")))
}
override fun onResponse(call: Call<T>?, response: Response<T>) {
onResult(response.result())
}
})