use verified/error text colors for diff

This commit is contained in:
sk
2023-11-12 23:01:46 +01:00
parent 8a5b36db96
commit aa42873274
6 changed files with 20 additions and 10 deletions

View File

@@ -1601,7 +1601,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList
title.setText(item.parsedName); title.setText(item.parsedName);
value.setText(item.parsedValue); value.setText(item.parsedValue);
if(item.verifiedAt!=null){ if(item.verifiedAt!=null){
int textColor=UiUtils.isDarkTheme() ? 0xFF89bb9c : 0xFF5b8e63; int textColor=UiUtils.getThemeColor(getContext(), R.attr.colorM3Success);
value.setTextColor(textColor); value.setTextColor(textColor);
value.setLinkTextColor(textColor); value.setLinkTextColor(textColor);
Drawable check=getResources().getDrawable(R.drawable.ic_fluent_checkmark_starburst_20_regular, getActivity().getTheme()).mutate(); Drawable check=getResources().getDrawable(R.drawable.ic_fluent_checkmark_starburst_20_regular, getActivity().getTheme()).mutate();

View File

@@ -250,9 +250,9 @@ public abstract class StatusDisplayItem{
boolean hasSpoiler=!TextUtils.isEmpty(statusForContent.spoilerText); boolean hasSpoiler=!TextUtils.isEmpty(statusForContent.spoilerText);
if(!TextUtils.isEmpty(statusForContent.content)){ if(!TextUtils.isEmpty(statusForContent.content)){
SpannableStringBuilder parsedText=HtmlParser.parse(statusForContent.content, statusForContent.emojis, statusForContent.mentions, statusForContent.tags, accountID); SpannableStringBuilder parsedText=HtmlParser.parse(statusForContent.content, statusForContent.emojis, statusForContent.mentions, statusForContent.tags, accountID, fragment.getContext());
HtmlParser.applyFilterHighlights(fragment.getActivity(), parsedText, status.filtered); HtmlParser.applyFilterHighlights(fragment.getActivity(), parsedText, status.filtered);
TextStatusDisplayItem text=new TextStatusDisplayItem(parentID, HtmlParser.parse(statusForContent.content, statusForContent.emojis, statusForContent.mentions, statusForContent.tags, accountID), fragment, statusForContent, (flags & FLAG_NO_TRANSLATE) != 0); TextStatusDisplayItem text=new TextStatusDisplayItem(parentID, HtmlParser.parse(statusForContent.content, statusForContent.emojis, statusForContent.mentions, statusForContent.tags, accountID, fragment.getContext()), fragment, statusForContent, (flags & FLAG_NO_TRANSLATE) != 0);
contentItems.add(text); contentItems.add(text);
}else if(!hasSpoiler && header!=null){ }else if(!hasSpoiler && header!=null){
header.needBottomPadding=true; header.needBottomPadding=true;

View File

@@ -3,21 +3,21 @@ package org.joinmastodon.android.ui.text;
import android.text.TextPaint; import android.text.TextPaint;
import android.text.style.CharacterStyle; import android.text.style.CharacterStyle;
import org.joinmastodon.android.ui.utils.UiUtils;
public class DiffRemovedSpan extends CharacterStyle { public class DiffRemovedSpan extends CharacterStyle {
private final String text; private final String text;
private final int color;
public DiffRemovedSpan(String text){ public DiffRemovedSpan(String text, int color){
this.text=text; this.text=text;
this.color=color;
} }
@Override @Override
public void updateDrawState(TextPaint tp) { public void updateDrawState(TextPaint tp) {
tp.setStrikeThruText(true); tp.setStrikeThruText(true);
tp.setColor(0xFFCA5B63); tp.setColor(color);
} }
public String getText() { public String getText() {

View File

@@ -70,6 +70,10 @@ public class HtmlParser{
private HtmlParser(){} private HtmlParser(){}
public static SpannableStringBuilder parse(String source, List<Emoji> emojis, List<Mention> mentions, List<Hashtag> tags, String accountID){
return parse(source, emojis, mentions, tags, accountID, null);
}
/** /**
* Parse HTML and custom emoji into a spanned string for display. * Parse HTML and custom emoji into a spanned string for display.
* Supported tags: <ul> * Supported tags: <ul>
@@ -82,7 +86,7 @@ public class HtmlParser{
* @param emojis Custom emojis that are present in source as <code>:code:</code> * @param emojis Custom emojis that are present in source as <code>:code:</code>
* @return a spanned string * @return a spanned string
*/ */
public static SpannableStringBuilder parse(String source, List<Emoji> emojis, List<Mention> mentions, List<Hashtag> tags, String accountID){ public static SpannableStringBuilder parse(String source, List<Emoji> emojis, List<Mention> mentions, List<Hashtag> tags, String accountID, Context context){
class SpanInfo{ class SpanInfo{
public Object span; public Object span;
public int start; public int start;
@@ -107,6 +111,9 @@ public class HtmlParser{
Map<String, Hashtag> tagsByTag=tags.stream().distinct().collect(Collectors.toMap(t->t.name.toLowerCase(), Function.identity())); Map<String, Hashtag> tagsByTag=tags.stream().distinct().collect(Collectors.toMap(t->t.name.toLowerCase(), Function.identity()));
final SpannableStringBuilder ssb=new SpannableStringBuilder(); final SpannableStringBuilder ssb=new SpannableStringBuilder();
int colorInsert=UiUtils.getThemeColor(context, R.attr.colorM3Success);
int colorDelete=UiUtils.getThemeColor(context, R.attr.colorM3Error);
Jsoup.parseBodyFragment(source).body().traverse(new NodeVisitor(){ Jsoup.parseBodyFragment(source).body().traverse(new NodeVisitor(){
private final ArrayList<SpanInfo> openSpans=new ArrayList<>(); private final ArrayList<SpanInfo> openSpans=new ArrayList<>();
@@ -173,8 +180,8 @@ public class HtmlParser{
case "code", "pre" -> openSpans.add(new SpanInfo(new TypefaceSpan("monospace"), ssb.length(), el)); case "code", "pre" -> openSpans.add(new SpanInfo(new TypefaceSpan("monospace"), ssb.length(), el));
case "blockquote" -> openSpans.add(new SpanInfo(new LeadingMarginSpan.Standard(V.dp(10)), ssb.length(), el)); case "blockquote" -> openSpans.add(new SpanInfo(new LeadingMarginSpan.Standard(V.dp(10)), ssb.length(), el));
// fake elements for the edit history diff view // fake elements for the edit history diff view
case "edit-diff-insert" -> openSpans.add(new SpanInfo(new ForegroundColorSpan(UiUtils.isDarkTheme() ? 0xFF89bb9c : 0xFF5b8e63), ssb.length(), el)); case "edit-diff-insert" -> openSpans.add(new SpanInfo(new ForegroundColorSpan(colorInsert), ssb.length(), el));
case "edit-diff-delete" -> openSpans.add(new SpanInfo(new DiffRemovedSpan(el.text()), ssb.length(), el)); case "edit-diff-delete" -> openSpans.add(new SpanInfo(new DiffRemovedSpan(el.text(), colorDelete), ssb.length(), el));
} }
} }
} }

View File

@@ -37,6 +37,7 @@
<attr name="colorM3DarkOnSurface" format="color" /> <attr name="colorM3DarkOnSurface" format="color" />
<attr name="colorTabBarAlpha" format="color" /> <attr name="colorTabBarAlpha" format="color" />
<attr name="colorFilledCardAlpha" format="color" /> <attr name="colorFilledCardAlpha" format="color" />
<attr name="colorM3Success" format="color" />
<attr name="toolbarActionButtonStyle" format="reference" /> <attr name="toolbarActionButtonStyle" format="reference" />
<attr name="colorPrimary25" format="color" /> <attr name="colorPrimary25" format="color" />

View File

@@ -59,6 +59,7 @@
<item name="colorPoll">@color/bookmark_selected</item> <item name="colorPoll">@color/bookmark_selected</item>
<item name="colorTabBarAlpha">#14000000</item> <item name="colorTabBarAlpha">#14000000</item>
<item name="colorFilledCardAlpha">#22000000</item> <item name="colorFilledCardAlpha">#22000000</item>
<item name="colorM3Success">#FF5b8e63</item>
<item name="colorM3DisabledBackground">#1F1F1F1F</item> <item name="colorM3DisabledBackground">#1F1F1F1F</item>
<item name="colorM3Error">#B3261E</item> <item name="colorM3Error">#B3261E</item>
@@ -143,6 +144,7 @@
<item name="colorM3OnErrorContainer">#F9DEDC</item> <item name="colorM3OnErrorContainer">#F9DEDC</item>
<item name="colorWhite">#000</item> <item name="colorWhite">#000</item>
<item name="colorSensitiveOverlay">#80000000</item> <item name="colorSensitiveOverlay">#80000000</item>
<item name="colorM3Success">#FF89bb9c</item>
</style> </style>
<style name="ColorPalette.Dark.TrueBlack"> <style name="ColorPalette.Dark.TrueBlack">