Truncate viewed text only

pull/177/head
M66B 5 years ago
parent 5a730c246b
commit 20fe6314ad

@ -177,7 +177,8 @@ public class ActivityEML extends ActivityBase {
String html = result.parts.getHtml(context); String html = result.parts.getHtml(context);
if (html != null) { if (html != null) {
Document document = HtmlHelper.sanitize(context, html, false, true); Document parsed = JsoupEx.parse(html);
Document document = HtmlHelper.sanitizeView(context, parsed, false);
result.body = HtmlHelper.fromHtml(document.html()); result.body = HtmlHelper.fromHtml(document.html());
} }

@ -1858,7 +1858,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return document.html(); return document.html();
} else { } else {
// Cleanup message // Cleanup message
document = HtmlHelper.sanitize(context, document, show_images, true, true); document = HtmlHelper.sanitizeView(context, document, show_images);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
args.putParcelable("actions", getConversationActions(message, document)); args.putParcelable("actions", getConversationActions(message, document));

@ -78,7 +78,7 @@ public class EditTextCompose extends AppCompatEditText {
return false; return false;
html = "<div>" + HtmlHelper.formatPre(text.toString()) + "</div>"; html = "<div>" + HtmlHelper.formatPre(text.toString()) + "</div>";
} }
Document document = HtmlHelper.sanitize(context, html, false, false); Document document = HtmlHelper.sanitizeCompose(context, html, false);
Spanned paste = HtmlHelper.fromHtml(document.html()); Spanned paste = HtmlHelper.fromHtml(document.html());
int colorPrimary = Helper.resolveColor(context, R.attr.colorPrimary); int colorPrimary = Helper.resolveColor(context, R.attr.colorPrimary);

