Skip to content

Instantly share code, notes, and snippets.

Osman Saral osrl

View GitHub Profile
View TextViewExtensions.kt
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
View LaunchActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
PaymentConfiguration.init("my_key")
CustomerSession.initCustomerSession(MyEphemeralKeyProvider())
...
}
@osrl
osrl / Call.kt
Last active Sep 26, 2019
A Kotlin extension function to Retrofit Call class
View Call.kt
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())
}
})
You can’t perform that action at this time.