@@ -30,6 +30,7 @@ import org.wordpress.aztec.ITextFormat
3030import org.wordpress.aztec.R
3131import org.wordpress.aztec.formatting.BlockFormatter
3232import org.wordpress.aztec.setTaskList
33+ import java.lang.ref.WeakReference
3334
3435fun createTaskListSpan (
3536 nestingLevel : Int ,
@@ -61,11 +62,12 @@ class AztecTaskListSpanAligned(
6162open 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