Skip to content

Commit c7ad53b

Browse files
authored
Merge pull request #384 from wordpress-mobile/issue/373-horizontal-rule-button
Issue/373 horizontal rule button
2 parents fd80b56 + aea1b7d commit c7ad53b

13 files changed

+108
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ class AztecParser {
415415
i = next
416416
}
417417

418-
if (span is AztecHorizontalLineSpan) {
418+
if (span is AztecHorizontalRuleSpan) {
419419
out.append("<${span.startTag}>")
420420
i = next
421421
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ class AztecTagHandler : Html.TagHandler {
9797
LINE -> {
9898
if (opening) {
9999
// Add an extra newline above the line to prevent weird typing on the line above
100-
start(output, AztecHorizontalLineSpan(context, ContextCompat.getDrawable(context, R.drawable.img_hr), nestingLevel))
100+
start(output, AztecHorizontalRuleSpan(context, ContextCompat.getDrawable(context, R.drawable.img_hr), nestingLevel))
101101

102102
output.append(Constants.MAGIC_CHAR)
103103
} else {
104-
end(output, AztecHorizontalLineSpan::class.java)
104+
end(output, AztecHorizontalRuleSpan::class.java)
105105
}
106106
return true
107107
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,7 @@ class AztecText : AppCompatAutoCompleteTextView, TextWatcher, UnknownHtmlSpan.On
579579
TextFormat.FORMAT_UNORDERED_LIST -> blockFormatter.toggleUnorderedList()
580580
TextFormat.FORMAT_ORDERED_LIST -> blockFormatter.toggleOrderedList()
581581
TextFormat.FORMAT_QUOTE -> blockFormatter.toggleQuote()
582+
TextFormat.FORMAT_HORIZONTAL_RULE -> lineBlockFormatter.applyHorizontalRule()
582583
TextFormat.FORMAT_MORE -> lineBlockFormatter.applyMoreComment()
583584
TextFormat.FORMAT_PAGE -> lineBlockFormatter.applyPageComment()
584585
TextFormat.FORMAT_CODE -> inlineFormatter.toggleCode()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ enum class TextFormat {
1818
FORMAT_STRIKETHROUGH,
1919
FORMAT_QUOTE,
2020
FORMAT_LINK,
21+
FORMAT_HORIZONTAL_RULE,
2122
FORMAT_MORE,
2223
FORMAT_PAGE,
2324
FORMAT_PARAGRAPH,

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,32 @@ class LineBlockFormatter(editor: AztecText) : AztecFormatter(editor) {
118118
if (selectionEnd < EndOfBufferMarkerAdder.safeLength(editor)) selectionEnd + 1 else selectionEnd)
119119
}
120120

121+
fun applyHorizontalRule() {
122+
editor.removeInlineStylesFromRange(selectionStart, selectionEnd)
123+
editor.removeBlockStylesFromRange(selectionStart, selectionEnd, true)
124+
125+
val nestingLevel = AztecNestable.getNestingLevelAt(editableText, selectionStart)
126+
127+
val span = AztecHorizontalRuleSpan(
128+
editor.context,
129+
ContextCompat.getDrawable(editor.context, R.drawable.img_hr),
130+
nestingLevel,
131+
editor
132+
)
133+
134+
val builder = SpannableStringBuilder(Constants.MAGIC_STRING)
135+
builder.setSpan(span, 0, 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE)
136+
137+
editableText.replace(selectionStart, selectionEnd, builder)
138+
139+
editor.setSelection(
140+
if (selectionEnd < EndOfBufferMarkerAdder.safeLength(editor)) {
141+
selectionEnd + 1
142+
} else {
143+
selectionEnd
144+
}
145+
)
146+
}
121147

122148
fun insertVideo(drawable: Drawable?, attributes: Attributes, onVideoTappedListener: OnVideoTappedListener?): AztecMediaSpan {
123149
val nestingLevel = AztecNestable.getNestingLevelAt(editableText, selectionStart)

aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecHorizontalLineSpan.kt renamed to aztec/src/main/kotlin/org/wordpress/aztec/spans/AztecHorizontalRuleSpan.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,15 @@ package org.wordpress.aztec.spans
33
import android.content.Context
44
import android.graphics.drawable.Drawable
55
import org.wordpress.aztec.AztecAttributes
6+
import org.wordpress.aztec.AztecText
67

7-
class AztecHorizontalLineSpan(context: Context, drawable: Drawable, override var nestingLevel: Int,
8-
override var attributes: AztecAttributes = AztecAttributes()) :
8+
class AztecHorizontalRuleSpan(context: Context, drawable: Drawable, override var nestingLevel: Int,
9+
editor: AztecText? = null, override var attributes: AztecAttributes = AztecAttributes()) :
910
AztecDynamicImageSpan(context, drawable), AztecFullWidthImageSpan, AztecSpan {
1011

12+
init {
13+
textView = editor
14+
}
15+
1116
override val TAG: String = "hr"
12-
}
17+
}

aztec/src/main/kotlin/org/wordpress/aztec/toolbar/ToolbarAction.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ enum class ToolbarAction constructor(val buttonId: Int, val actionType: ToolbarA
1717
UNDERLINE(R.id.format_bar_button_underline, ToolbarActionType.INLINE_STYLE, TextFormat.FORMAT_UNDERLINE),
1818
QUOTE(R.id.format_bar_button_quote, ToolbarActionType.BLOCK_STYLE, TextFormat.FORMAT_QUOTE),
1919
LINK(R.id.format_bar_button_link, ToolbarActionType.OTHER, TextFormat.FORMAT_LINK),
20+
HORIZONTAL_RULE(R.id.format_bar_button_horizontal_rule, ToolbarActionType.LINE_BLOCK, TextFormat.FORMAT_HORIZONTAL_RULE),
2021
MORE(R.id.format_bar_button_more, ToolbarActionType.LINE_BLOCK, TextFormat.FORMAT_MORE),
2122
PAGE(R.id.format_bar_button_page, ToolbarActionType.LINE_BLOCK, TextFormat.FORMAT_PAGE),
2223
HTML(R.id.format_bar_button_html, ToolbarActionType.OTHER, null);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<vector
4+
xmlns:android="http://schemas.android.com/apk/res/android"
5+
android:height="48dp"
6+
android:width="48dp"
7+
android:viewportHeight="48"
8+
android:viewportWidth="48" >
9+
10+
<!-- @color/grey_darken_20 -->
11+
<path
12+
android:fillColor="#ff4f748e"
13+
android:pathData="M14.2,22.9h19.6v2.2H14.2V22.9z" >
14+
</path>
15+
16+
</vector>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<vector
4+
xmlns:android="http://schemas.android.com/apk/res/android"
5+
android:height="48dp"
6+
android:width="48dp"
7+
android:viewportHeight="48"
8+
android:viewportWidth="48" >
9+
10+
<!-- @color/grey_lighten_20 -->
11+
<path
12+
android:fillColor="#ffc8d7e1"
13+
android:pathData="M14.2,22.9h19.6v2.2H14.2V22.9z" >
14+
</path>
15+
16+
</vector>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<vector
4+
xmlns:android="http://schemas.android.com/apk/res/android"
5+
android:height="48dp"
6+
android:width="48dp"
7+
android:viewportHeight="48"
8+
android:viewportWidth="48" >
9+
10+
<!-- @color/blue_wordpress -->
11+
<path
12+
android:fillColor="#ff0087be"
13+
android:pathData="M14.2,22.9h19.6v2.2H14.2V22.9z" >
14+
</path>
15+
16+
</vector>

0 commit comments

Comments
 (0)