Skip to content

Commit ea627b6

Browse files
committed
Update AlignmentApproach to AlignmentRendering
1 parent bff8cac commit ea627b6

26 files changed

+155
-152
lines changed

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

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.wordpress.aztec
2+
3+
/**
4+
* With [SPAN_LEVEL] any alignment must be specified at the span level. Importantly, this
5+
* means that the View's gravity will always be ignored in determining the rendering of
6+
* the text's alignment.
7+
*
8+
* With [VIEW_LEVEL] alignment, the rendering of alignment is determined by the View's gravity.
9+
* Note that it is not possible to update the underlying alignment using [AztecText.toggleFormatting]
10+
* when you are using [VIEW_LEVEL] alignment rendering.
11+
*/
12+
enum class AlignmentRendering { SPAN_LEVEL, VIEW_LEVEL }

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ import java.util.ArrayList
5757
import java.util.Collections
5858
import java.util.Comparator
5959

60-
class AztecParser @JvmOverloads constructor(private val alignmentApproach: AlignmentApproach,
60+
class AztecParser @JvmOverloads constructor(private val alignmentRendering: AlignmentRendering,
6161
val plugins: List<IAztecPlugin> = listOf(),
6262
private val ignoredTags: List<String> = listOf("body", "html")) {
6363
/**
@@ -69,7 +69,7 @@ class AztecParser @JvmOverloads constructor(private val alignmentApproach: Align
6969
val tidySource = tidy(source)
7070

7171
val spanned = SpannableString(Html.fromHtml(tidySource,
72-
AztecTagHandler(context, plugins, alignmentApproach), context, plugins, ignoredTags, true))
72+
AztecTagHandler(context, plugins, alignmentRendering), context, plugins, ignoredTags, true))
7373

7474
postprocessSpans(spanned)
7575

@@ -83,7 +83,7 @@ class AztecParser @JvmOverloads constructor(private val alignmentApproach: Align
8383
val tidySource = if (shouldSkipTidying) source else tidy(source)
8484

8585
val spanned = SpannableStringBuilder(Html.fromHtml(tidySource,
86-
AztecTagHandler(context, plugins, alignmentApproach), context, plugins, ignoredTags, shouldIgnoreWhitespace))
86+
AztecTagHandler(context, plugins, alignmentRendering), context, plugins, ignoredTags, shouldIgnoreWhitespace))
8787

8888
addVisualNewlinesToBlockElements(spanned)
8989
markBlockElementsAsParagraphs(spanned)

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import org.wordpress.aztec.util.getLast
5151
import org.xml.sax.Attributes
5252
import java.util.ArrayList
5353

54-
class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = ArrayList(), private val alignmentApproach: AlignmentApproach
54+
class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = ArrayList(), private val alignmentRendering: AlignmentRendering
5555
) : Html.TagHandler {
5656
private val loadingDrawable: Drawable
5757

@@ -74,7 +74,7 @@ class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = Ar
7474

7575
when (tag.toLowerCase()) {
7676
LIST_LI -> {
77-
val span = createListItemSpan(nestingLevel, alignmentApproach, AztecAttributes(attributes))
77+
val span = createListItemSpan(nestingLevel, alignmentRendering, AztecAttributes(attributes))
7878
handleElement(output, opening, span)
7979
return true
8080
}
@@ -83,25 +83,25 @@ class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = Ar
8383
return true
8484
}
8585
SPAN -> {
86-
val span = createHiddenHtmlSpan(tag, AztecAttributes(attributes), nestingLevel, alignmentApproach)
86+
val span = createHiddenHtmlSpan(tag, AztecAttributes(attributes), nestingLevel, alignmentRendering)
8787
handleElement(output, opening, span)
8888
return true
8989
}
9090
DIV, FIGURE, FIGCAPTION, SECTION -> {
91-
val hiddenHtmlBlockSpan = createHiddenHtmlBlockSpan(tag, alignmentApproach, nestingLevel, AztecAttributes(attributes))
91+
val hiddenHtmlBlockSpan = createHiddenHtmlBlockSpan(tag, alignmentRendering, nestingLevel, AztecAttributes(attributes))
9292
handleElement(output, opening, hiddenHtmlBlockSpan)
9393
return true
9494
}
9595
LIST_UL -> {
96-
handleElement(output, opening, createUnorderedListSpan(nestingLevel, alignmentApproach, AztecAttributes(attributes)))
96+
handleElement(output, opening, createUnorderedListSpan(nestingLevel, alignmentRendering, AztecAttributes(attributes)))
9797
return true
9898
}
9999
LIST_OL -> {
100-
handleElement(output, opening, createOrderedListSpan(nestingLevel, alignmentApproach, AztecAttributes(attributes)))
100+
handleElement(output, opening, createOrderedListSpan(nestingLevel, alignmentRendering, AztecAttributes(attributes)))
101101
return true
102102
}
103103
BLOCKQUOTE -> {
104-
val span = createAztecQuoteSpan(nestingLevel, AztecAttributes(attributes), alignmentApproach)
104+
val span = createAztecQuoteSpan(nestingLevel, AztecAttributes(attributes), alignmentRendering)
105105
handleElement(output, opening, span)
106106
return true
107107
}
@@ -124,7 +124,7 @@ class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = Ar
124124
return true
125125
}
126126
PARAGRAPH -> {
127-
val paragraphSpan = createParagraphSpan(nestingLevel, alignmentApproach, AztecAttributes(attributes))
127+
val paragraphSpan = createParagraphSpan(nestingLevel, alignmentRendering, AztecAttributes(attributes))
128128
handleElement(output, opening, paragraphSpan)
129129
return true
130130
}
@@ -140,13 +140,13 @@ class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = Ar
140140
return true
141141
}
142142
PREFORMAT -> {
143-
val preformatSpan = createPreformatSpan(nestingLevel, alignmentApproach, AztecAttributes(attributes))
143+
val preformatSpan = createPreformatSpan(nestingLevel, alignmentRendering, AztecAttributes(attributes))
144144
handleElement(output, opening, preformatSpan)
145145
return true
146146
}
147147
else -> {
148148
if (tag.length == 2 && Character.toLowerCase(tag[0]) == 'h' && tag[1] >= '1' && tag[1] <= '6') {
149-
handleElement(output, opening, createHeadingSpan(nestingLevel, tag, AztecAttributes(attributes), alignmentApproach))
149+
handleElement(output, opening, createHeadingSpan(nestingLevel, tag, AztecAttributes(attributes), alignmentRendering))
150150
return true
151151
}
152152
}

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

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
152152

153153
val DEFAULT_IMAGE_WIDTH = 800
154154

155-
val DEFAULT_ALIGNMENT_APPROACH = AlignmentApproach.SPAN_LEVEL
155+
val DEFAULT_ALIGNMENT_RENDERING = AlignmentRendering.SPAN_LEVEL
156156

157157
var watchersNestingLevel: Int = 0
158158

@@ -251,7 +251,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
251251

252252
var isInCalypsoMode = true
253253
var isInGutenbergMode: Boolean = false
254-
val alignmentApproach: AlignmentApproach
254+
val alignmentRendering: AlignmentRendering
255255

256256
var consumeHistoryEvent: Boolean = false
257257

@@ -337,22 +337,22 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
337337
}
338338

339339
constructor(context: Context) : super(context) {
340-
alignmentApproach = DEFAULT_ALIGNMENT_APPROACH
340+
alignmentRendering = DEFAULT_ALIGNMENT_RENDERING
341341
init(null)
342342
}
343343

344-
constructor(context: Context, alignmentApproach: AlignmentApproach) : super(context) {
345-
this.alignmentApproach = alignmentApproach
344+
constructor(context: Context, alignmentRendering: AlignmentRendering) : super(context) {
345+
this.alignmentRendering = alignmentRendering
346346
init(null)
347347
}
348348

349349
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
350-
alignmentApproach = DEFAULT_ALIGNMENT_APPROACH
350+
alignmentRendering = DEFAULT_ALIGNMENT_RENDERING
351351
init(attrs)
352352
}
353353

354354
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
355-
alignmentApproach = DEFAULT_ALIGNMENT_APPROACH
355+
alignmentRendering = DEFAULT_ALIGNMENT_RENDERING
356356
init(attrs)
357357
}
358358

@@ -428,7 +428,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
428428
getPreformatBackgroundAlpha(styles),
429429
styles.getColor(R.styleable.AztecText_preformatColor, 0),
430430
verticalParagraphMargin),
431-
alignmentApproach
431+
alignmentRendering
432432
)
433433

434434
linkFormatter = LinkFormatter(this, LinkFormatter.LinkStyle(styles.getColor(
@@ -603,9 +603,9 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
603603
// will have the chance to run their "beforeTextChanged" and "onTextChanged" with the same string!
604604

605605
BlockElementWatcher(this)
606-
.add(HeadingHandler(alignmentApproach))
606+
.add(HeadingHandler(alignmentRendering))
607607
.add(ListHandler())
608-
.add(ListItemHandler(alignmentApproach))
608+
.add(ListItemHandler(alignmentRendering))
609609
.add(QuoteHandler())
610610
.add(PreformatHandler())
611611
.install(this)
@@ -1180,7 +1180,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
11801180

11811181
open fun fromHtml(source: String, isInit: Boolean = true) {
11821182
val builder = SpannableStringBuilder()
1183-
val parser = AztecParser(alignmentApproach, plugins)
1183+
val parser = AztecParser(alignmentRendering, plugins)
11841184

11851185
var cleanSource = CleaningUtils.cleanNestedBoldTags(source)
11861186
cleanSource = Format.removeSourceEditorFormatting(cleanSource, isInCalypsoMode, isInGutenbergMode)
@@ -1325,7 +1325,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
13251325
}
13261326

13271327
private fun parseHtml(content: Spannable, withCursorTag: Boolean): String {
1328-
val parser = AztecParser(alignmentApproach, plugins)
1328+
val parser = AztecParser(alignmentRendering, plugins)
13291329
val output: SpannableStringBuilder
13301330
try {
13311331
output = SpannableStringBuilder(content)
@@ -1571,7 +1571,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
15711571
// Convert selected text to html and add it to clipboard
15721572
fun copy(editable: Editable, start: Int, end: Int) {
15731573
val selectedText = editable.subSequence(start, end)
1574-
val parser = AztecParser(alignmentApproach, plugins)
1574+
val parser = AztecParser(alignmentRendering, plugins)
15751575
val output = SpannableStringBuilder(selectedText)
15761576

15771577
clearMetaSpans(output)
@@ -1637,7 +1637,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
16371637

16381638
if (clip.itemCount > 0) {
16391639
val textToPaste = if (asPlainText) clip.getItemAt(0).coerceToText(context).toString()
1640-
else clip.getItemAt(0).coerceToHtmlText(AztecParser(alignmentApproach, plugins))
1640+
else clip.getItemAt(0).coerceToHtmlText(AztecParser(alignmentRendering, plugins))
16411641

16421642
val oldHtml = toPlainHtml().replace("<aztec_cursor>", "")
16431643
val newHtml = oldHtml.replace(Constants.REPLACEMENT_MARKER_STRING, textToPaste + "<" + AztecCursorSpan.AZTEC_CURSOR_TAG + ">")
@@ -1755,7 +1755,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
17551755
val spanStart = text.getSpanStart(unknownHtmlSpan)
17561756

17571757
val textBuilder = SpannableStringBuilder()
1758-
textBuilder.append(AztecParser(alignmentApproach, plugins).fromHtml(source.getPureHtml(), context).trim())
1758+
textBuilder.append(AztecParser(alignmentRendering, plugins).fromHtml(source.getPureHtml(), context).trim())
17591759
setSelection(spanStart)
17601760

17611761
disableTextChangedListener()

0 commit comments

Comments
 (0)