Skip to content

Commit 90fd525

Browse files
committed
Add Redacted inline formatting action
- New AztecRedactedSpan combining red background + strikethrough - Toolbar button with redacted icon added after strikethrough - HTML round-trips as <span class="redacted"> - Wired into InlineFormatter, AztecText, AztecTagHandler - Added to demo app toolbar layout
1 parent 6cc4b6c commit 90fd525

File tree

14 files changed

+119
-1
lines changed

14 files changed

+119
-1
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,7 @@ open class MainActivity : AppCompatActivity(),
475475
ToolbarAction.LINK,
476476
ToolbarAction.UNDERLINE,
477477
ToolbarAction.STRIKETHROUGH,
478+
ToolbarAction.REDACTED,
478479
ToolbarAction.ALIGN_LEFT,
479480
ToolbarAction.ALIGN_CENTER,
480481
ToolbarAction.ALIGN_RIGHT,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import org.wordpress.aztec.plugins.html2visual.IHtmlTagHandler
3131
import org.wordpress.aztec.source.CssStyleFormatter
3232
import org.wordpress.aztec.spans.AztecAudioSpan
3333
import org.wordpress.aztec.spans.AztecBackgroundColorSpan
34+
import org.wordpress.aztec.spans.AztecRedactedSpan
3435
import org.wordpress.aztec.spans.AztecHorizontalRuleSpan
3536
import org.wordpress.aztec.spans.AztecImageSpan
3637
import org.wordpress.aztec.spans.AztecListItemSpan
@@ -176,6 +177,10 @@ class AztecTagHandler(val context: Context, val plugins: List<IAztecPlugin> = Ar
176177

177178
private fun handleBackgroundColorSpanTag(attributes: Attributes, tag: String, nestingLevel: Int): IAztecSpan {
178179
val attrs = AztecAttributes(attributes)
180+
val classAttr = attrs.getValue("class") ?: ""
181+
if (classAttr.contains("redacted") || (tagStack.isNotEmpty() && tagStack.last() is AztecRedactedSpan)) {
182+
return AztecRedactedSpan(attrs)
183+
}
179184
return if (CssStyleFormatter.containsStyleAttribute(
180185
attrs,
181186
CssStyleFormatter.CSS_BACKGROUND_COLOR_ATTRIBUTE

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,6 +1441,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
14411441
AztecTextFormat.FORMAT_CITE,
14421442
AztecTextFormat.FORMAT_UNDERLINE,
14431443
AztecTextFormat.FORMAT_STRIKETHROUGH,
1444+
AztecTextFormat.FORMAT_REDACTED,
14441445
AztecTextFormat.FORMAT_BACKGROUND,
14451446
AztecTextFormat.FORMAT_HIGHLIGHT,
14461447
AztecTextFormat.FORMAT_CODE -> inlineFormatter.toggle(textFormat)
@@ -1483,6 +1484,7 @@ open class AztecText : AppCompatEditText, TextWatcher, UnknownHtmlSpan.OnUnknown
14831484
AztecTextFormat.FORMAT_CITE,
14841485
AztecTextFormat.FORMAT_UNDERLINE,
14851486
AztecTextFormat.FORMAT_STRIKETHROUGH,
1487+
AztecTextFormat.FORMAT_REDACTED,
14861488
AztecTextFormat.FORMAT_BACKGROUND,
14871489
AztecTextFormat.FORMAT_MARK,
14881490
AztecTextFormat.FORMAT_HIGHLIGHT,

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,6 @@ enum class AztecTextFormat : ITextFormat {
3838
FORMAT_CODE,
3939
FORMAT_BACKGROUND,
4040
FORMAT_MARK,
41-
FORMAT_HIGHLIGHT
41+
FORMAT_HIGHLIGHT,
42+
FORMAT_REDACTED
4243
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import org.wordpress.aztec.spans.AztecUnderlineSpan
2727
import org.wordpress.aztec.spans.HighlightSpan
2828
import org.wordpress.aztec.spans.IAztecExclusiveInlineSpan
2929
import org.wordpress.aztec.spans.IAztecInlineSpan
30+
import org.wordpress.aztec.spans.AztecRedactedSpan
3031
import org.wordpress.aztec.spans.MarkSpan
3132
import org.wordpress.aztec.watchers.TextChangedEvent
3233

@@ -99,6 +100,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h
99100
AztecTextFormat.FORMAT_EMPHASIS,
100101
AztecTextFormat.FORMAT_CITE,
101102
AztecTextFormat.FORMAT_STRIKETHROUGH,
103+
AztecTextFormat.FORMAT_REDACTED,
102104
AztecTextFormat.FORMAT_BACKGROUND,
103105
AztecTextFormat.FORMAT_UNDERLINE,
104106
AztecTextFormat.FORMAT_CODE -> {
@@ -321,6 +323,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h
321323
AztecStyleEmphasisSpan::class.java -> AztecTextFormat.FORMAT_EMPHASIS
322324
AztecStyleCiteSpan::class.java -> AztecTextFormat.FORMAT_CITE
323325
AztecStrikethroughSpan::class.java -> AztecTextFormat.FORMAT_STRIKETHROUGH
326+
AztecRedactedSpan::class.java -> AztecTextFormat.FORMAT_REDACTED
324327
AztecUnderlineSpan::class.java -> AztecTextFormat.FORMAT_UNDERLINE
325328
AztecCodeSpan::class.java -> AztecTextFormat.FORMAT_CODE
326329
AztecBackgroundColorSpan::class.java -> return AztecTextFormat.FORMAT_BACKGROUND
@@ -475,6 +478,7 @@ class InlineFormatter(editor: AztecText, val codeStyle: CodeStyle, private val h
475478
AztecTextFormat.FORMAT_EMPHASIS -> AztecStyleEmphasisSpan()
476479
AztecTextFormat.FORMAT_CITE -> AztecStyleCiteSpan()
477480
AztecTextFormat.FORMAT_STRIKETHROUGH -> AztecStrikethroughSpan()
481+
AztecTextFormat.FORMAT_REDACTED -> AztecRedactedSpan()
478482
AztecTextFormat.FORMAT_UNDERLINE -> AztecUnderlineSpan()
479483
AztecTextFormat.FORMAT_CODE -> AztecCodeSpan(codeStyle)
480484
AztecTextFormat.FORMAT_BACKGROUND -> AztecBackgroundColorSpan(backgroundSpanColor ?: R.color.background)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package org.wordpress.aztec.spans
2+
3+
import android.graphics.Color
4+
import android.text.TextPaint
5+
import android.text.style.CharacterStyle
6+
import org.wordpress.aztec.AztecAttributes
7+
8+
class AztecRedactedSpan(
9+
override var attributes: AztecAttributes = AztecAttributes()
10+
) : CharacterStyle(), IAztecInlineSpan {
11+
12+
override val TAG = "span"
13+
14+
override fun updateDrawState(tp: TextPaint) {
15+
tp.bgColor = Color.RED
16+
tp.isStrikeThruText = true
17+
}
18+
19+
init {
20+
attributes.setValue("class", "redacted")
21+
}
22+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ enum class ToolbarAction constructor(
9797
ToolbarActionType.INLINE_STYLE,
9898
setOf(AztecTextFormat.FORMAT_STRIKETHROUGH),
9999
R.layout.format_bar_button_strikethrough),
100+
REDACTED(
101+
R.id.format_bar_button_redacted,
102+
R.drawable.format_bar_button_redacted_selector,
103+
ToolbarActionType.INLINE_STYLE,
104+
setOf(AztecTextFormat.FORMAT_REDACTED),
105+
R.layout.format_bar_button_redacted),
100106
ALIGN_LEFT(R.id.format_bar_button_align_left,
101107
R.drawable.format_bar_button_align_left_selector,
102108
ToolbarActionType.BLOCK_STYLE,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ sealed class ToolbarItems {
6060
ToolbarAction.LINK,
6161
ToolbarAction.UNDERLINE,
6262
ToolbarAction.STRIKETHROUGH,
63+
ToolbarAction.REDACTED,
6364
ToolbarAction.ALIGN_LEFT,
6465
ToolbarAction.ALIGN_CENTER,
6566
ToolbarAction.ALIGN_RIGHT,
@@ -76,6 +77,7 @@ sealed class ToolbarItems {
7677
ToolbarAction.LINK,
7778
ToolbarAction.UNDERLINE,
7879
ToolbarAction.STRIKETHROUGH,
80+
ToolbarAction.REDACTED,
7981
ToolbarAction.ALIGN_LEFT,
8082
ToolbarAction.ALIGN_CENTER,
8183
ToolbarAction.ALIGN_RIGHT,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
<path
11+
android:fillColor="?attr/toolbarIconNormalColor"
12+
android:pathData="M14,20h20v8H14V20z" />
13+
14+
<path
15+
android:strokeColor="?attr/toolbarIconNormalColor"
16+
android:strokeWidth="2"
17+
android:pathData="M10,24L38,24" />
18+
19+
</vector>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
<path
11+
android:fillColor="?attr/toolbarIconDisabledColor"
12+
android:pathData="M14,20h20v8H14V20z" />
13+
14+
<path
15+
android:strokeColor="?attr/toolbarIconDisabledColor"
16+
android:strokeWidth="2"
17+
android:pathData="M10,24L38,24" />
18+
19+
</vector>

0 commit comments

Comments
 (0)