Fixed/improved collapsing quotes

pull/168/head
M66B 5 years ago
parent 86afc8a978
commit dd39eec9b0

@ -1448,15 +1448,18 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return document.html(); return document.html();
} else { } else {
// Cleanup message
String html = HtmlHelper.sanitize(context, body, show_images);
// Collapse quotes // Collapse quotes
if (!show_quotes) { if (!show_quotes) {
for (Element quote : document.select("blockquote")) Document doc = JsoupEx.parse(html);
for (Element quote : doc.select("blockquote"))
quote.html("&#8230;"); quote.html("&#8230;");
body = document.html(); html = doc.html();
} }
// Cleanup message // Add debug info
String html = HtmlHelper.sanitize(context, body, show_images);
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,24 +1485,22 @@ 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);
@ -1507,9 +1509,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return d; return d;
} }
}, },
builder.getSpanStart(squote), s, e, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
builder.getSpanEnd(squote),
builder.getSpanFlags(squote));
} }
return builder; return builder;

Loading…
Cancel
Save