Skip to content

Commit 806c3a4

Browse files
authored
Merge pull request #1093 from wordpress-mobile/add-redraw-placeholder-method
Add redrawViews method to PlaceholderManager
2 parents cbb43e3 + 47331a1 commit 806c3a4

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

media-placeholders/src/main/java/org/wordpress/aztec/placeholders/PlaceholderManager.kt

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -496,24 +496,28 @@ class PlaceholderManager(
496496
return
497497
}
498498
aztecText.viewTreeObserver.removeOnGlobalLayoutListener(this)
499-
val spans = aztecText.editableText.getSpans(
500-
0,
501-
aztecText.editableText.length,
502-
AztecPlaceholderSpan::class.java
503-
)
499+
job = redrawViews()
500+
}
501+
}
504502

505-
if (spans == null || spans.isEmpty()) {
506-
return
507-
}
508-
job = launch {
509-
clearAllViews()
510-
spans.forEach {
511-
val type = it.attributes.getValue(TYPE_ATTRIBUTE)
512-
val adapter = adapters[type] ?: return@forEach
513-
it.drawable = buildPlaceholderDrawable(adapter, it.attributes)
514-
aztecText.refreshText(false)
515-
insertInPosition(it.attributes, aztecText.editableText.getSpanStart(it))
516-
}
503+
fun redrawViews(): Job? {
504+
val spans = aztecText.editableText.getSpans(
505+
0,
506+
aztecText.editableText.length,
507+
AztecPlaceholderSpan::class.java
508+
)
509+
510+
if (spans == null || spans.isEmpty()) {
511+
return null
512+
}
513+
return launch {
514+
clearAllViews()
515+
spans.forEach {
516+
val type = it.attributes.getValue(TYPE_ATTRIBUTE)
517+
val adapter = adapters[type] ?: return@forEach
518+
it.drawable = buildPlaceholderDrawable(adapter, it.attributes)
519+
aztecText.refreshText(false)
520+
insertInPosition(it.attributes, aztecText.editableText.getSpanStart(it))
517521
}
518522
}
519523
}

0 commit comments

Comments
 (0)