From 82173bfe062423106bbf25101f772351f1a8d24f Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 8 Nov 2020 21:09:31 +0100 Subject: [PATCH] Cleanup --- .../java/eu/faircode/email/ActivityEML.java | 2 +- .../eu/faircode/email/ActivitySignature.java | 2 +- .../eu/faircode/email/AdapterMessage.java | 2 +- app/src/main/java/eu/faircode/email/Core.java | 4 +-- .../eu/faircode/email/EditTextCompose.java | 2 +- .../eu/faircode/email/FragmentAccount.java | 2 +- .../eu/faircode/email/FragmentAnswer.java | 4 +-- .../eu/faircode/email/FragmentCompose.java | 10 +++--- .../eu/faircode/email/FragmentIdentity.java | 2 +- .../eu/faircode/email/FragmentQuickSetup.java | 2 +- .../java/eu/faircode/email/HtmlHelper.java | 31 ++++--------------- 11 files changed, 22 insertions(+), 41 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityEML.java b/app/src/main/java/eu/faircode/email/ActivityEML.java index 20ea41de52..7feaa0bff8 100644 --- a/app/src/main/java/eu/faircode/email/ActivityEML.java +++ b/app/src/main/java/eu/faircode/email/ActivityEML.java @@ -179,7 +179,7 @@ public class ActivityEML extends ActivityBase { if (html != null) { Document parsed = JsoupEx.parse(html); Document document = HtmlHelper.sanitizeView(context, parsed, false); - result.body = HtmlHelper.fromDocument(context, document, true, null, null); + result.body = HtmlHelper.fromDocument(context, document, null, null); } return result; diff --git a/app/src/main/java/eu/faircode/email/ActivitySignature.java b/app/src/main/java/eu/faircode/email/ActivitySignature.java index 8ef33b5d0c..3451a8cd35 100644 --- a/app/src/main/java/eu/faircode/email/ActivitySignature.java +++ b/app/src/main/java/eu/faircode/email/ActivitySignature.java @@ -190,7 +190,7 @@ public class ActivitySignature extends ActivityBase { else if (etText.getRaw()) etText.setText(html); else - etText.setText(HtmlHelper.fromHtml(html, false, new Html.ImageGetter() { + etText.setText(HtmlHelper.fromHtml(html, new Html.ImageGetter() { @Override public Drawable getDrawable(String source) { return ImageHelper.decodeImage(ActivitySignature.this, -1, source, true, 0, 1.0f, etText); diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index 1d45658e86..0955c3e14c 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -2199,7 +2199,7 @@ public class AdapterMessage extends RecyclerView.Adapter 0) { NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle() - .bigText(HtmlHelper.fromHtml(sbm.toString(), true, context)); + .bigText(HtmlHelper.fromHtml(sbm.toString(), context)); if (!TextUtils.isEmpty(message.subject)) bigText.setSummaryText(message.subject); diff --git a/app/src/main/java/eu/faircode/email/EditTextCompose.java b/app/src/main/java/eu/faircode/email/EditTextCompose.java index cad2e22cc2..4f2a985c19 100644 --- a/app/src/main/java/eu/faircode/email/EditTextCompose.java +++ b/app/src/main/java/eu/faircode/email/EditTextCompose.java @@ -135,7 +135,7 @@ public class EditTextCompose extends FixedEditText { ssb = new SpannableStringBuilder(html); else { Document document = HtmlHelper.sanitizeCompose(context, html, false); - Spanned paste = HtmlHelper.fromDocument(context, document, true, new Html.ImageGetter() { + Spanned paste = HtmlHelper.fromDocument(context, document, new Html.ImageGetter() { @Override public Drawable getDrawable(String source) { return ImageHelper.decodeImage(context, diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index 18fe897a40..65f5349b02 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -1333,7 +1333,7 @@ public class FragmentAccount extends FragmentBase { btnSupport.setVisibility(View.VISIBLE); if (provider != null && provider.documentation != null) { - tvInstructions.setText(HtmlHelper.fromHtml(provider.documentation.toString(), true, getContext())); + tvInstructions.setText(HtmlHelper.fromHtml(provider.documentation.toString(), getContext())); tvInstructions.setVisibility(View.VISIBLE); } diff --git a/app/src/main/java/eu/faircode/email/FragmentAnswer.java b/app/src/main/java/eu/faircode/email/FragmentAnswer.java index 76bf734050..789d42c49d 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAnswer.java +++ b/app/src/main/java/eu/faircode/email/FragmentAnswer.java @@ -186,7 +186,7 @@ public class FragmentAnswer extends FragmentBase { if (answer == null) etText.setText(null); else - etText.setText(HtmlHelper.fromHtml(answer.text, false, new Html.ImageGetter() { + etText.setText(HtmlHelper.fromHtml(answer.text, new Html.ImageGetter() { @Override public Drawable getDrawable(String source) { return ImageHelper.decodeImage(getContext(), -1, source, true, 0, 1.0f, etText); @@ -471,7 +471,7 @@ public class FragmentAnswer extends FragmentBase { getString(R.string.title_answer_template_name) + "
" + getString(R.string.title_answer_template_email) + - "

", false, getContext()); + "

", getContext()); View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_ask_again, null); TextView tvMessage = dview.findViewById(R.id.tvMessage); diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 4d75c29f95..d96a504eea 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -1670,7 +1670,7 @@ public class FragmentCompose extends FragmentBase { String html = EntityAnswer.replacePlaceholders(answer.text, to); - Spanned spanned = HtmlHelper.fromHtml(html, false, new Html.ImageGetter() { + Spanned spanned = HtmlHelper.fromHtml(html, new Html.ImageGetter() { @Override public Drawable getDrawable(String source) { return ImageHelper.decodeImage(getContext(), working, source, true, zoom, 1.0f, etBody); @@ -2248,7 +2248,7 @@ public class FragmentCompose extends FragmentBase { args.putInt("start", start); // TODO: double conversion - return HtmlHelper.fromHtml(HtmlHelper.toHtml(s, context), false, new Html.ImageGetter() { + return HtmlHelper.fromHtml(HtmlHelper.toHtml(s, context), new Html.ImageGetter() { @Override public Drawable getDrawable(String source) { return ImageHelper.decodeImage(context, id, source, true, zoom, 1.0f, etBody); @@ -5024,7 +5024,7 @@ public class FragmentCompose extends FragmentBase { Elements ref = doc.select("div[fairemail=reference]"); ref.remove(); - Spanned spannedBody = HtmlHelper.fromDocument(context, doc, false, new Html.ImageGetter() { + Spanned spannedBody = HtmlHelper.fromDocument(context, doc, new Html.ImageGetter() { @Override public Drawable getDrawable(String source) { return ImageHelper.decodeImage(context, id, source, true, zoom, 1.0f, etBody); @@ -5052,7 +5052,7 @@ public class FragmentCompose extends FragmentBase { if (!ref.isEmpty()) { Document dref = JsoupEx.parse(ref.outerHtml()); Document quote = HtmlHelper.sanitizeView(context, dref, show_images); - spannedRef = HtmlHelper.fromDocument(context, quote, true, + spannedRef = HtmlHelper.fromDocument(context, quote, new Html.ImageGetter() { @Override public Drawable getDrawable(String source) { @@ -5155,7 +5155,7 @@ public class FragmentCompose extends FragmentBase { Spanned signature = null; if (identity != null && !TextUtils.isEmpty(identity.signature)) - signature = HtmlHelper.fromHtml(identity.signature, false, new Html.ImageGetter() { + signature = HtmlHelper.fromHtml(identity.signature, new Html.ImageGetter() { @Override public Drawable getDrawable(String source) { return ImageHelper.decodeImage(getContext(), working, source, true, 0, 1.0f, tvSignature); diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentity.java b/app/src/main/java/eu/faircode/email/FragmentIdentity.java index 32fba07fa6..b505d005e6 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentity.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentity.java @@ -972,7 +972,7 @@ public class FragmentIdentity extends FragmentBase { btnSupport.setVisibility(View.VISIBLE); if (provider != null && provider.documentation != null) { - tvInstructions.setText(HtmlHelper.fromHtml(provider.documentation.toString(), true, getContext())); + tvInstructions.setText(HtmlHelper.fromHtml(provider.documentation.toString(), getContext())); tvInstructions.setVisibility(View.VISIBLE); } diff --git a/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java b/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java index 51d2da5ab2..6b0ad44651 100644 --- a/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java +++ b/app/src/main/java/eu/faircode/email/FragmentQuickSetup.java @@ -511,7 +511,7 @@ public class FragmentQuickSetup extends FragmentBase { btnSupport.setVisibility(View.VISIBLE); if (args.containsKey("documentation")) { - tvInstructions.setText(HtmlHelper.fromHtml(args.getString("documentation"), true, getContext())); + tvInstructions.setText(HtmlHelper.fromHtml(args.getString("documentation"), getContext())); tvInstructions.setVisibility(View.VISIBLE); } diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index df5ffd7677..9b9dad213e 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -1851,7 +1851,7 @@ public class HtmlHelper { truncate(d, true); - SpannableStringBuilder ssb = fromDocument(context, d, true, null, null); + SpannableStringBuilder ssb = fromDocument(context, d, null, null); for (URLSpan span : ssb.getSpans(0, ssb.length(), URLSpan.class)) { String url = span.getURL(); @@ -2000,7 +2000,7 @@ public class HtmlHelper { } static SpannableStringBuilder fromDocument( - Context context, @NonNull Document document, boolean compress, + Context context, @NonNull Document document, @Nullable Html.ImageGetter imageGetter, @Nullable Html.TagHandler tagHandler) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean debug = prefs.getBoolean("debug", false); @@ -2468,25 +2468,6 @@ public class HtmlHelper { else Log.e("Invalid span " + start + "..." + end + " len=" + len + " type=" + span.getClass().getName()); } - - private void newline(int index) { - int count = 0; - - if (compress) { - int i = Math.min(index, ssb.length() - 1); - while (i >= 0) { - char kar = ssb.charAt(i); - if (kar == '\n') - count++; - else if (kar != ' ' && kar != '\u00A0') - break; - i--; - } - } - - if (count < 2) - ssb.insert(index, "\n"); - } }, document.body()); if (debug) @@ -2529,13 +2510,13 @@ public class HtmlHelper { return ssb; } - static Spanned fromHtml(@NonNull String html, boolean compress, Context context) { - return fromHtml(html, compress, null, null, context); + static Spanned fromHtml(@NonNull String html, Context context) { + return fromHtml(html, null, null, context); } - static Spanned fromHtml(@NonNull String html, boolean compress, @Nullable Html.ImageGetter imageGetter, @Nullable Html.TagHandler tagHandler, Context context) { + static Spanned fromHtml(@NonNull String html, @Nullable Html.ImageGetter imageGetter, @Nullable Html.TagHandler tagHandler, Context context) { Document document = JsoupEx.parse(html); - return fromDocument(context, document, compress, imageGetter, tagHandler); + return fromDocument(context, document, imageGetter, tagHandler); } static String toHtml(Spanned spanned, Context context) {