Styler: do not style across multiple messages
This commit is contained in:
parent
0aa694b7a2
commit
86bd13da67
2 changed files with 14 additions and 3 deletions
|
@ -43,7 +43,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);
|
||||
|
|
|
@ -45,6 +45,7 @@ import android.widget.EditText;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import de.pixart.messenger.entities.Message;
|
||||
import de.pixart.messenger.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 "*":
|
||||
|
|
Reference in a new issue