Improved quote collapsing

pull/199/head
M66B 3 years ago
parent 2048374ad0
commit 71f69e124d

@ -2376,21 +2376,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
args.putParcelable("actions", getConversationActions(message, document, context));
// Collapse quotes
if (!show_quotes) {
List<Element> successive = new ArrayList<>();
for (Element quote : document.select("blockquote"))
if (HtmlHelper.hasBorder(quote)) {
Element next = quote.nextElementSibling();
if (next != null &&
"blockquote".equals(next.tagName()) &&
HtmlHelper.hasBorder(next))
successive.add(quote);
else
quote.html("&#8230;");
}
for (Element quote : successive)
quote.remove();
}
if (!show_quotes)
HtmlHelper.collapseQuotes(document);
// Draw images
SpannableStringBuilder ssb = HtmlHelper.fromDocument(context, document, new Html.ImageGetter() {

@ -2018,6 +2018,39 @@ public class HtmlHelper {
return "true".equals(e.attr("x-border"));
}
static void collapseQuotes(Document document) {
document.body().filter(new NodeFilter() {
private int level = 0;
@Override
public FilterResult head(Node node, int depth) {
if (level > 0)
return FilterResult.REMOVE;
if (node instanceof Element) {
Element element = (Element) node;
if ("blockquote".equals(element.tagName()) && hasBorder(element)) {
Element prev = element.previousElementSibling();
if (prev != null &&
"blockquote".equals(prev.tagName()) && hasBorder(prev))
return FilterResult.REMOVE;
level++;
}
}
return FilterResult.CONTINUE;
}
@Override
public FilterResult tail(Node node, int depth) {
if ("blockquote".equals(node.nodeName()))
level--;
return FilterResult.CONTINUE;
}
});
document.select("blockquote").html("&#8230;");
}
static String truncate(String text, int at) {
if (text.length() < at)
return text;

Loading…
Cancel
Save