Skip to content

Commit 1d07842

Browse files
committed
Make drawable null safe in task list span
1 parent 9dc1510 commit 1d07842

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,24 +101,24 @@ open class AztecTaskListSpan(
101101
val drawableHeight = (0.8 * (p.fontMetrics.bottom - p.fontMetrics.top))
102102
// Make sure the marker is correctly aligned on RTL languages
103103
val markerStartPosition: Float = x + (listStyle.indicatorMargin * dir) * 1f
104-
val d: Drawable = contextRef.get()!!.resources.getDrawable(R.drawable.ic_checkbox, null)
104+
val d: Drawable? = contextRef.get()?.resources?.getDrawable(R.drawable.ic_checkbox, null)
105105
val leftBound = markerStartPosition.toInt()
106106
if (isChecked(text, lineIndex)) {
107-
d.state = intArrayOf(android.R.attr.state_checked)
107+
d?.state = intArrayOf(android.R.attr.state_checked)
108108
} else {
109-
d.state = intArrayOf()
109+
d?.state = intArrayOf()
110110
}
111111
val (startShift, endShift) = if (dir > 0) {
112112
0.8 to 0.2
113113
} else {
114114
0.2 to 0.8
115115
}
116116

117-
d.setBounds((leftBound - drawableHeight * startShift).toInt().coerceAtLeast(0),
117+
d?.setBounds((leftBound - drawableHeight * startShift).toInt().coerceAtLeast(0),
118118
(baseline - drawableHeight * 0.8).toInt(),
119119
(leftBound + drawableHeight * endShift).toInt(),
120120
(baseline + drawableHeight * 0.2).toInt())
121-
d.draw(c)
121+
d?.draw(c)
122122

123123
p.color = oldColor
124124
p.style = style

0 commit comments

Comments
 (0)