Skip to content

Commit 27b36d9

Browse files
committed
Added strikethrough and checked color options to task list span.
1 parent 446bd41 commit 27b36d9

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
11
package org.wordpress.aztec.spans
22

33
import android.text.Layout
4+
import android.text.TextPaint
5+
import android.text.style.CharacterStyle
46
import org.wordpress.aztec.AlignmentRendering
57
import org.wordpress.aztec.AztecAttributes
68
import org.wordpress.aztec.ITextFormat
9+
import org.wordpress.aztec.formatting.BlockFormatter
710
import java.lang.StringBuilder
811

912
fun 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
*/
2530
open 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

82102
class 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

Comments
 (0)