From 06d63aec7c3bef88b63a6b1f0842590bf35b92fc Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 22 Sep 2023 20:26:14 +0200 Subject: [PATCH] Add context --- .../eu/faircode/email/AdapterMessage.java | 2 +- .../eu/faircode/email/FragmentCompose.java | 2 +- .../java/eu/faircode/email/HtmlHelper.java | 20 +++++++++---------- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 1e50d2bed6..ece81b3514 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -7391,7 +7391,7 @@ public class AdapterMessage extends RecyclerView.Adapter sheets = HtmlHelper.parseStyles(d.head().select("style")); for (Element element : d.select("*")) { - String computed = HtmlHelper.processStyles( + String computed = HtmlHelper.processStyles(context, element.tagName(), element.className(), element.attr("style"), diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 67f9d9d8fc..cabac89c85 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -5858,7 +5858,7 @@ public class FragmentCompose extends FragmentBase { for (Element element : e.select("*")) { String tag = element.tagName(); String clazz = element.attr("class"); - String style = HtmlHelper.processStyles(tag, clazz, null, sheets); + String style = HtmlHelper.processStyles(context, tag, clazz, null, sheets); style = HtmlHelper.mergeStyles(style, element.attr("style")); if (!TextUtils.isEmpty(style)) element.attr("style", style); diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index abcfa4a290..505714daef 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -663,7 +663,7 @@ public class HtmlHelper { // Class style String tag = element.tagName(); String clazz = element.className(); - String style = processStyles(tag, clazz, null, sheets); + String style = processStyles(context, tag, clazz, null, sheets); // Element style style = mergeStyles(style, element.attr("style")); @@ -1780,17 +1780,17 @@ public class HtmlHelper { return sheets; } - static String processStyles(String tag, String clazz, String style, List sheets) { + static String processStyles(Context context, String tag, String clazz, String style, List sheets) { for (CSSStyleSheet sheet : sheets) - if (isScreenMedia(sheet.getMedia())) { - style = processStyles(null, clazz, style, sheet.getCssRules(), Selector.SAC_ELEMENT_NODE_SELECTOR); - style = processStyles(tag, clazz, style, sheet.getCssRules(), Selector.SAC_ELEMENT_NODE_SELECTOR); - style = processStyles(tag, clazz, style, sheet.getCssRules(), Selector.SAC_CONDITIONAL_SELECTOR); + if (isScreenMedia(context, sheet.getMedia())) { + style = processStyles(context, null, clazz, style, sheet.getCssRules(), Selector.SAC_ELEMENT_NODE_SELECTOR); + style = processStyles(context, tag, clazz, style, sheet.getCssRules(), Selector.SAC_ELEMENT_NODE_SELECTOR); + style = processStyles(context, tag, clazz, style, sheet.getCssRules(), Selector.SAC_CONDITIONAL_SELECTOR); } return style; } - private static String processStyles(String tag, String clazz, String style, CSSRuleList rules, int stype) { + private static String processStyles(Context context, String tag, String clazz, String style, CSSRuleList rules, int stype) { for (int i = 0; rules != null && i < rules.getLength(); i++) { CSSRule rule = rules.item(i); switch (rule.getType()) { @@ -1829,15 +1829,15 @@ public class HtmlHelper { case CSSRule.MEDIA_RULE: CSSMediaRuleImpl mrule = (CSSMediaRuleImpl) rule; - if (isScreenMedia(mrule.getMedia())) - style = processStyles(tag, clazz, style, mrule.getCssRules(), stype); + if (isScreenMedia(context, mrule.getMedia())) + style = processStyles(context, tag, clazz, style, mrule.getCssRules(), stype); break; } } return style; } - private static boolean isScreenMedia(MediaList media) { + private static boolean isScreenMedia(Context context, MediaList media) { // https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries // https://developers.google.com/gmail/design/reference/supported_css#supported_types if (media instanceof MediaListImpl) {