Skip to content

Commit 9eaf5c9

Browse files
committed
fixed merge conflict
2 parents 4416b4f + 41bdd4c commit 9eaf5c9

File tree

10 files changed

+111
-29
lines changed

10 files changed

+111
-29
lines changed

.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 0 additions & 7 deletions
This file was deleted.

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: 19 additions & 7 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
@@ -410,7 +411,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
410411
BlockFormatter.HeaderStyle(verticalHeadingMargin),
411412
BlockFormatter.PreformatStyle(
412413
styles.getColor(R.styleable.AztecText_preformatBackground, 0),
413-
styles.getFraction(R.styleable.AztecText_preformatBackgroundAlpha, 1, 1, 0f),
414+
getPreformatBackgroundAlpha(styles),
414415
styles.getColor(R.styleable.AztecText_preformatColor, 0),
415416
verticalParagraphMargin)
416417
)
@@ -663,6 +664,12 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
663664
}
664665
}
665666

667+
// We are exposing this method in order to allow subclasses to set their own alpha value
668+
// for preformatted background
669+
open fun getPreformatBackgroundAlpha(styles: TypedArray): Float {
670+
return styles.getFraction(R.styleable.AztecText_preformatBackgroundAlpha, 1, 1, 0f)
671+
}
672+
666673
override fun onRestoreInstanceState(state: Parcelable?) {
667674
disableTextChangedListener()
668675

@@ -1098,6 +1105,10 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
10981105
}
10991106
}
11001107

1108+
open fun shouldSkipTidying(): Boolean {
1109+
return false
1110+
}
1111+
11011112
override fun afterTextChanged(text: Editable) {
11021113
if (isTextChangedListenerDisabled()) {
11031114
subWatcherNestingLevel()
@@ -1146,7 +1157,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
11461157

11471158
var cleanSource = CleaningUtils.cleanNestedBoldTags(source)
11481159
cleanSource = Format.removeSourceEditorFormatting(cleanSource, isInCalypsoMode, isInGutenbergMode)
1149-
builder.append(parser.fromHtml(cleanSource, context))
1160+
builder.append(parser.fromHtml(cleanSource, context, shouldSkipTidying()))
11501161

11511162
Format.preProcessSpannedText(builder, isInCalypsoMode)
11521163

@@ -1311,7 +1322,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
13111322

13121323
Format.postProcessSpannedText(output, isInCalypsoMode)
13131324

1314-
return EndOfBufferMarkerAdder.removeEndOfTextMarker(parser.toHtml(output, withCursorTag))
1325+
return EndOfBufferMarkerAdder.removeEndOfTextMarker(parser.toHtml(output, withCursorTag, shouldSkipTidying()))
13151326
}
13161327

13171328
// default behavior returns formatted HTML from this text
@@ -1513,13 +1524,14 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
15131524
deleteInlineStyleFromTheBeginning()
15141525
}
15151526
}
1516-
// Fix for crash when pasting text on Samsung Devices running Android 8.
1517-
// Ref: https://github.com/wordpress-mobile/WordPress-Android/issues/8827
1527+
// Fix for crash when pasting text on Samsung Devices running Android 7 & 8.
1528+
// Android 7 Ref: https://github.com/wordpress-mobile/WordPress-Android/issues/10872
1529+
// Android 8 Ref: https://github.com/wordpress-mobile/WordPress-Android/issues/8827
15181530
clipboardIdentifier -> {
1519-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && Build.VERSION.SDK_INT < 28
1531+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && Build.VERSION.SDK_INT < Build.VERSION_CODES.P
15201532
&& Build.MANUFACTURER.toLowerCase().equals("samsung")) {
15211533
// Nope return true
1522-
Toast.makeText(context, R.string.samsung_disabled_custom_clipboard, Toast.LENGTH_LONG).show()
1534+
Toast.makeText(context, context.getString(R.string.samsung_disabled_custom_clipboard, Build.VERSION.RELEASE), Toast.LENGTH_LONG).show()
15231535
} else {
15241536
return super.onTextContextMenuItem(id)
15251537
}

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

aztec/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<!-- GENERAL -->
44
<string name="cursor_moved">Cursor moved</string>
5-
<string name="samsung_disabled_custom_clipboard">Sorry, this feature is disabled on Android 8. Please use the Paste action instead.</string>
5+
<string name="samsung_disabled_custom_clipboard">Sorry, this feature is disabled on Android %1$s. Please use the Paste action instead.</string>
66

77
<!-- LINK DIALOG -->
88
<string name="link_dialog_title">Insert link</string>

0 commit comments

Comments
 (0)