Skip to content

Commit a9bbb9a

Browse files
committed
Merge branch 'trunk' into feature/implement-merging-of-placeholders
2 parents 9716bde + b94299d commit a9bbb9a

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,10 @@ class PlaceholderManager(
166166

167167
private suspend fun buildPlaceholderDrawable(adapter: PlaceholderAdapter, attrs: AztecAttributes): Drawable {
168168
val drawable = ContextCompat.getDrawable(aztecText.context, android.R.color.transparent)!!
169-
updateDrawableBounds(adapter, attrs, drawable)
169+
val editorWidth = if (aztecText.width > 0) {
170+
aztecText.width - aztecText.paddingStart - aztecText.paddingEnd
171+
} else aztecText.maxImagesWidth
172+
drawable.setBounds(0, 0, adapter.calculateWidth(attrs, editorWidth), adapter.calculateHeight(attrs, editorWidth))
170173
return drawable
171174
}
172175

@@ -395,23 +398,14 @@ class PlaceholderManager(
395398
spans.forEach {
396399
val type = it.attributes.getValue(TYPE_ATTRIBUTE)
397400
val adapter = adapters[type] ?: return@forEach
398-
updateDrawableBounds(adapter, it.attributes, it.drawable)
401+
it.drawable = buildPlaceholderDrawable(adapter, it.attributes)
399402
aztecText.refreshText(false)
400403
insertInPosition(it.attributes, aztecText.editableText.getSpanStart(it))
401404
}
402405
}
403406
}
404407
}
405408

406-
private suspend fun updateDrawableBounds(adapter: PlaceholderAdapter, attrs: AztecAttributes, drawable: Drawable?) {
407-
val editorWidth = if (aztecText.width > 0) {
408-
aztecText.width - aztecText.paddingStart - aztecText.paddingEnd - EDITOR_INNER_PADDING
409-
} else aztecText.maxImagesWidth
410-
if (drawable?.bounds?.right != editorWidth) {
411-
drawable?.setBounds(0, 0, adapter.calculateWidth(attrs, editorWidth), adapter.calculateHeight(attrs, editorWidth))
412-
}
413-
}
414-
415409
private suspend fun clearAllViews() {
416410
positionToIdMutex.withLock {
417411
for (placeholder in positionToId) {
@@ -549,6 +543,7 @@ class PlaceholderManager(
549543
data class Placeholder(val elementPosition: Int, val uuid: String)
550544

551545
companion object {
546+
private const val TAG = "PlaceholderManager"
552547
private const val DEFAULT_HTML_TAG = "placeholder"
553548
private const val UUID_ATTRIBUTE = "uuid"
554549
private const val TYPE_ATTRIBUTE = "type"

0 commit comments

Comments
 (0)