@ -880,7 +880,7 @@ public class FragmentCompose extends FragmentBase {
p.html(TextUtils.join("<br>", line)); p.html(TextUtils.join("<br>", line));
document.body().appendChild(p); document.body().appendChild(p);
} else { } else {
Document d = HtmlHelper.sanitize(context, ref.outerHtml(), true, false); Document d = HtmlHelper.sanitizeCompose(context, ref.outerHtml(), true);
Element b = d.body(); Element b = d.body();
b.tagName("div"); b.tagName("div");
document.body().appendChild(b); document.body().appendChild(b);
@ -2983,7 +2983,7 @@ public class FragmentCompose extends FragmentBase {
data.draft.subject = args.getString("subject", ""); data.draft.subject = args.getString("subject", "");
String b = args.getString("body", ""); String b = args.getString("body", "");
if (!TextUtils.isEmpty(b)) { if (!TextUtils.isEmpty(b)) {
Document d = HtmlHelper.sanitize(context, b, false, false); Document d = HtmlHelper.sanitizeCompose(context, b, false);
Element e = d.body(); Element e = d.body();
e.tagName("div"); e.tagName("div");
document.body().appendChild(e); document.body().appendChild(e);
@ -3105,7 +3105,7 @@ public class FragmentCompose extends FragmentBase {
data.draft.subject = ref.subject; data.draft.subject = ref.subject;
if (ref.content) { if (ref.content) {
String html = Helper.readText(ref.getFile(context)); String html = Helper.readText(ref.getFile(context));
Document d = HtmlHelper.sanitize(context, html, true, false); Document d = HtmlHelper.sanitizeCompose(context, html, true);
Element e = d.body(); Element e = d.body();
e.tagName("div"); e.tagName("div");
document.body().appendChild(e); document.body().appendChild(e);
@ -3391,7 +3391,7 @@ public class FragmentCompose extends FragmentBase {
refFile.delete(); refFile.delete();
} }
Document document = HtmlHelper.sanitize(context, doc.html(), true, false); Document document = HtmlHelper.sanitizeCompose(context, doc.html(), true);
EntityIdentity identity = null; EntityIdentity identity = null;
if (data.draft.identity != null) if (data.draft.identity != null)
@ -3789,7 +3789,7 @@ public class FragmentCompose extends FragmentBase {
if (body == null) if (body == null)
b = Document.createShell(""); b = Document.createShell("");
else else
b = HtmlHelper.sanitize(context, body, true, false); b = HtmlHelper.sanitizeCompose(context, body, true);
if (TextUtils.isEmpty(body) || if (TextUtils.isEmpty(body) ||
!b.body().html().equals(doc.body().html()) || !b.body().html().equals(doc.body().html()) ||
@ -4230,7 +4230,7 @@ public class FragmentCompose extends FragmentBase {
Spanned spannedRef = null; Spanned spannedRef = null;
if (!ref.isEmpty()) { if (!ref.isEmpty()) {
Document quote = HtmlHelper.sanitize(context, ref.outerHtml(), show_images, false); Document quote = HtmlHelper.sanitizeCompose(context, ref.outerHtml(), show_images);
Spanned spannedQuote = HtmlHelper.fromHtml(quote.html(), Spanned spannedQuote = HtmlHelper.fromHtml(quote.html(),
new Html.ImageGetter() { new Html.ImageGetter() {
@Override @Override

@ -237,14 +237,24 @@ public class HtmlHelper {
x11ColorMap.put("yellowgreen", 0x9ACD32); x11ColorMap.put("yellowgreen", 0x9ACD32);
} }
static Document sanitize(Context context, String html, boolean show_images, boolean autolink) { static Document sanitizeCompose(Context context, String html, boolean show_images) {
try {
Document parsed = JsoupEx.parse(html); Document parsed = JsoupEx.parse(html);
return sanitize(context, parsed, show_images, autolink, false); return sanitize(context, parsed, false, show_images);
} catch (Throwable ex) {
// OutOfMemoryError
Log.e(ex);
Document document = Document.createShell("");
Element strong = document.createElement("strong");
strong.text(Log.formatThrowable(ex));
document.body().appendChild(strong);
return document;
}
} }
static Document sanitize(Context context, Document parsed, boolean show_images, boolean autolink, boolean more) { static Document sanitizeView(Context context, Document parsed, boolean show_images) {
try { try {
return _sanitize(context, parsed, show_images, autolink, more); return sanitize(context, parsed, true, show_images);
} catch (Throwable ex) { } catch (Throwable ex) {
// OutOfMemoryError // OutOfMemoryError
Log.e(ex); Log.e(ex);
@ -256,7 +266,7 @@ public class HtmlHelper {
} }
} }
private static Document _sanitize(Context context, Document parsed, boolean show_images, boolean autolink, boolean more) { private static Document sanitize(Context context, Document parsed, boolean view, boolean show_images) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean text_color = prefs.getBoolean("text_color", true); boolean text_color = prefs.getBoolean("text_color", true);
boolean text_size = prefs.getBoolean("text_size", true); boolean text_size = prefs.getBoolean("text_size", true);
@ -328,14 +338,12 @@ public class HtmlHelper {
} }
// Limit length // Limit length
if (truncate(parsed, true)) { if (view && truncate(parsed, true)) {
parsed.body() parsed.body()
.appendElement("br") .appendElement("br")
.appendElement("p") .appendElement("p")
.appendElement("em") .appendElement("em")
.text(context.getString(R.string.title_too_large)); .text(context.getString(R.string.title_too_large));
if (more)
parsed.body() parsed.body()
.appendElement("p") .appendElement("p")
.appendElement("big") .appendElement("big")
@ -688,7 +696,7 @@ public class HtmlHelper {
} }
// Autolink // Autolink
if (autolink) { if (view) {
final Pattern pattern = Pattern.compile( final Pattern pattern = Pattern.compile(
PatternsCompat.AUTOLINK_EMAIL_ADDRESS.pattern() + "|" + PatternsCompat.AUTOLINK_EMAIL_ADDRESS.pattern() + "|" +
PatternsCompat.AUTOLINK_WEB_URL.pattern()); PatternsCompat.AUTOLINK_WEB_URL.pattern());

Loading…
Cancel
Save