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