View indentations

pull/199/head
M66B 3 years ago
parent b20a13783b
commit b558e3b2e0

@ -2377,15 +2377,18 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
// Collapse quotes
if (!show_quotes) {
List<Element> succesive = new ArrayList<>();
for (Element quote : document.select("blockquote")) {
Element next = quote.nextElementSibling();
if (next != null && "blockquote".equals(next.tagName()))
succesive.add(quote);
else
quote.html("&#8230;");
}
for (Element quote : succesive)
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();
}

@ -807,6 +807,17 @@ public class HtmlHelper {
sb.append(key).append(':').append(value).append(';');
}
break;
case "border":
case "border-left":
case "border-right":
if (value != null) {
// 1px solid rgb(204,204,204)
Float border = getFontSize(value.trim().split("\\s+")[0], 1.0f);
if (border != null && border > 0)
element.attr("x-border", "true");
}
break;
}
}
@ -1989,14 +2000,19 @@ public class HtmlHelper {
private static String _getText(Document d) {
truncate(d, MAX_FULL_TEXT_SIZE);
for (Element bq : d.select("blockquote")) {
bq.prependChild(new TextNode("["));
bq.appendChild(new TextNode("]"));
}
for (Element bq : d.select("blockquote"))
if (hasBorder(bq)) {
bq.prependChild(new TextNode("["));
bq.appendChild(new TextNode("]"));
}
return d.text();
}
static boolean hasBorder(Element e) {
return "true".equals(e.attr("x-border"));
}
static String truncate(String text, int at) {
if (text.length() < at)
return text;
@ -2206,7 +2222,8 @@ public class HtmlHelper {
int level = 1;
Element parent = bq.parent();
while (parent != null) {
if ("blockquote".equals(parent.tagName()))
if ("blockquote".equals(parent.tagName()) &&
hasBorder(parent))
level++;
parent = parent.parent();
}
@ -2291,6 +2308,7 @@ public class HtmlHelper {
int bulletGap = context.getResources().getDimensionPixelSize(R.dimen.bullet_gap_size);
int bulletRadius = context.getResources().getDimensionPixelSize(R.dimen.bullet_radius_size);
int bulletIndent = context.getResources().getDimensionPixelSize(R.dimen.bullet_indent_size);
int intentSize = context.getResources().getDimensionPixelSize(R.dimen.indent_size);
int quoteGap = context.getResources().getDimensionPixelSize(R.dimen.quote_gap_size);
int quoteStripe = context.getResources().getDimensionPixelSize(R.dimen.quote_stripe_width);
int line_dash_length = context.getResources().getDimensionPixelSize(R.dimen.line_dash_length);
@ -2573,10 +2591,13 @@ public class HtmlHelper {
if (ssb.length() == 0 || ssb.charAt(ssb.length() - 1) != '\n')
ssb.append("\n");
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P)
setSpan(ssb, new QuoteSpan(colorBlockquote), start, ssb.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else
setSpan(ssb, new QuoteSpan(colorBlockquote, quoteStripe, quoteGap), start, ssb.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
if (hasBorder(element)) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P)
setSpan(ssb, new QuoteSpan(colorBlockquote), start, ssb.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
else
setSpan(ssb, new QuoteSpan(colorBlockquote, quoteStripe, quoteGap), start, ssb.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
} else
setSpan(ssb, new IndentSpan(intentSize), start, ssb.length());
break;
case "br":
ssb.append('\n');
@ -2858,7 +2879,8 @@ public class HtmlHelper {
.removeAttr("x-align")
.removeAttr("x-column")
.removeAttr("x-dashed")
.removeAttr("x-tracking");
.removeAttr("x-tracking")
.removeAttr("x-border");
}
static Spanned fromHtml(@NonNull String html, Context context) {

@ -0,0 +1,37 @@
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018-2021 by Marcel Bokhorst (M66B)
*/
import android.os.Parcel;
import android.text.style.LeadingMarginSpan;
public class IndentSpan extends LeadingMarginSpan.Standard {
public IndentSpan(int first, int rest) {
super(first, rest);
}
public IndentSpan(int every) {
super(every);
}
public IndentSpan(Parcel src) {
super(src);
}
}

@ -8,6 +8,7 @@
<dimen name="bullet_gap_size">6dp</dimen>
<dimen name="bullet_radius_size">3dp</dimen>
<dimen name="bullet_indent_size">24dp</dimen>
<dimen name="indent_size">24dp</dimen>
<dimen name="quote_gap_size">6dp</dimen>
<dimen name="quote_stripe_width">3dp</dimen>
<dimen name="line_dash_length">3dp</dimen>

Loading…
Cancel
Save