mirror of https://github.com/M66B/FairEmail.git
Optional from HTML compression
This commit is contained in:
parent
e4958c0874
commit
ea4e40c079
|
@ -182,7 +182,7 @@ public class ActivityEML extends ActivityBase {
|
||||||
if (html != null) {
|
if (html != null) {
|
||||||
Document parsed = JsoupEx.parse(html);
|
Document parsed = JsoupEx.parse(html);
|
||||||
Document document = HtmlHelper.sanitizeView(context, parsed, false);
|
Document document = HtmlHelper.sanitizeView(context, parsed, false);
|
||||||
result.body = HtmlHelper.fromDocument(context, document);
|
result.body = HtmlHelper.fromDocument(context, document, true, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
@ -189,7 +189,7 @@ public class ActivitySignature extends ActivityBase {
|
||||||
else if (raw)
|
else if (raw)
|
||||||
etText.setText(html);
|
etText.setText(html);
|
||||||
else
|
else
|
||||||
etText.setText(HtmlHelper.fromHtml(html, new Html.ImageGetter() {
|
etText.setText(HtmlHelper.fromHtml(html, false, new Html.ImageGetter() {
|
||||||
@Override
|
@Override
|
||||||
public Drawable getDrawable(String source) {
|
public Drawable getDrawable(String source) {
|
||||||
return ImageHelper.decodeImage(ActivitySignature.this, -1, source, true, 0, etText);
|
return ImageHelper.decodeImage(ActivitySignature.this, -1, source, true, 0, etText);
|
||||||
|
|
|
@ -2027,7 +2027,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw images
|
// Draw images
|
||||||
SpannableStringBuilder ssb = HtmlHelper.fromDocument(context, document, new Html.ImageGetter() {
|
SpannableStringBuilder ssb = HtmlHelper.fromDocument(context, document, true, new Html.ImageGetter() {
|
||||||
@Override
|
@Override
|
||||||
public Drawable getDrawable(String source) {
|
public Drawable getDrawable(String source) {
|
||||||
Drawable drawable = ImageHelper.decodeImage(context, message.id, source, show_images, zoom, tvBody);
|
Drawable drawable = ImageHelper.decodeImage(context, message.id, source, show_images, zoom, tvBody);
|
||||||
|
|
|
@ -3374,7 +3374,7 @@ class Core {
|
||||||
|
|
||||||
// Device
|
// Device
|
||||||
builder.setStyle(new NotificationCompat.BigTextStyle()
|
builder.setStyle(new NotificationCompat.BigTextStyle()
|
||||||
.bigText(HtmlHelper.fromHtml(sb.toString(), context))
|
.bigText(HtmlHelper.fromHtml(sb.toString(), true, context))
|
||||||
.setSummaryText(title));
|
.setSummaryText(title));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3663,7 +3663,7 @@ class Core {
|
||||||
|
|
||||||
if (sbm.length() > 0) {
|
if (sbm.length() > 0) {
|
||||||
NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle()
|
NotificationCompat.BigTextStyle bigText = new NotificationCompat.BigTextStyle()
|
||||||
.bigText(HtmlHelper.fromHtml(sbm.toString(), context));
|
.bigText(HtmlHelper.fromHtml(sbm.toString(), true, context));
|
||||||
if (!TextUtils.isEmpty(message.subject))
|
if (!TextUtils.isEmpty(message.subject))
|
||||||
bigText.setSummaryText(message.subject);
|
bigText.setSummaryText(message.subject);
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class EditTextCompose extends FixedEditText {
|
||||||
}
|
}
|
||||||
|
|
||||||
Document document = HtmlHelper.sanitizeCompose(context, html, false);
|
Document document = HtmlHelper.sanitizeCompose(context, html, false);
|
||||||
Spanned paste = HtmlHelper.fromDocument(getContext(), document, new Html.ImageGetter() {
|
Spanned paste = HtmlHelper.fromDocument(getContext(), document, true, new Html.ImageGetter() {
|
||||||
@Override
|
@Override
|
||||||
public Drawable getDrawable(String source) {
|
public Drawable getDrawable(String source) {
|
||||||
return ImageHelper.decodeImage(getContext(),
|
return ImageHelper.decodeImage(getContext(),
|
||||||
|
|
|
@ -1373,7 +1373,7 @@ public class FragmentAccount extends FragmentBase {
|
||||||
btnSupport.setVisibility(View.VISIBLE);
|
btnSupport.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
if (provider != null && provider.documentation != null) {
|
if (provider != null && provider.documentation != null) {
|
||||||
tvInstructions.setText(HtmlHelper.fromHtml(provider.documentation.toString(), getContext()));
|
tvInstructions.setText(HtmlHelper.fromHtml(provider.documentation.toString(), true, getContext()));
|
||||||
tvInstructions.setVisibility(View.VISIBLE);
|
tvInstructions.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -166,7 +166,7 @@ public class FragmentAnswer extends FragmentBase {
|
||||||
if (answer == null)
|
if (answer == null)
|
||||||
etText.setText(null);
|
etText.setText(null);
|
||||||
else
|
else
|
||||||
etText.setText(HtmlHelper.fromHtml(answer.text, new Html.ImageGetter() {
|
etText.setText(HtmlHelper.fromHtml(answer.text, false, new Html.ImageGetter() {
|
||||||
@Override
|
@Override
|
||||||
public Drawable getDrawable(String source) {
|
public Drawable getDrawable(String source) {
|
||||||
return ImageHelper.decodeImage(getContext(), -1, source, true, 0, etText);
|
return ImageHelper.decodeImage(getContext(), -1, source, true, 0, etText);
|
||||||
|
@ -425,7 +425,7 @@ public class FragmentAnswer extends FragmentBase {
|
||||||
getString(R.string.title_answer_template_name) +
|
getString(R.string.title_answer_template_name) +
|
||||||
"<br>" +
|
"<br>" +
|
||||||
getString(R.string.title_answer_template_email) +
|
getString(R.string.title_answer_template_email) +
|
||||||
"</p>", getContext());
|
"</p>", false, getContext());
|
||||||
|
|
||||||
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_ask_again, null);
|
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_ask_again, null);
|
||||||
TextView tvMessage = dview.findViewById(R.id.tvMessage);
|
TextView tvMessage = dview.findViewById(R.id.tvMessage);
|
||||||
|
|
|
@ -1966,7 +1966,7 @@ public class FragmentCompose extends FragmentBase {
|
||||||
args.putInt("start", start);
|
args.putInt("start", start);
|
||||||
|
|
||||||
// TODO: double conversion
|
// TODO: double conversion
|
||||||
return HtmlHelper.fromHtml(HtmlHelper.toHtml(s, getContext()), new Html.ImageGetter() {
|
return HtmlHelper.fromHtml(HtmlHelper.toHtml(s, getContext()), false, new Html.ImageGetter() {
|
||||||
@Override
|
@Override
|
||||||
public Drawable getDrawable(String source) {
|
public Drawable getDrawable(String source) {
|
||||||
return ImageHelper.decodeImage(context, id, source, true, zoom, etBody);
|
return ImageHelper.decodeImage(context, id, source, true, zoom, etBody);
|
||||||
|
@ -2754,7 +2754,7 @@ public class FragmentCompose extends FragmentBase {
|
||||||
|
|
||||||
String html = EntityAnswer.replacePlaceholders(answer, to);
|
String html = EntityAnswer.replacePlaceholders(answer, to);
|
||||||
|
|
||||||
Spanned spanned = HtmlHelper.fromHtml(html, new Html.ImageGetter() {
|
Spanned spanned = HtmlHelper.fromHtml(html, false, new Html.ImageGetter() {
|
||||||
@Override
|
@Override
|
||||||
public Drawable getDrawable(String source) {
|
public Drawable getDrawable(String source) {
|
||||||
return ImageHelper.decodeImage(getContext(), working, source, true, zoom, etBody);
|
return ImageHelper.decodeImage(getContext(), working, source, true, zoom, etBody);
|
||||||
|
@ -4630,7 +4630,7 @@ public class FragmentCompose extends FragmentBase {
|
||||||
Elements ref = doc.select("div[fairemail=reference]");
|
Elements ref = doc.select("div[fairemail=reference]");
|
||||||
ref.remove();
|
ref.remove();
|
||||||
|
|
||||||
Spanned spannedBody = HtmlHelper.fromDocument(context, doc, new Html.ImageGetter() {
|
Spanned spannedBody = HtmlHelper.fromDocument(context, doc, false, new Html.ImageGetter() {
|
||||||
@Override
|
@Override
|
||||||
public Drawable getDrawable(String source) {
|
public Drawable getDrawable(String source) {
|
||||||
return ImageHelper.decodeImage(context, id, source, true, zoom, etBody);
|
return ImageHelper.decodeImage(context, id, source, true, zoom, etBody);
|
||||||
|
@ -4658,7 +4658,7 @@ public class FragmentCompose extends FragmentBase {
|
||||||
if (!ref.isEmpty()) {
|
if (!ref.isEmpty()) {
|
||||||
Document dref = JsoupEx.parse(ref.outerHtml());
|
Document dref = JsoupEx.parse(ref.outerHtml());
|
||||||
Document quote = HtmlHelper.sanitizeView(context, dref, show_images);
|
Document quote = HtmlHelper.sanitizeView(context, dref, show_images);
|
||||||
spannedRef = HtmlHelper.fromDocument(context, quote,
|
spannedRef = HtmlHelper.fromDocument(context, quote, true,
|
||||||
new Html.ImageGetter() {
|
new Html.ImageGetter() {
|
||||||
@Override
|
@Override
|
||||||
public Drawable getDrawable(String source) {
|
public Drawable getDrawable(String source) {
|
||||||
|
@ -4755,7 +4755,7 @@ public class FragmentCompose extends FragmentBase {
|
||||||
|
|
||||||
Spanned signature = null;
|
Spanned signature = null;
|
||||||
if (identity != null && !TextUtils.isEmpty(identity.signature))
|
if (identity != null && !TextUtils.isEmpty(identity.signature))
|
||||||
signature = HtmlHelper.fromHtml(identity.signature, new Html.ImageGetter() {
|
signature = HtmlHelper.fromHtml(identity.signature, false, new Html.ImageGetter() {
|
||||||
@Override
|
@Override
|
||||||
public Drawable getDrawable(String source) {
|
public Drawable getDrawable(String source) {
|
||||||
return ImageHelper.decodeImage(getContext(), working, source, true, 0, tvSignature);
|
return ImageHelper.decodeImage(getContext(), working, source, true, 0, tvSignature);
|
||||||
|
|
|
@ -995,7 +995,7 @@ public class FragmentIdentity extends FragmentBase {
|
||||||
btnSupport.setVisibility(View.VISIBLE);
|
btnSupport.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
if (provider != null && provider.documentation != null) {
|
if (provider != null && provider.documentation != null) {
|
||||||
tvInstructions.setText(HtmlHelper.fromHtml(provider.documentation.toString(), getContext()));
|
tvInstructions.setText(HtmlHelper.fromHtml(provider.documentation.toString(), true, getContext()));
|
||||||
tvInstructions.setVisibility(View.VISIBLE);
|
tvInstructions.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -491,7 +491,7 @@ public class FragmentQuickSetup extends FragmentBase {
|
||||||
btnSupport.setVisibility(View.VISIBLE);
|
btnSupport.setVisibility(View.VISIBLE);
|
||||||
|
|
||||||
if (args.containsKey("documentation")) {
|
if (args.containsKey("documentation")) {
|
||||||
tvInstructions.setText(HtmlHelper.fromHtml(args.getString("documentation"), getContext()));
|
tvInstructions.setText(HtmlHelper.fromHtml(args.getString("documentation"), true, getContext()));
|
||||||
tvInstructions.setVisibility(View.VISIBLE);
|
tvInstructions.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1587,7 +1587,7 @@ public class HtmlHelper {
|
||||||
|
|
||||||
truncate(d, true);
|
truncate(d, true);
|
||||||
|
|
||||||
SpannableStringBuilder ssb = fromDocument(context, d, false, null, null);
|
SpannableStringBuilder ssb = fromDocument(context, d, false, true, null, null);
|
||||||
|
|
||||||
for (URLSpan span : ssb.getSpans(0, ssb.length(), URLSpan.class)) {
|
for (URLSpan span : ssb.getSpans(0, ssb.length(), URLSpan.class)) {
|
||||||
String url = span.getURL();
|
String url = span.getURL();
|
||||||
|
@ -1804,15 +1804,16 @@ public class HtmlHelper {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SpannableStringBuilder fromDocument(Context context, @NonNull Document document) {
|
static SpannableStringBuilder fromDocument(
|
||||||
return fromDocument(context, document, null, null);
|
Context context, @NonNull Document document, boolean compress,
|
||||||
|
@Nullable Html.ImageGetter imageGetter, @Nullable Html.TagHandler tagHandler) {
|
||||||
|
return fromDocument(context, document, true, compress, imageGetter, tagHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
static SpannableStringBuilder fromDocument(Context context, @NonNull Document document, @Nullable Html.ImageGetter imageGetter, @Nullable Html.TagHandler tagHandler) {
|
private static SpannableStringBuilder fromDocument(
|
||||||
return fromDocument(context, document, true, imageGetter, tagHandler);
|
Context context, @NonNull Document document,
|
||||||
}
|
final boolean warn, final boolean compress,
|
||||||
|
@Nullable Html.ImageGetter imageGetter, @Nullable Html.TagHandler tagHandler) {
|
||||||
private static SpannableStringBuilder fromDocument(Context context, @NonNull Document document, final boolean warn, @Nullable Html.ImageGetter imageGetter, @Nullable Html.TagHandler tagHandler) {
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
boolean debug = prefs.getBoolean("debug", false);
|
boolean debug = prefs.getBoolean("debug", false);
|
||||||
|
|
||||||
|
@ -2179,14 +2180,17 @@ public class HtmlHelper {
|
||||||
|
|
||||||
private void newline(int index) {
|
private void newline(int index) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int i = Math.min(index, ssb.length() - 1);
|
|
||||||
while (i >= 0) {
|
if (compress) {
|
||||||
char kar = ssb.charAt(i);
|
int i = Math.min(index, ssb.length() - 1);
|
||||||
if (kar == '\n')
|
while (i >= 0) {
|
||||||
count++;
|
char kar = ssb.charAt(i);
|
||||||
else if (kar != ' ' && kar != '\u00A0')
|
if (kar == '\n')
|
||||||
break;
|
count++;
|
||||||
i--;
|
else if (kar != ' ' && kar != '\u00A0')
|
||||||
|
break;
|
||||||
|
i--;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count < 2)
|
if (count < 2)
|
||||||
|
@ -2219,15 +2223,13 @@ public class HtmlHelper {
|
||||||
return ssb;
|
return ssb;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Spanned fromHtml(@NonNull String html, Context context) {
|
static Spanned fromHtml(@NonNull String html, boolean compress, Context context) {
|
||||||
return fromHtml(html, null, null, context);
|
return fromHtml(html, compress, null, null, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Spanned fromHtml(@NonNull String html, @Nullable Html.ImageGetter imageGetter, @Nullable Html.TagHandler tagHandler, Context context) {
|
static Spanned fromHtml(@NonNull String html, boolean compress, @Nullable Html.ImageGetter imageGetter, @Nullable Html.TagHandler tagHandler, Context context) {
|
||||||
Document document = JsoupEx.parse(html);
|
Document document = JsoupEx.parse(html);
|
||||||
return fromDocument(context, document, false, imageGetter, tagHandler);
|
Spanned spanned = fromDocument(context, document, false, compress, imageGetter, tagHandler);
|
||||||
/*
|
|
||||||
Spanned spanned = HtmlCompat.fromHtml(html, FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM, imageGetter, tagHandler);
|
|
||||||
|
|
||||||
int i = spanned.length();
|
int i = spanned.length();
|
||||||
while (i > 1 && spanned.charAt(i - 2) == '\n' && spanned.charAt(i - 1) == '\n')
|
while (i > 1 && spanned.charAt(i - 2) == '\n' && spanned.charAt(i - 1) == '\n')
|
||||||
|
@ -2235,8 +2237,7 @@ public class HtmlHelper {
|
||||||
if (i != spanned.length())
|
if (i != spanned.length())
|
||||||
spanned = (Spanned) spanned.subSequence(0, i);
|
spanned = (Spanned) spanned.subSequence(0, i);
|
||||||
|
|
||||||
return reverseSpans(spanned);
|
return spanned;
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static String toHtml(Spanned spanned, Context context) {
|
static String toHtml(Spanned spanned, Context context) {
|
||||||
|
|
Loading…
Reference in New Issue