Optimization

pull/193/head
M66B 4 years ago
parent 8f3bd8b5ce
commit c24f79354e

@ -1499,11 +1499,13 @@ class Core {
String body = parts.getHtml(context);
File file = message.getFile(context);
Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body);
String preview = HtmlHelper.getPreviewText(text);
db.message().setMessageContent(message.id,
true,
HtmlHelper.getLanguage(context, body),
HtmlHelper.getLanguage(context, text),
parts.isPlainOnly(),
HtmlHelper.getPreview(body),
preview,
parts.getWarnings(message.warning));
MessageClassifier.classify(message, folder, null, context);
@ -2208,11 +2210,13 @@ class Core {
String body = parts.getHtml(context);
File file = message.getFile(context);
Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body);
String preview = HtmlHelper.getPreviewText(text);
db.message().setMessageContent(message.id,
true,
HtmlHelper.getLanguage(context, body),
HtmlHelper.getLanguage(context, text),
parts.isPlainOnly(),
HtmlHelper.getPreview(body),
preview,
parts.getWarnings(message.warning));
for (EntityAttachment attachment : parts.getAttachments())
@ -3011,11 +3015,13 @@ class Core {
String body = parts.getHtml(context);
File file = message.getFile(context);
Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body);
String preview = HtmlHelper.getPreviewText(text);
db.message().setMessageContent(message.id,
true,
HtmlHelper.getLanguage(context, body),
HtmlHelper.getLanguage(context, text),
parts.isPlainOnly(),
HtmlHelper.getPreview(body),
preview,
parts.getWarnings(message.warning));
MessageClassifier.classify(message, folder, null, context);
@ -3447,11 +3453,13 @@ class Core {
String body = parts.getHtml(context);
File file = message.getFile(context);
Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body);
String preview = HtmlHelper.getPreviewText(text);
db.message().setMessageContent(message.id,
true,
HtmlHelper.getLanguage(context, body),
HtmlHelper.getLanguage(context, text),
parts.isPlainOnly(),
HtmlHelper.getPreview(body),
preview,
parts.getWarnings(message.warning));
MessageClassifier.classify(message, folder, null, context);

