aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2017-12-06 16:58:08 +0100
committerDaniel Gultsch <daniel@gultsch.de>2017-12-06 16:58:08 +0100
commita4b44ee73013781afe20c1585938496e32b72eca (patch)
treef44862f29460fb8c2bbb35531032a2df975a5ee0
parentc489b6a8ebf75862959a3b32fb50e7af84852c86 (diff)
Styler: do not style across multiple messages
-rw-r--r--src/main/java/eu/siacs/conversations/utils/ImStyleParser.java2
-rw-r--r--src/main/java/eu/siacs/conversations/utils/StylingHelper.java15
2 files changed, 14 insertions, 3 deletions
diff --git a/src/main/java/eu/siacs/conversations/utils/ImStyleParser.java b/src/main/java/eu/siacs/conversations/utils/ImStyleParser.java
index 4e43811..7521b0e 100644
--- a/src/main/java/eu/siacs/conversations/utils/ImStyleParser.java
+++ b/src/main/java/eu/siacs/conversations/utils/ImStyleParser.java
@@ -44,7 +44,7 @@ public class ImStyleParser {
return parse(text, 0, text.length() - 1);
}
- private static List<Style> parse(CharSequence text, int start, int end) {
+ public static List<Style> parse(CharSequence text, int start, int end) {
List<Style> styles = new ArrayList<>();
for (int i = start; i <= end; ++i) {
char c = text.charAt(i);
diff --git a/src/main/java/eu/siacs/conversations/utils/StylingHelper.java b/src/main/java/eu/siacs/conversations/utils/StylingHelper.java
index 6dbdee7..4548444 100644
--- a/src/main/java/eu/siacs/conversations/utils/StylingHelper.java
+++ b/src/main/java/eu/siacs/conversations/utils/StylingHelper.java
@@ -45,6 +45,7 @@ import android.widget.EditText;
import java.util.Arrays;
import java.util.List;
+import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.ui.text.QuoteSpan;
public class StylingHelper {
@@ -65,8 +66,8 @@ public class StylingHelper {
}
}
- public static void format(final Editable editable, @ColorInt int textColor) {
- for (ImStyleParser.Style style : ImStyleParser.parse(editable)) {
+ public static void format(final Editable editable, int start, int end, @ColorInt int textColor) {
+ for (ImStyleParser.Style style : ImStyleParser.parse(editable,start,end)) {
final int keywordLength = style.getKeyword().length();
editable.setSpan(createSpanForStyle(style), style.getStart() + keywordLength, style.getEnd() - keywordLength + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
makeKeywordOpaque(editable, style.getStart(), style.getStart() + keywordLength, textColor);
@@ -74,6 +75,16 @@ public class StylingHelper {
}
}
+ public static void format(final Editable editable, @ColorInt int textColor) {
+ int end = 0;
+ Message.MergeSeparator[] spans = editable.getSpans(0, editable.length() - 1, Message.MergeSeparator.class);
+ for(Message.MergeSeparator span : spans) {
+ format(editable,end,editable.getSpanStart(span),textColor);
+ end = editable.getSpanEnd(span);
+ }
+ format(editable,end,editable.length() -1,textColor);
+ }
+
private static ParcelableSpan createSpanForStyle(ImStyleParser.Style style) {
switch (style.getKeyword()) {
case "*":