Skip to content

Instantly share code, notes, and snippets.

@elsennov
Created July 25, 2017 02:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elsennov/384a95da93723e192c7c5f3f97128285 to your computer and use it in GitHub Desktop.
Save elsennov/384a95da93723e192c7c5f3f97128285 to your computer and use it in GitHub Desktop.
Coroutine async UI
private fun applyHashtagSpanForResiNumber(fullText: String,
messageEditorSpannable: Spannable) {
launch(UI) {
var indexAsync = async(CommonPool, CoroutineStart.LAZY) {
fullText.indexOf(RESI_NUMBER, 0)
}
while (indexAsync.await() != -1) {
val hashtagSpanAsync = async(CommonPool, CoroutineStart.LAZY) {
CharacterStyle.wrap(hashtagForegroundColorSpan)
}
val hashtagSpanValue = hashtagSpanAsync.await()
messageEditorSpannable.setSpan(
hashtagSpanValue,
indexAsync.await(),
indexAsync.await() + RESI_NUMBER.length,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
)
indexAsync = async(CommonPool, CoroutineStart.LAZY) {
fullText.indexOf(RESI_NUMBER, indexAsync.await() + 1)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment