Created
July 25, 2017 02:50
-
-
Save elsennov/384a95da93723e192c7c5f3f97128285 to your computer and use it in GitHub Desktop.
Coroutine async UI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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