From 47331a1c4f8f51fa476470addcdc97f345bf1f94 Mon Sep 17 00:00:00 2001 From: vojtasmrcek Date: Wed, 13 Nov 2024 10:45:46 +0100 Subject: [PATCH] Add redrawViews method to PlaceholderManager --- .../aztec/placeholders/PlaceholderManager.kt | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/media-placeholders/src/main/java/org/wordpress/aztec/placeholders/PlaceholderManager.kt b/media-placeholders/src/main/java/org/wordpress/aztec/placeholders/PlaceholderManager.kt index 8cf5c5331..baf5d4007 100644 --- a/media-placeholders/src/main/java/org/wordpress/aztec/placeholders/PlaceholderManager.kt +++ b/media-placeholders/src/main/java/org/wordpress/aztec/placeholders/PlaceholderManager.kt @@ -496,24 +496,28 @@ class PlaceholderManager( return } aztecText.viewTreeObserver.removeOnGlobalLayoutListener(this) - val spans = aztecText.editableText.getSpans( - 0, - aztecText.editableText.length, - AztecPlaceholderSpan::class.java - ) + job = redrawViews() + } + } - if (spans == null || spans.isEmpty()) { - return - } - job = launch { - clearAllViews() - spans.forEach { - val type = it.attributes.getValue(TYPE_ATTRIBUTE) - val adapter = adapters[type] ?: return@forEach - it.drawable = buildPlaceholderDrawable(adapter, it.attributes) - aztecText.refreshText(false) - insertInPosition(it.attributes, aztecText.editableText.getSpanStart(it)) - } + fun redrawViews(): Job? { + val spans = aztecText.editableText.getSpans( + 0, + aztecText.editableText.length, + AztecPlaceholderSpan::class.java + ) + + if (spans == null || spans.isEmpty()) { + return null + } + return launch { + clearAllViews() + spans.forEach { + val type = it.attributes.getValue(TYPE_ATTRIBUTE) + val adapter = adapters[type] ?: return@forEach + it.drawable = buildPlaceholderDrawable(adapter, it.attributes) + aztecText.refreshText(false) + insertInPosition(it.attributes, aztecText.editableText.getSpanStart(it)) } } }