Skip to content

Commit 5b0653e

Browse files
committed
Use context ref in task list span.
1 parent 12401d0 commit 5b0653e

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecTaskListSpan.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import org.wordpress.aztec.ITextFormat
3030
import org.wordpress.aztec.R
3131
import org.wordpress.aztec.formatting.BlockFormatter
3232
import org.wordpress.aztec.setTaskList
33+
import java.lang.ref.WeakReference
3334

3435
fun createTaskListSpan(
3536
nestingLevel: Int,
@@ -61,11 +62,12 @@ class AztecTaskListSpanAligned(
6162
open class AztecTaskListSpan(
6263
override var nestingLevel: Int,
6364
override var attributes: AztecAttributes = AztecAttributes(),
64-
val context: Context,
65+
context: Context,
6566
var listStyle: BlockFormatter.ListStyle = BlockFormatter.ListStyle(0, 0, 0, 0, 0),
6667
var onRefresh: ((AztecTaskListSpan) -> Unit)? = null
6768
) : AztecListSpan(nestingLevel, listStyle.verticalPadding) {
6869
private var toggled: Boolean = false
70+
private var contextRef: WeakReference<Context> = WeakReference(context)
6971
override val TAG = "ul"
7072

7173
override val startTag: String
@@ -82,7 +84,7 @@ open class AztecTaskListSpan(
8284
top: Int, baseline: Int, bottom: Int,
8385
text: CharSequence, start: Int, end: Int,
8486
first: Boolean, l: Layout) {
85-
if (!first) return
87+
if (!first || contextRef.get() == null) return
8688

8789
val spanStart = (text as Spanned).getSpanStart(this)
8890
val spanEnd = text.getSpanEnd(this)
@@ -99,7 +101,7 @@ open class AztecTaskListSpan(
99101
val drawableHeight = (0.8 * (p.fontMetrics.bottom - p.fontMetrics.top))
100102
// Make sure the marker is correctly aligned on RTL languages
101103
val markerStartPosition: Float = x + (listStyle.indicatorMargin * dir) * 1f
102-
val d: Drawable = context.resources.getDrawable(R.drawable.ic_checkbox, null)
104+
val d: Drawable = contextRef.get()!!.resources.getDrawable(R.drawable.ic_checkbox, null)
103105
val leftBound = markerStartPosition.toInt()
104106
if (isChecked(text, lineIndex)) {
105107
d.state = intArrayOf(android.R.attr.state_checked)

0 commit comments

Comments
 (0)