1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2024-12-27 18:27:43 +00:00

Fixed/improved collapsing quotes

This commit is contained in:
M66B 2019-11-14 16:06:30 +01:00
parent 86afc8a978
commit dd39eec9b0

View file

@ -1448,15 +1448,18 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return document.html(); return document.html();
} else { } else {
// Collapse quotes
if (!show_quotes) {
for (Element quote : document.select("blockquote"))
quote.html("&#8230;");
body = document.html();
}
// Cleanup message // Cleanup message
String html = HtmlHelper.sanitize(context, body, show_images); String html = HtmlHelper.sanitize(context, body, show_images);
// Collapse quotes
if (!show_quotes) {
Document doc = JsoupEx.parse(html);
for (Element quote : doc.select("blockquote"))
quote.html("&#8230;");
html = doc.html();
}
// Add debug info
if (debug) { if (debug) {
Document format = JsoupEx.parse(html); Document format = JsoupEx.parse(html);
format.outputSettings().prettyPrint(true).outline(true).indentAmount(1); format.outputSettings().prettyPrint(true).outline(true).indentAmount(1);
@ -1466,6 +1469,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
html += "<pre>" + TextUtils.join("<br>", lines) + "</pre>"; html += "<pre>" + TextUtils.join("<br>", lines) + "</pre>";
} }
// Draw images
Spanned spanned = HtmlHelper.fromHtml(html, new Html.ImageGetter() { Spanned spanned = HtmlHelper.fromHtml(html, new Html.ImageGetter() {
@Override @Override
public Drawable getDrawable(String source) { public Drawable getDrawable(String source) {
@ -1481,35 +1485,31 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}, null); }, null);
// Replace quote spans // Replace quote spans
final int px = Helper.dp2pixels(context, 24 + (zoom) * 8);
SpannableStringBuilder builder = new SpannableStringBuilder(spanned); SpannableStringBuilder builder = new SpannableStringBuilder(spanned);
QuoteSpan[] quoteSpans = builder.getSpans(0, builder.length(), QuoteSpan.class); QuoteSpan[] quoteSpans = builder.getSpans(0, builder.length(), QuoteSpan.class);
for (QuoteSpan quoteSpan : quoteSpans) { for (QuoteSpan quoteSpan : quoteSpans) {
builder.setSpan( int s = builder.getSpanStart(quoteSpan);
new StyledQuoteSpan(context, colorPrimary), int e = builder.getSpanEnd(quoteSpan);
builder.getSpanStart(quoteSpan), Log.i("Quote start=" + s + " end=" + e);
builder.getSpanEnd(quoteSpan),
builder.getSpanFlags(quoteSpan));
builder.removeSpan(quoteSpan); builder.removeSpan(quoteSpan);
}
// Make collapsed quotes clickable StyledQuoteSpan squote = new StyledQuoteSpan(context, colorPrimary);
if (!show_quotes) { builder.setSpan(squote, s, e, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
final int px = Helper.dp2pixels(context, 24 + (zoom) * 8);
StyledQuoteSpan[] squotes = builder.getSpans(0, builder.length(), StyledQuoteSpan.class); if (!show_quotes)
for (StyledQuoteSpan squote : squotes) builder.setSpan(
builder.setSpan(new DynamicDrawableSpan() { new DynamicDrawableSpan() {
@Override @Override
public Drawable getDrawable() { public Drawable getDrawable() {
Drawable d = context.getDrawable(R.drawable.baseline_format_quote_24); Drawable d = context.getDrawable(R.drawable.baseline_format_quote_24);
d.setTint(colorAccent); d.setTint(colorAccent);
d.setBounds(0, 0, px, px); d.setBounds(0, 0, px, px);
return d; return d;
} }
}, },
builder.getSpanStart(squote), s, e, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
builder.getSpanEnd(squote),
builder.getSpanFlags(squote));
} }
return builder; return builder;