diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index b4b74faa3..b6a8d3d39 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -411,6 +411,13 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie viewHolder.image.setVisibility(View.GONE); viewHolder.audioPlayer.setVisibility(View.GONE); viewHolder.messageBody.setVisibility(View.VISIBLE); + + viewHolder.messageBody.setTextColor(this.getMessageTextColor(darkBackground, true)); + viewHolder.messageBody.setLinkTextColor(this.getMessageTextColor(darkBackground, true)); + viewHolder.messageBody.setHighlightColor(ContextCompat.getColor(activity, darkBackground + ? (type == SENT || !mUseGreenBackground ? R.color.black26 : R.color.grey800) : R.color.grey500)); + viewHolder.messageBody.setTypeface(null, Typeface.NORMAL); + if (message.getBody() != null) { final String nick = UIHelper.getMessageDisplayName(message); SpannableStringBuilder body = message.getMergedBody(); @@ -477,7 +484,7 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie body.setSpan(new RelativeSizeSpan(1.2f), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } - StylingHelper.format(body, true); + StylingHelper.format(body, viewHolder.messageBody.getCurrentTextColor()); Linkify.addLinks(body, XMPP_PATTERN, "xmpp"); Linkify.addLinks(body, Patterns.AUTOLINK_WEB_URL, "http", WEBURL_MATCH_FILTER, WEBURL_TRANSFORM_FILTER); @@ -491,11 +498,6 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie viewHolder.messageBody.setText(""); viewHolder.messageBody.setTextIsSelectable(false); } - viewHolder.messageBody.setTextColor(this.getMessageTextColor(darkBackground, true)); - viewHolder.messageBody.setLinkTextColor(this.getMessageTextColor(darkBackground, true)); - viewHolder.messageBody.setHighlightColor(ContextCompat.getColor(activity, darkBackground - ? (type == SENT || !mUseGreenBackground ? R.color.black26 : R.color.grey800) : R.color.grey500)); - viewHolder.messageBody.setTypeface(null, Typeface.NORMAL); } private void displayDownloadableMessage(ViewHolder viewHolder, final Message message, String text) { diff --git a/src/main/java/eu/siacs/conversations/utils/StylingHelper.java b/src/main/java/eu/siacs/conversations/utils/StylingHelper.java index 5077a2c58..2e434cebe 100644 --- a/src/main/java/eu/siacs/conversations/utils/StylingHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/StylingHelper.java @@ -63,25 +63,17 @@ public class StylingHelper { } } - public static void format(final Editable editable) { - format(editable, false); - } - - public static void format(final Editable editable, final boolean replaceStyleAnnotation) { - for (ImStyleParser.Style style : ImStyleParser.parse(editable)) { - editable.setSpan(createSpanForStyle(style), style.getStart(), style.getEnd(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - if (replaceStyleAnnotation) { - editable.replace(style.getStart(), style.getStart() + 1, "\u200B"); - editable.replace(style.getEnd(), style.getEnd() + 1, "\u200B"); - } - } - } - public static void format(final Editable editable, @ColorInt int color) { + final int syntaxColor = Color.argb( + Math.round(Color.alpha(color) * 0.6f), + Color.red(color), + Color.green(color), + Color.blue(color) + ); for(ImStyleParser.Style style : ImStyleParser.parse(editable)) { editable.setSpan(createSpanForStyle(style), style.getStart() + 1, style.getEnd(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - editable.setSpan(new ForegroundColorSpan(color),style.getStart(),style.getStart()+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); - editable.setSpan(new ForegroundColorSpan(color),style.getEnd(),style.getEnd()+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + editable.setSpan(new ForegroundColorSpan(syntaxColor),style.getStart(),style.getStart()+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); + editable.setSpan(new ForegroundColorSpan(syntaxColor),style.getEnd(),style.getEnd()+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } @@ -121,14 +113,7 @@ public class StylingHelper { @Override public void afterTextChanged(Editable editable) { clear(editable); - final int color = mEditText.getCurrentTextColor(); - final int syntaxColor = Color.argb( - Math.round(Color.alpha(color) * 0.6f), - Color.red(color), - Color.green(color), - Color.blue(color) - ); - format(editable,syntaxColor); + format(editable,mEditText.getCurrentTextColor()); } } }