Skip to content

Instantly share code, notes, and snippets.

Avatar

Hakob Astvacatryan hakobast

  • Yerevan, Armenia
View GitHub Profile
@hakobast
hakobast / AndroidExtensions.kt
Created Oct 20, 2019
Extension function to replace spans
View AndroidExtensions.kt
fun Spannable.replaceSpans(spanResolver: (index: Int, span: Any) -> Any?): Spannable {
this.getSpans(0, this.length, Any::class.java).forEachIndexed { index, span ->
val newSpan = spanResolver(index, span) ?: return@forEachIndexed
this.setSpan(
newSpan,
this.getSpanStart(span),
this.getSpanEnd(span),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
}