Skip to content

Commit 3fee0e0

Browse files
authored
Merge Release/1.3.36 into master (#885)
1 parent c41afad commit 3fee0e0

File tree

8 files changed

+105
-17
lines changed

8 files changed

+105
-17
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## [1.3.36](https://github.com/wordpress-mobile/AztecEditor-Android/releases/tag/v1.3.36)
4+
### Changed
5+
- Implement start and reversed in lists
6+
- Allow preformatted background alpha and tidying to be set from child classes
7+
38
## [1.3.35](https://github.com/wordpress-mobile/AztecEditor-Android/releases/tag/v1.3.35)
49
### Changed
510
- Update Glide version to 4.10.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ repositories {
105105
```
106106
```gradle
107107
dependencies {
108-
api ('com.github.wordpress-mobile.WordPress-Aztec-Android:aztec:v1.3.35')
108+
api ('com.github.wordpress-mobile.WordPress-Aztec-Android:aztec:v1.3.36')
109109
}
110110
```
111111

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,46 @@ 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>"
112+
private val ORDERED_REVERSED_NEGATIVE_WITH_START = "<h4>Reversed Start in 1 List:</h4>" +
113+
"<ol reversed start=\"1\">\n" +
114+
" <li>One</li>\n" +
115+
" <li>Zero</li>\n" +
116+
" <li>Minus One</li>\n" +
117+
"</ol>"
118+
private val ORDERED_REVERSED_WITH_START_IDENT = "<h4>Reversed Start in 6 List:</h4>" +
119+
"<ol reversed>" +
120+
" <li>Six</li>" +
121+
" <li>Five</li>" +
122+
" <li>Four</li>" +
123+
" <li>Three</li>" +
124+
" <li>Two</li>" +
125+
" <li>One<ol>" +
126+
" <li>One</li>" +
127+
" <li>Two</li>" +
128+
" <li>Three</li>" +
129+
" <li>Four</li>" +
130+
" <li>Five</li>" +
131+
" <li>Six</li>" +
132+
" <li>Seven</li> " +
133+
" </ol></li></ol>"
94134
private val LINE = "<hr />"
95135
private val UNORDERED = "<ul><li style=\"color:darkred\">Unordered</li><li>Should not have color</li></ul>"
96136
private val QUOTE = "<blockquote>Quote</blockquote>"
@@ -147,6 +187,11 @@ open class MainActivity : AppCompatActivity(),
147187
UNDERLINE +
148188
STRIKETHROUGH +
149189
ORDERED +
190+
ORDERED_WITH_START +
191+
ORDERED_REVERSED +
192+
ORDERED_REVERSED_WITH_START +
193+
ORDERED_REVERSED_NEGATIVE_WITH_START +
194+
ORDERED_REVERSED_WITH_START_IDENT +
150195
LINE +
151196
UNORDERED +
152197
QUOTE +

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class AztecParser @JvmOverloads constructor(val plugins: List<IAztecPlugin> = li
7575
return spanned
7676
}
7777

78-
fun fromHtml(source: String, context: Context): Spanned {
79-
val tidySource = tidy(source)
78+
fun fromHtml(source: String, context: Context, shouldSkipTidying: Boolean = false): Spanned {
79+
val tidySource = if (shouldSkipTidying) source else tidy(source)
8080

8181
val spanned = SpannableStringBuilder(Html.fromHtml(tidySource,
8282
AztecTagHandler(context, plugins), context, plugins, ignoredTags))
@@ -90,7 +90,8 @@ class AztecParser @JvmOverloads constructor(val plugins: List<IAztecPlugin> = li
9090
return spanned
9191
}
9292

93-
fun toHtml(text: Spanned, withCursor: Boolean = false): String {
93+
@JvmOverloads
94+
fun toHtml(text: Spanned, withCursor: Boolean = false, shouldSkipTidying: Boolean = false): String {
9495
val out = StringBuilder()
9596

9697
val data = SpannableStringBuilder(text)
@@ -107,7 +108,8 @@ class AztecParser @JvmOverloads constructor(val plugins: List<IAztecPlugin> = li
107108
}
108109

109110
withinHtml(out, data)
110-
val html = postprocessHtml(tidy(out.toString()))
111+
val tidyOut = if (shouldSkipTidying) out.toString() else tidy(out.toString())
112+
val html = postprocessHtml(tidyOut)
111113
return html
112114
}
113115

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import android.annotation.SuppressLint
2121
import android.content.ClipData
2222
import android.content.ClipboardManager
2323
import android.content.Context
24+
import android.content.res.TypedArray
2425
import android.graphics.Bitmap
2526
import android.graphics.Canvas
2627
import android.graphics.drawable.BitmapDrawable
@@ -417,7 +418,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
417418
BlockFormatter.HeaderStyle(verticalHeadingMargin),
418419
BlockFormatter.PreformatStyle(
419420
styles.getColor(R.styleable.AztecText_preformatBackground, 0),
420-
styles.getFraction(R.styleable.AztecText_preformatBackgroundAlpha, 1, 1, 0f),
421+
getPreformatBackgroundAlpha(styles),
421422
styles.getColor(R.styleable.AztecText_preformatColor, 0),
422423
verticalParagraphMargin)
423424
)
@@ -709,6 +710,12 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
709710
return inputConnectionRef?.get()!!
710711
}
711712

713+
// We are exposing this method in order to allow subclasses to set their own alpha value
714+
// for preformatted background
715+
open fun getPreformatBackgroundAlpha(styles: TypedArray): Float {
716+
return styles.getFraction(R.styleable.AztecText_preformatBackgroundAlpha, 1, 1, 0f)
717+
}
718+
712719
override fun onRestoreInstanceState(state: Parcelable?) {
713720
disableTextChangedListener()
714721

@@ -1144,6 +1151,10 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
11441151
}
11451152
}
11461153

1154+
open fun shouldSkipTidying(): Boolean {
1155+
return false
1156+
}
1157+
11471158
override fun afterTextChanged(text: Editable) {
11481159
if (isTextChangedListenerDisabled()) {
11491160
subWatcherNestingLevel()
@@ -1192,7 +1203,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
11921203

11931204
var cleanSource = CleaningUtils.cleanNestedBoldTags(source)
11941205
cleanSource = Format.removeSourceEditorFormatting(cleanSource, isInCalypsoMode, isInGutenbergMode)
1195-
builder.append(parser.fromHtml(cleanSource, context))
1206+
builder.append(parser.fromHtml(cleanSource, context, shouldSkipTidying()))
11961207

11971208
Format.preProcessSpannedText(builder, isInCalypsoMode)
11981209

@@ -1357,7 +1368,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
13571368

13581369
Format.postProcessSpannedText(output, isInCalypsoMode)
13591370

1360-
return EndOfBufferMarkerAdder.removeEndOfTextMarker(parser.toHtml(output, withCursorTag))
1371+
return EndOfBufferMarkerAdder.removeEndOfTextMarker(parser.toHtml(output, withCursorTag, shouldSkipTidying()))
13611372
}
13621373

13631374
// default behavior returns formatted HTML from this text

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ abstract class AztecListSpan(override var nestingLevel: Int,
3434
}
3535
}
3636

37-
fun getIndexOfProcessedLine(text: CharSequence, end: Int): Int {
37+
fun getIndexOfProcessedLine(text: CharSequence, end: Int): Int? {
3838
val spanStart = (text as Spanned).getSpanStart(this)
3939
val spanEnd = text.getSpanEnd(this)
4040

@@ -44,7 +44,7 @@ abstract class AztecListSpan(override var nestingLevel: Int,
4444
val hasSublist = listText.getSpans(end - spanStart - 1, end - spanStart, AztecListSpan::class.java)
4545
.any { it.nestingLevel > nestingLevel }
4646
if (hasSublist) {
47-
return -1
47+
return null
4848
}
4949
}
5050

@@ -55,7 +55,7 @@ abstract class AztecListSpan(override var nestingLevel: Int,
5555
.any { it.nestingLevel == nestingLevel + 1 && listText.getSpanStart(it) == startOfLine }
5656

5757
if (!isValidListItem) {
58-
return -1
58+
return null
5959
}
6060

6161
// count the list item spans up to the current line with the expected nesting level => item number
@@ -65,6 +65,17 @@ 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 listText.getSpans(0, listText.length, AztecListItemSpan::class.java)
75+
.filter { it.nestingLevel == nestingLevel + 1 }
76+
.size
77+
}
78+
6879
fun nestingDepth(text: Spanned, index: Int, nextIndex: Int): Int {
6980
val finalNextIndex = if (nextIndex > text.length) index else nextIndex
7081
return IAztecNestable.getNestingLevelAt(text, index, finalNextIndex)

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,26 @@ class AztecOrderedListSpan(
5555
p.color = listStyle.indicatorColor
5656
p.style = Paint.Style.FILL
5757

58-
val lineIndex = getIndexOfProcessedLine(text, end)
59-
val textToDraw = if (lineIndex > -1) {
60-
if (dir >= 0) lineIndex.toString() + "."
61-
else "." + lineIndex.toString()
58+
val start = if (attributes.hasAttribute("start") == true) {
59+
attributes.getValue("start").toInt()
6260
} else {
63-
""
61+
0
62+
}
63+
64+
var textToDraw = ""
65+
getIndexOfProcessedLine(text, end)?.let {
66+
val isReversed = attributes.hasAttribute("reversed")
67+
val lineIndex = if (start > 0) {
68+
if (isReversed) start - (it - 1)
69+
else start + (it - 1)
70+
} else {
71+
val number = getNumberOfItemsInProcessedLine(text)
72+
if (isReversed) number - (it - 1)
73+
else it
74+
}
75+
76+
textToDraw = if (dir >= 0) lineIndex.toString() + "."
77+
else "." + lineIndex.toString()
6478
}
6579

6680
val width = p.measureText(textToDraw)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class AztecUnorderedListSpan(
5353
p.style = Paint.Style.FILL
5454

5555
val lineIndex = getIndexOfProcessedLine(text, end)
56-
val textToDraw = if (lineIndex > -1) "\u2022" else ""
56+
val textToDraw = if (lineIndex != null) "\u2022" else ""
5757

5858
val width = p.measureText(textToDraw)
5959

0 commit comments

Comments
 (0)