Skip to content

Commit a8b83f0

Browse files
committed
Implement ordered list with start
Implement ordered reversed list Implement ordered reversed list with start
1 parent 9f2cb0c commit a8b83f0

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

app/src/main/kotlin/org/wordpress/aztec/demo/MainActivity.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,24 @@ open class MainActivity : AppCompatActivity(),
9191
private val UNDERLINE = "<u style=\"color:lime\">Underline</u><br>"
9292
private val STRIKETHROUGH = "<s style=\"color:#ff666666\" class=\"test\">Strikethrough</s><br>" // <s> or <strike> or <del>
9393
private val ORDERED = "<ol style=\"color:green\"><li>Ordered</li><li>should have color</li></ol>"
94+
private val ORDERED_WITH_START = "<h4>Start in 10 List:</h4>" +
95+
"<ol start=\"10\">\n" +
96+
" <li>Ten</li>\n" +
97+
" <li>Eleven</li>\n" +
98+
" <li>Twelve</li>\n" +
99+
"</ol>"
100+
private val ORDERED_REVERSED = "<h4>Reversed List:</h4>" +
101+
"<ol reversed>\n" +
102+
" <li>Three</li>\n" +
103+
" <li>Two</li>\n" +
104+
" <li>One</li>\n" +
105+
"</ol>"
106+
private val ORDERED_REVERSED_WITH_START = "<h4>Reversed Start in 10 List:</h4>" +
107+
"<ol reversed start=\"10\">\n" +
108+
" <li>Ten</li>\n" +
109+
" <li>Nine</li>\n" +
110+
" <li>Eight</li>\n" +
111+
"</ol>"
94112
private val LINE = "<hr />"
95113
private val UNORDERED = "<ul><li style=\"color:darkred\">Unordered</li><li>Should not have color</li></ul>"
96114
private val QUOTE = "<blockquote>Quote</blockquote>"
@@ -147,6 +165,9 @@ open class MainActivity : AppCompatActivity(),
147165
UNDERLINE +
148166
STRIKETHROUGH +
149167
ORDERED +
168+
ORDERED_WITH_START +
169+
ORDERED_REVERSED +
170+
ORDERED_REVERSED_WITH_START +
150171
LINE +
151172
UNORDERED +
152173
QUOTE +

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,19 @@ abstract class AztecListSpan(override var nestingLevel: Int,
6565
.size
6666
}
6767

68+
fun getNumberOfItemsInProcessedLine(text: CharSequence): Int {
69+
val spanStart = (text as Spanned).getSpanStart(this)
70+
val spanEnd = text.getSpanEnd(this)
71+
72+
val listText = text.subSequence(spanStart, spanEnd) as Spanned
73+
74+
return if (listText.length == 0) {
75+
0
76+
} else {
77+
listText.split("\n").size
78+
}
79+
}
80+
6881
fun nestingDepth(text: Spanned, index: Int, nextIndex: Int): Int {
6982
val finalNextIndex = if (nextIndex > text.length) index else nextIndex
7083
return IAztecNestable.getNestingLevelAt(text, index, finalNextIndex)

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,22 @@ class AztecOrderedListSpan(
5555
p.color = listStyle.indicatorColor
5656
p.style = Paint.Style.FILL
5757

58-
val lineIndex = getIndexOfProcessedLine(text, end)
58+
var start = if (attributes.hasAttribute("start") == true) {
59+
attributes.getValue("start").toInt()
60+
} else {
61+
0
62+
}
63+
64+
val isReversed = attributes.hasAttribute("reversed")
65+
var lineIndex = if (start > 0) {
66+
if (isReversed) start - (getIndexOfProcessedLine(text, end) - 1)
67+
else start + (getIndexOfProcessedLine(text, end) - 1)
68+
} else {
69+
val number = getNumberOfItemsInProcessedLine(text)
70+
if (isReversed) number - (getIndexOfProcessedLine(text, end))
71+
else getIndexOfProcessedLine(text, end)
72+
}
73+
5974
val textToDraw = if (lineIndex > -1) {
6075
if (dir >= 0) lineIndex.toString() + "."
6176
else "." + lineIndex.toString()

0 commit comments

Comments
 (0)