@ -611,11 +611,13 @@ public class EntityRule {
File file = reply.getFile(context);
Helper.writeText(file, body);
String text = HtmlHelper.getFullText(body);
String preview = HtmlHelper.getPreviewText(text);
db.message().setMessageContent(reply.id,
true,
HtmlHelper.getLanguage(context, body),
HtmlHelper.getLanguage(context, text),
false,
HtmlHelper.getPreview(body),
preview,
null);
if (attachments)
@ -700,7 +702,9 @@ public class EntityRule {
.append(' ').append(message.subject).append(". ");
String body = Helper.readText(message.getFile(context));
String preview = HtmlHelper.getPreview(body);
String text = HtmlHelper.getFullText(body);
String preview = HtmlHelper.getPreviewText(text);
if (!TextUtils.isEmpty(preview))
sb.append(res.getString(R.string.title_rule_tts_content))
.append(' ').append(preview);

@ -3924,11 +3924,13 @@ public class FragmentCompose extends FragmentBase {
Helper.writeText(data.draft.getFile(context), html);
Helper.writeText(data.draft.getFile(context, data.draft.revision), html);
String text = HtmlHelper.getFullText(html);
String preview = HtmlHelper.getPreviewText(text);
db.message().setMessageContent(data.draft.id,
true,
HtmlHelper.getLanguage(context, html),
HtmlHelper.getLanguage(context, text),
data.draft.plain_only,
HtmlHelper.getPreview(html),
preview,
null);
if ("participation".equals(action)) {
@ -4077,11 +4079,13 @@ public class FragmentCompose extends FragmentBase {
Helper.writeText(file, html);
Helper.writeText(data.draft.getFile(context, data.draft.revision), html);
String text = HtmlHelper.getFullText(html);
String preview = HtmlHelper.getPreviewText(text);
db.message().setMessageContent(data.draft.id,
true,
HtmlHelper.getLanguage(context, html),
HtmlHelper.getLanguage(context, text),
data.draft.plain_only,
HtmlHelper.getPreview(html),
preview,
null);
} else
EntityOperation.queue(context, data.draft, EntityOperation.BODY);
@ -4593,11 +4597,13 @@ public class FragmentCompose extends FragmentBase {
Helper.writeText(draft.getFile(context), body);
String full = HtmlHelper.getFullText(body);
String preview = HtmlHelper.getPreviewText(full);
db.message().setMessageContent(draft.id,
true,
HtmlHelper.getLanguage(context, body),
HtmlHelper.getLanguage(context, full),
draft.plain_only, // unchanged
HtmlHelper.getPreview(body),
preview,
null);
db.message().setMessageRevision(draft.id, draft.revision);

@ -1709,14 +1709,13 @@ public class HtmlHelper {
Log.d(document.head().html());
}
static String getLanguage(Context context, String body) {
static String getLanguage(Context context, String text) {
try {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean language_detection = prefs.getBoolean("language_detection", false);
if (!language_detection)
return null;
String text = getFullText(body);
Locale locale = TextHelper.detectLanguage(context, text);
return (locale == null ? null : locale.getLanguage());
} catch (Throwable ex) {
@ -1725,25 +1724,22 @@ public class HtmlHelper {
}
}
static String getPreview(String body) {
try {
if (body == null)
return null;
Document d = JsoupEx.parse(body);
return _getText(d, false);
} catch (OutOfMemoryError ex) {
Log.e(ex);
static String getPreviewText(String text) {
if (text == null)
return null;
}
String preview = text
.replace("\u200C", "") // Zero-width non-joiner
.replaceAll("\\s+", " ");
return truncate(preview, PREVIEW_SIZE);
}
@Deprecated
static String getFullText(String body) {
try {
if (body == null)
return null;
Document d = JsoupEx.parse(body);
return _getText(d, true);
return _getText(d);
} catch (OutOfMemoryError ex) {
Log.e(ex);
return null;
@ -1753,29 +1749,22 @@ public class HtmlHelper {
static String getFullText(File file) throws IOException {
try {
Document d = JsoupEx.parse(file);
return _getText(d, true);
return _getText(d);
} catch (OutOfMemoryError ex) {
Log.e(ex);
return null;
}
}
private static String _getText(Document d, boolean full) {
truncate(d, !full);
private static String _getText(Document d) {
truncate(d, false);
for (Element bq : d.select("blockquote")) {
bq.prependChild(new TextNode("["));
bq.appendChild(new TextNode("]"));
}
String text = d.text();
if (full)
return text;
String preview = text
.replace("\u200C", "") // Zero-width non-joiner
.replaceAll("\\s+", " ");
return truncate(preview, PREVIEW_SIZE);
return d.text();
}
static String truncate(String text, int at) {

@ -1251,12 +1251,7 @@ public class Log {
File file = draft.getFile(context);
Helper.writeText(file, body);
db.message().setMessageContent(draft.id,
true,
HtmlHelper.getLanguage(context, body),
false,
HtmlHelper.getPreview(body),
null);
db.message().setMessageContent(draft.id, true, null, false, null, null);
attachSettings(context, draft.id, 1);
attachAccounts(context, draft.id, 2);

@ -538,8 +538,9 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
if (plain != null && plain)
body = body.replace("<div x-plain=\"true\">", "<div>");
String language = HtmlHelper.getLanguage(this, body);
String preview = HtmlHelper.getPreview(body);
String text = HtmlHelper.getFullText(body);
String language = HtmlHelper.getLanguage(this, text);
String preview = HtmlHelper.getPreviewText(text);
try {
db.beginTransaction();

@ -288,8 +288,9 @@ public class ServiceUI extends IntentService {
if (body != null)
body = "<p>" + body.replaceAll("\\r?\\n", "<br>") + "</p>";
String language = HtmlHelper.getLanguage(this, body);
String preview = HtmlHelper.getPreview(body);
String text = HtmlHelper.getFullText(body);
String language = HtmlHelper.getLanguage(this, text);
String preview = HtmlHelper.getPreviewText(text);
DB db = DB.getInstance(this);
try {

Loading…
Cancel
Save