Skip to content

Commit d697b0b

Browse files
committed
Use AlignmentApproach with AztecQuoteSpan
1 parent b996947 commit d697b0b

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ import org.wordpress.aztec.spans.AztecVideoSpan
4242
import org.wordpress.aztec.spans.HiddenHtmlSpan
4343
import org.wordpress.aztec.spans.IAztecAttributedSpan
4444
import org.wordpress.aztec.spans.IAztecNestable
45+
import org.wordpress.aztec.spans.createAztecQuoteSpan
4546
import org.wordpress.aztec.spans.createHeadingSpan
4647
import org.wordpress.aztec.spans.createHiddenHtmlBlockSpan
4748
import org.wordpress.aztec.spans.createParagraphSpan
@@ -98,7 +99,8 @@ class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = Ar
9899
return true
99100
}
100101
BLOCKQUOTE -> {
101-
handleElement(output, opening, AztecQuoteSpan(nestingLevel, AztecAttributes(attributes)))
102+
val span = createAztecQuoteSpan(nestingLevel, AztecAttributes(attributes), alignmentApproach)
103+
handleElement(output, opening, span)
102104
return true
103105
}
104106
IMAGE -> {

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.wordpress.aztec.spans.IAztecCompositeBlockSpan
2727
import org.wordpress.aztec.spans.IAztecLineBlockSpan
2828
import org.wordpress.aztec.spans.IAztecNestable
2929
import org.wordpress.aztec.spans.ParagraphSpan
30+
import org.wordpress.aztec.spans.createAztecQuoteSpan
3031
import org.wordpress.aztec.spans.createHeadingSpan
3132
import org.wordpress.aztec.spans.createParagraphSpan
3233
import org.wordpress.aztec.spans.createPreformatSpan
@@ -295,7 +296,7 @@ class BlockFormatter(editor: AztecText,
295296
when (textFormat) {
296297
AztecTextFormat.FORMAT_ORDERED_LIST -> return Arrays.asList(AztecOrderedListSpan(nestingLevel, attrs, listStyle), AztecListItemSpan(nestingLevel + 1))
297298
AztecTextFormat.FORMAT_UNORDERED_LIST -> return Arrays.asList(AztecUnorderedListSpan(nestingLevel, attrs, listStyle), AztecListItemSpan(nestingLevel + 1))
298-
AztecTextFormat.FORMAT_QUOTE -> return Arrays.asList(AztecQuoteSpan(nestingLevel, attrs, quoteStyle))
299+
AztecTextFormat.FORMAT_QUOTE -> return Arrays.asList(createAztecQuoteSpan(nestingLevel, attrs, alignmentApproach, quoteStyle))
299300
AztecTextFormat.FORMAT_HEADING_1,
300301
AztecTextFormat.FORMAT_HEADING_2,
301302
AztecTextFormat.FORMAT_HEADING_3,
@@ -341,7 +342,7 @@ class BlockFormatter(editor: AztecText,
341342
typeIsAssignableTo(AztecOrderedListSpan::class) -> AztecOrderedListSpan(nestingLevel, attrs, listStyle)
342343
typeIsAssignableTo(AztecUnorderedListSpan::class) -> AztecUnorderedListSpan(nestingLevel, attrs, listStyle)
343344
typeIsAssignableTo(AztecListItemSpan::class) -> AztecListItemSpan(nestingLevel, attrs)
344-
typeIsAssignableTo(AztecQuoteSpan::class) -> AztecQuoteSpan(nestingLevel, attrs, quoteStyle)
345+
typeIsAssignableTo(AztecQuoteSpan::class) -> createAztecQuoteSpan(nestingLevel, attrs, alignmentApproach, quoteStyle)
345346
typeIsAssignableTo(AztecHeadingSpan::class) -> createHeadingSpan(nestingLevel, textFormat, attrs, alignmentApproach, headerStyle)
346347
typeIsAssignableTo(AztecPreformatSpan::class) -> createPreformatSpan(nestingLevel, alignmentApproach, attrs, preformatStyle)
347348
else -> createParagraphSpan(nestingLevel, alignmentApproach, attrs)

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,42 @@ import android.text.style.LineHeightSpan
3333
import android.text.style.QuoteSpan
3434
import android.text.style.UpdateLayout
3535
import androidx.collection.ArrayMap
36+
import org.wordpress.aztec.AlignmentApproach
3637
import org.wordpress.aztec.AztecAttributes
3738
import org.wordpress.aztec.formatting.BlockFormatter
3839
import java.util.Locale
3940

40-
class AztecQuoteSpan(
41+
fun createAztecQuoteSpan(
42+
nestingLevel: Int,
43+
attributes: AztecAttributes = AztecAttributes(),
44+
alignmentApproach: AlignmentApproach,
45+
quoteStyle: BlockFormatter.QuoteStyle = BlockFormatter.QuoteStyle(0, 0, 0f, 0, 0, 0, 0)
46+
) = when (alignmentApproach) {
47+
AlignmentApproach.SPAN_LEVEL -> AztecQuoteSpanAligned(nestingLevel, attributes, quoteStyle, null)
48+
AlignmentApproach.VIEW_LEVEL -> AztecQuoteSpan(nestingLevel, attributes, quoteStyle)
49+
}
50+
51+
/**
52+
* We need to have two classes for handling alignment at either the Span-level (AztecQuoteSpanAligned)
53+
* or the View-level (AztecQuoteSpan). IAztecAlignment implements AlignmentSpan, which has a
54+
* getAlignment method that returns a non-null Layout.Alignment. The Android system checks for
55+
* AlignmentSpans and, if present, overrides the view's gravity with their value. Having a class
56+
* that does not implement AlignmentSpan allows the view's gravity to control. These classes should
57+
* be created using the createAztecQuoteSpan(...) methods.
58+
*/
59+
class AztecQuoteSpanAligned(
60+
nestingLevel: Int,
61+
attributes: AztecAttributes,
62+
quoteStyle: BlockFormatter.QuoteStyle,
63+
override var align: Layout.Alignment?
64+
) : AztecQuoteSpan(nestingLevel, attributes, quoteStyle), IAztecAlignmentSpan
65+
66+
open class AztecQuoteSpan(
4167
override var nestingLevel: Int,
42-
override var attributes: AztecAttributes = AztecAttributes(),
43-
var quoteStyle: BlockFormatter.QuoteStyle = BlockFormatter.QuoteStyle(0, 0, 0f, 0, 0, 0, 0),
44-
override var align: Layout.Alignment? = null
68+
override var attributes: AztecAttributes,
69+
var quoteStyle: BlockFormatter.QuoteStyle
4570
) : QuoteSpan(),
4671
LineBackgroundSpan,
47-
IAztecAlignmentSpan,
4872
IAztecBlockSpan,
4973
LineHeightSpan,
5074
UpdateLayout

0 commit comments

Comments
 (0)