Styler: do not style across multiple messages
This commit is contained in:
parent
c489b6a8eb
commit
a4b44ee730
|
@ -44,7 +44,7 @@ public class ImStyleParser {
|
||||||
return parse(text, 0, text.length() - 1);
|
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<>();
|
List<Style> styles = new ArrayList<>();
|
||||||
for (int i = start; i <= end; ++i) {
|
for (int i = start; i <= end; ++i) {
|
||||||
char c = text.charAt(i);
|
char c = text.charAt(i);
|
||||||
|
|
|
@ -45,6 +45,7 @@ import android.widget.EditText;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import eu.siacs.conversations.entities.Message;
|
||||||
import eu.siacs.conversations.ui.text.QuoteSpan;
|
import eu.siacs.conversations.ui.text.QuoteSpan;
|
||||||
|
|
||||||
public class StylingHelper {
|
public class StylingHelper {
|
||||||
|
@ -65,8 +66,8 @@ public class StylingHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void format(final Editable editable, @ColorInt int textColor) {
|
public static void format(final Editable editable, int start, int end, @ColorInt int textColor) {
|
||||||
for (ImStyleParser.Style style : ImStyleParser.parse(editable)) {
|
for (ImStyleParser.Style style : ImStyleParser.parse(editable,start,end)) {
|
||||||
final int keywordLength = style.getKeyword().length();
|
final int keywordLength = style.getKeyword().length();
|
||||||
editable.setSpan(createSpanForStyle(style), style.getStart() + keywordLength, style.getEnd() - keywordLength + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
editable.setSpan(createSpanForStyle(style), style.getStart() + keywordLength, style.getEnd() - keywordLength + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
makeKeywordOpaque(editable, style.getStart(), style.getStart() + keywordLength, textColor);
|
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) {
|
private static ParcelableSpan createSpanForStyle(ImStyleParser.Style style) {
|
||||||
switch (style.getKeyword()) {
|
switch (style.getKeyword()) {
|
||||||
case "*":
|
case "*":
|
||||||
|
|
Loading…
Reference in New Issue