Styler: do not style across multiple messages

This commit is contained in:
Daniel Gultsch 2017-12-06 16:58:08 +01:00
parent c489b6a8eb
commit a4b44ee730
2 changed files with 14 additions and 3 deletions

View File

@ -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);

View File

@ -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 "*":