Skip to content

Commit 2f913c3

Browse files
committed
Cleanup PlaceholderManager.kt
1 parent 3da2732 commit 2f913c3

File tree

1 file changed

+4
-19
lines changed

1 file changed

+4
-19
lines changed

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

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import android.graphics.drawable.Drawable
77
import android.text.Editable
88
import android.text.Layout
99
import android.text.Spanned
10-
import android.util.Log
1110
import android.view.MotionEvent
1211
import android.view.View
1312
import android.view.ViewTreeObserver
@@ -111,7 +110,10 @@ class PlaceholderManager(
111110

112111
private suspend fun buildPlaceholderDrawable(adapter: PlaceholderAdapter, attrs: AztecAttributes): Drawable {
113112
val drawable = ContextCompat.getDrawable(aztecText.context, android.R.color.transparent)!!
114-
updateDrawableBounds(adapter, attrs, drawable)
113+
val editorWidth = if (aztecText.width > 0) {
114+
aztecText.width - aztecText.paddingStart - aztecText.paddingEnd
115+
} else aztecText.maxImagesWidth
116+
drawable.setBounds(0, 0, adapter.calculateWidth(attrs, editorWidth), adapter.calculateHeight(attrs, editorWidth))
115117
return drawable
116118
}
117119

@@ -318,31 +320,14 @@ class PlaceholderManager(
318320
spans.forEach {
319321
val type = it.attributes.getValue(TYPE_ATTRIBUTE)
320322
val adapter = adapters[type] ?: return@forEach
321-
val start = aztecText.editableText.getSpanStart(it)
322-
val end = aztecText.editableText.getSpanEnd(it)
323-
val flags = aztecText.editableText.getSpanFlags(it)
324-
aztecText.editableText.removeSpan(it)
325323
it.drawable = buildPlaceholderDrawable(adapter, it.attributes)
326-
aztecText.editableText.setSpan(it, start, end, flags)
327324
aztecText.refreshText(false)
328325
insertInPosition(it.attributes, aztecText.editableText.getSpanStart(it))
329326
}
330327
}
331328
}
332329
}
333330

334-
private suspend fun updateDrawableBounds(adapter: PlaceholderAdapter, attrs: AztecAttributes, drawable: Drawable?) {
335-
val editorWidth = if (aztecText.width > 0) {
336-
aztecText.width - aztecText.paddingStart - aztecText.paddingEnd
337-
} else aztecText.maxImagesWidth
338-
Log.d(TAG, "Updating drawable bounds - editor width: $editorWidth")
339-
if (drawable?.bounds?.right != editorWidth) {
340-
Log.d(TAG, "Bounds before - right - ${drawable?.bounds?.right} - bottom - ${drawable?.bounds?.bottom}")
341-
drawable?.setBounds(0, 0, adapter.calculateWidth(attrs, editorWidth), adapter.calculateHeight(attrs, editorWidth))
342-
Log.d(TAG, "Bounds after - right - ${drawable?.bounds?.right} - bottom - ${drawable?.bounds?.bottom}")
343-
}
344-
}
345-
346331
private fun clearAllViews() {
347332
for (placeholder in positionToId) {
348333
container.findViewWithTag<View>(placeholder.uuid)?.let {

0 commit comments

Comments
 (0)