11package org.wordpress.aztec.spans
22
33import android.text.Layout
4+ import android.text.TextPaint
5+ import android.text.style.CharacterStyle
46import org.wordpress.aztec.AlignmentRendering
57import org.wordpress.aztec.AztecAttributes
68import org.wordpress.aztec.ITextFormat
9+ import org.wordpress.aztec.formatting.BlockFormatter
710import java.lang.StringBuilder
811
912fun createListItemSpan (nestingLevel : Int ,
1013 alignmentRendering : AlignmentRendering ,
11- attributes : AztecAttributes = AztecAttributes ()) : IAztecBlockSpan =
14+ attributes : AztecAttributes = AztecAttributes (),
15+ listItemStyle : BlockFormatter .ListItemStyle = BlockFormatter .ListItemStyle (
16+ false, 0)): IAztecBlockSpan =
1217 when (alignmentRendering) {
13- AlignmentRendering .SPAN_LEVEL -> AztecListItemSpanAligned (nestingLevel, attributes, null )
14- AlignmentRendering .VIEW_LEVEL -> AztecListItemSpan (nestingLevel, attributes)
18+ AlignmentRendering .SPAN_LEVEL -> AztecListItemSpanAligned (nestingLevel, attributes, null , listItemStyle )
19+ AlignmentRendering .VIEW_LEVEL -> AztecListItemSpan (nestingLevel, attributes, listItemStyle )
1520 }
1621
1722/* *
@@ -24,7 +29,9 @@ fun createListItemSpan(nestingLevel: Int,
2429 */
2530open class AztecListItemSpan (
2631 override var nestingLevel : Int ,
27- override var attributes : AztecAttributes ) : IAztecCompositeBlockSpan {
32+ override var attributes : AztecAttributes ,
33+ var listItemStyle : BlockFormatter .ListItemStyle = BlockFormatter .ListItemStyle (
34+ false, 0)) : CharacterStyle(), IAztecCompositeBlockSpan {
2835 fun toggleCheck () {
2936 if (attributes.getValue(CHECKED ) == " true" ) {
3037 attributes.setValue(CHECKED , " false" )
@@ -74,13 +81,27 @@ open class AztecListItemSpan(
7481
7582 override var endBeforeBleed: Int = - 1
7683 override var startBeforeCollapse: Int = - 1
84+
7785 companion object {
7886 const val CHECKED = " checked"
7987 }
88+
89+ override fun updateDrawState (tp : TextPaint ) {
90+ val isChecked = attributes.getValue(CHECKED ) == " true"
91+
92+ if (listItemStyle.strikeThroughCheckedItems) {
93+ tp.isStrikeThruText = isChecked
94+ }
95+
96+ if (listItemStyle.checkedItemsTextColor != 0 && isChecked) {
97+ tp.color = listItemStyle.checkedItemsTextColor
98+ }
99+ }
80100}
81101
82102class AztecListItemSpanAligned (
83103 nestingLevel : Int ,
84104 attributes : AztecAttributes ,
85- override var align : Layout .Alignment ?
86- ) : AztecListItemSpan(nestingLevel, attributes), IAztecAlignmentSpan
105+ override var align : Layout .Alignment ? ,
106+ listItemStyle : BlockFormatter .ListItemStyle = BlockFormatter .ListItemStyle (false, 0)
107+ ) : AztecListItemSpan(nestingLevel, attributes, listItemStyle), IAztecAlignmentSpan
0 commit comments