Skip to content

Commit 6bd0ee0

Browse files
committed
Wired styling data to all the places where we create tasklist.
1 parent 27b36d9 commit 6bd0ee0

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

aztec/src/main/kotlin/org/wordpress/aztec/AztecText.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,8 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
313313
var lastPressedXCoord: Int = 0
314314
var lastPressedYCoord: Int = 0
315315

316+
private lateinit var listItemStyle: BlockFormatter.ListItemStyle
317+
316318
interface OnSelectionChangedListener {
317319
fun onSelectionChanged(selStart: Int, selEnd: Int)
318320
}
@@ -444,8 +446,14 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
444446
styles.getDimensionPixelSize(R.styleable.AztecText_bulletPadding, 0),
445447
styles.getDimensionPixelSize(R.styleable.AztecText_bulletWidth, 0),
446448
verticalParagraphPadding)
449+
450+
listItemStyle = BlockFormatter.ListItemStyle(
451+
styles.getBoolean(R.styleable.AztecText_taskListStrikethroughChecked, false),
452+
styles.getColor(R.styleable.AztecText_taskListCheckedTextColor, 0))
453+
447454
blockFormatter = BlockFormatter(editor = this,
448455
listStyle = listStyle,
456+
listItemStyle = listItemStyle,
449457
quoteStyle = BlockFormatter.QuoteStyle(
450458
styles.getColor(R.styleable.AztecText_quoteBackground, 0),
451459
styles.getColor(R.styleable.AztecText_quoteColor, 0),
@@ -771,7 +779,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
771779
BlockElementWatcher(this)
772780
.add(HeadingHandler(alignmentRendering))
773781
.add(ListHandler())
774-
.add(ListItemHandler(alignmentRendering))
782+
.add(ListItemHandler(alignmentRendering, listItemStyle))
775783
.add(QuoteHandler())
776784
.add(PreformatHandler())
777785
.install(this)
@@ -1582,6 +1590,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
15821590
editable.getSpans(start, end, EndOfParagraphMarker::class.java).forEach { it.verticalPadding = verticalParagraphPadding }
15831591
editable.getSpans(start, end, AztecURLSpan::class.java).forEach { it.linkStyle = linkFormatter.linkStyle }
15841592
editable.getSpans(start, end, AztecCodeSpan::class.java).forEach { it.codeStyle = inlineFormatter.codeStyle }
1593+
editable.getSpans(start, end, AztecListItemSpan::class.java).forEach { it.listItemStyle = listItemStyle }
15851594

15861595
val imageSpans = editable.getSpans(start, end, AztecImageSpan::class.java)
15871596
imageSpans.forEach {

aztec/src/main/kotlin/org/wordpress/aztec/formatting/BlockFormatter.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import kotlin.reflect.KClass
4444

4545
class BlockFormatter(editor: AztecText,
4646
private val listStyle: ListStyle,
47+
private val listItemStyle: ListItemStyle,
4748
private val quoteStyle: QuoteStyle,
4849
private val headerStyle: HeaderStyles,
4950
private val preformatStyle: PreformatStyle,
@@ -60,6 +61,8 @@ class BlockFormatter(editor: AztecText,
6061
}
6162
}
6263

64+
data class ListItemStyle(val strikeThroughCheckedItems: Boolean, val checkedItemsTextColor: Int)
65+
6366
data class QuoteStyle(val quoteBackground: Int, val quoteColor: Int, val quoteBackgroundAlpha: Float, val quoteMargin: Int, val quotePadding: Int, val quoteWidth: Int, val verticalPadding: Int)
6467
data class PreformatStyle(val preformatBackground: Int, val preformatBackgroundAlpha: Float, val preformatColor: Int, val verticalPadding: Int)
6568
data class HeaderStyles(val verticalPadding: Int, val styles: Map<AztecHeadingSpan.Heading, HeadingStyle>) {
@@ -452,7 +455,7 @@ class BlockFormatter(editor: AztecText,
452455
return when (textFormat) {
453456
AztecTextFormat.FORMAT_ORDERED_LIST -> listOf(createOrderedListSpan(nestingLevel, alignmentRendering, attrs, listStyle), createListItemSpan(nestingLevel + 1, alignmentRendering))
454457
AztecTextFormat.FORMAT_UNORDERED_LIST -> listOf(createUnorderedListSpan(nestingLevel, alignmentRendering, attrs, listStyle), createListItemSpan(nestingLevel + 1, alignmentRendering))
455-
AztecTextFormat.FORMAT_TASK_LIST -> listOf(createTaskListSpan(nestingLevel, alignmentRendering, attrs, editor.context, listStyle), createListItemSpan(nestingLevel + 1, alignmentRendering))
458+
AztecTextFormat.FORMAT_TASK_LIST -> listOf(createTaskListSpan(nestingLevel, alignmentRendering, attrs, editor.context, listStyle), createListItemSpan(nestingLevel + 1, alignmentRendering, listItemStyle = listItemStyle))
456459
AztecTextFormat.FORMAT_QUOTE -> listOf(createAztecQuoteSpan(nestingLevel, attrs, alignmentRendering, quoteStyle))
457460
AztecTextFormat.FORMAT_HEADING_1,
458461
AztecTextFormat.FORMAT_HEADING_2,
@@ -500,7 +503,7 @@ class BlockFormatter(editor: AztecText,
500503
typeIsAssignableTo(AztecOrderedListSpan::class) -> createOrderedListSpan(nestingLevel, alignmentRendering, attrs, listStyle)
501504
typeIsAssignableTo(AztecUnorderedListSpan::class) -> createUnorderedListSpan(nestingLevel, alignmentRendering, attrs, listStyle)
502505
typeIsAssignableTo(AztecTaskListSpan::class) -> createTaskListSpan(nestingLevel, alignmentRendering, attrs, editor.context, listStyle)
503-
typeIsAssignableTo(AztecListItemSpan::class) -> createListItemSpan(nestingLevel, alignmentRendering, attrs)
506+
typeIsAssignableTo(AztecListItemSpan::class) -> createListItemSpan(nestingLevel, alignmentRendering, attrs, listItemStyle)
504507
typeIsAssignableTo(AztecQuoteSpan::class) -> createAztecQuoteSpan(nestingLevel, attrs, alignmentRendering, quoteStyle)
505508
typeIsAssignableTo(AztecHeadingSpan::class) -> createHeadingSpan(nestingLevel, textFormat, attrs, alignmentRendering, headerStyle)
506509
typeIsAssignableTo(AztecPreformatSpan::class) -> createPreformatSpan(nestingLevel, alignmentRendering, attrs, preformatStyle)
@@ -812,7 +815,7 @@ class BlockFormatter(editor: AztecText,
812815
BlockHandler.set(editableText, listSpan, start, end)
813816
// special case for styling single empty lines
814817
if (end - start == 1 && (editableText[end - 1] == '\n' || editableText[end - 1] == Constants.END_OF_BUFFER_MARKER)) {
815-
ListItemHandler.newListItem(editableText, start, end, listSpan.nestingLevel + 1, alignmentRendering)
818+
ListItemHandler.newListItem(editableText, start, end, listSpan.nestingLevel + 1, alignmentRendering, listItemStyle)
816819
} else {
817820
val listEnd = if (end == editableText.length) end else end - 1
818821
val listContent = editableText.substring(start, listEnd)
@@ -831,7 +834,7 @@ class BlockFormatter(editor: AztecText,
831834
start + lineStart,
832835
start + lineEnd,
833836
listSpan.nestingLevel + 1,
834-
alignmentRendering)
837+
alignmentRendering, listItemStyle)
835838
}
836839
}
837840
}

aztec/src/main/kotlin/org/wordpress/aztec/handlers/ListItemHandler.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.wordpress.aztec.handlers
22

33
import android.text.Spannable
44
import org.wordpress.aztec.AlignmentRendering
5+
import org.wordpress.aztec.formatting.BlockFormatter
56
import org.wordpress.aztec.spans.AztecListItemSpan
67
import org.wordpress.aztec.spans.AztecListItemSpan.Companion.CHECKED
78
import org.wordpress.aztec.spans.AztecTaskListSpan
@@ -10,12 +11,13 @@ import org.wordpress.aztec.spans.createListItemSpan
1011
import org.wordpress.aztec.watchers.TextDeleter
1112

1213
class ListItemHandler(
13-
val alignmentRendering: AlignmentRendering
14+
val alignmentRendering: AlignmentRendering,
15+
val listItemStyle: BlockFormatter.ListItemStyle
1416
) : BlockHandler<AztecListItemSpan>(AztecListItemSpan::class.java) {
1517

1618
override fun handleNewlineAtStartOfBlock() {
1719
// newline added at start of bullet so, add a new bullet
18-
newListItem(text, newlineIndex, newlineIndex + 1, block.span.nestingLevel, alignmentRendering)
20+
newListItem(text, newlineIndex, newlineIndex + 1, block.span.nestingLevel, alignmentRendering, listItemStyle)
1921

2022
// push current bullet forward
2123
block.start = newlineIndex + 1
@@ -58,7 +60,7 @@ class ListItemHandler(
5860
newListItemStart = newlineIndex
5961
}
6062

61-
newListItem(text, newListItemStart, block.end, block.span.nestingLevel, alignmentRendering)
63+
newListItem(text, newListItemStart, block.end, block.span.nestingLevel, alignmentRendering, listItemStyle)
6264
block.end = newListItemStart
6365
}
6466

@@ -69,7 +71,7 @@ class ListItemHandler(
6971
}
7072

7173
// attach a new bullet around the end-of-text marker
72-
newListItem(text, markerIndex, markerIndex + 1, block.span.nestingLevel, alignmentRendering)
74+
newListItem(text, markerIndex, markerIndex + 1, block.span.nestingLevel, alignmentRendering, listItemStyle)
7375

7476
// the current list item has bled over to the marker so, let's adjust its range to just before the marker.
7577
// There's a newline there hopefully :)
@@ -82,10 +84,11 @@ class ListItemHandler(
8284
start: Int,
8385
end: Int,
8486
nestingLevel: Int,
85-
alignmentRendering: AlignmentRendering
87+
alignmentRendering: AlignmentRendering,
88+
listItemStyle: BlockFormatter.ListItemStyle
8689
) {
8790
val isInTaskList = !text.getSpans(start, end, AztecTaskListSpan::class.java).isNullOrEmpty()
88-
set(text, createListItemSpan(nestingLevel, alignmentRendering).apply {
91+
set(text, createListItemSpan(nestingLevel, alignmentRendering, listItemStyle = listItemStyle).apply {
8992
if (isInTaskList) {
9093
this.attributes.setValue(CHECKED, "false")
9194
}

0 commit comments

Comments
 (0)