View indentations

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

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

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

Loading…
Cancel
Save