Skip to content

Commit

Permalink
Make drawable null safe in task list span
Browse files Browse the repository at this point in the history
  • Loading branch information
khaykov committed Jul 25, 2024
1 parent 9dc1510 commit 1d07842
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,24 +101,24 @@ open class AztecTaskListSpan(
val drawableHeight = (0.8 * (p.fontMetrics.bottom - p.fontMetrics.top))
// Make sure the marker is correctly aligned on RTL languages
val markerStartPosition: Float = x + (listStyle.indicatorMargin * dir) * 1f
val d: Drawable = contextRef.get()!!.resources.getDrawable(R.drawable.ic_checkbox, null)
val d: Drawable? = contextRef.get()?.resources?.getDrawable(R.drawable.ic_checkbox, null)
val leftBound = markerStartPosition.toInt()
if (isChecked(text, lineIndex)) {
d.state = intArrayOf(android.R.attr.state_checked)
d?.state = intArrayOf(android.R.attr.state_checked)
} else {
d.state = intArrayOf()
d?.state = intArrayOf()
}
val (startShift, endShift) = if (dir > 0) {
0.8 to 0.2
} else {
0.2 to 0.8
}

d.setBounds((leftBound - drawableHeight * startShift).toInt().coerceAtLeast(0),
d?.setBounds((leftBound - drawableHeight * startShift).toInt().coerceAtLeast(0),
(baseline - drawableHeight * 0.8).toInt(),
(leftBound + drawableHeight * endShift).toInt(),
(baseline + drawableHeight * 0.2).toInt())
d.draw(c)
d?.draw(c)

p.color = oldColor
p.style = style
Expand Down

0 comments on commit 1d07842

Please sign in to comment.