Save memory on previewing

pull/174/head
M66B 5 years ago
parent 88f5a3ec86
commit 232f2726bb

@ -1124,11 +1124,12 @@ class Core {
MessageHelper helper = new MessageHelper((MimeMessage) imessage);
MessageHelper.MessageParts parts = helper.getMessageParts(context);
String body = parts.getHtml(context);
Helper.writeText(message.getFile(context), body);
File file = message.getFile(context);
Helper.writeText(file, body);
db.message().setMessageContent(message.id,
true,
parts.isPlainOnly(),
HtmlHelper.getPreview(body),
HtmlHelper.getPreview(file),
parts.getWarnings(message.warning));
}
@ -1577,11 +1578,12 @@ class Core {
}
String body = parts.getHtml(context);
Helper.writeText(message.getFile(context), body);
File file = message.getFile(context);
Helper.writeText(file, body);
db.message().setMessageContent(message.id,
true,
parts.isPlainOnly(),
HtmlHelper.getPreview(body),
HtmlHelper.getPreview(file),
parts.getWarnings(message.warning));
for (EntityAttachment attachment : parts.getAttachments())
@ -2316,11 +2318,12 @@ class Core {
if (message.size < maxSize) {
String body = parts.getHtml(context);
Helper.writeText(message.getFile(context), body);
File file = message.getFile(context);
Helper.writeText(file, body);
db.message().setMessageContent(message.id,
true,
parts.isPlainOnly(),
HtmlHelper.getPreview(body),
HtmlHelper.getPreview(file),
parts.getWarnings(message.warning));
Log.i(folder.name + " inline downloaded message id=" + message.id +
" size=" + message.size + "/" + (body == null ? null : body.length()));
@ -2649,11 +2652,12 @@ class Core {
if (state.getNetworkState().isUnmetered() ||
(message.size != null && message.size < maxSize)) {
String body = parts.getHtml(context);
Helper.writeText(message.getFile(context), body);
File file = message.getFile(context);
Helper.writeText(file, body);
db.message().setMessageContent(message.id,
true,
parts.isPlainOnly(),
HtmlHelper.getPreview(body),
HtmlHelper.getPreview(file),
parts.getWarnings(message.warning));
Log.i(folder.name + " downloaded message id=" + message.id +
" size=" + message.size + "/" + (body == null ? null : body.length()));
@ -3212,8 +3216,8 @@ class Core {
String preview = message.preview;
if (notify_preview_all)
try {
String html = Helper.readText(message.getFile(context));
preview = HtmlHelper.getFullText(html);
File file = message.getFile(context);
preview = HtmlHelper.getFullText(file);
} catch (Throwable ex) {
Log.e(ex);
}

@ -35,6 +35,7 @@ import androidx.room.PrimaryKey;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
@ -411,11 +412,12 @@ public class EntityRule {
reply.id = db.message().insertMessage(reply);
String body = answer.getText(message.from);
Helper.writeText(reply.getFile(context), body);
File file = reply.getFile(context);
Helper.writeText(file, body);
db.message().setMessageContent(reply.id,
true,
false,
HtmlHelper.getPreview(body),
HtmlHelper.getPreview(file),
null);
EntityOperation.queue(context, reply, EntityOperation.SEND);

@ -1056,30 +1056,53 @@ public class HtmlHelper {
Log.i(document.head().html());
}
static String getPreview(File file) throws IOException {
try {
Document d = JsoupEx.parse(file);
return _getText(d, false);
} catch (OutOfMemoryError ex) {
Log.e(ex);
return null;
}
}
@Deprecated
static String getPreview(String body) {
try {
return _getText(body, false);
if (body == null)
return null;
Document d = JsoupEx.parse(body);
return _getText(d, false);
} catch (OutOfMemoryError ex) {
Log.e(ex);
return null;
}
}
@Deprecated
static String getFullText(String body) {
try {
return _getText(body, true);
if (body == null)
return null;
Document d = JsoupEx.parse(body);
return _getText(d, true);
} catch (OutOfMemoryError ex) {
Log.e(ex);
return null;
}
}
private static String _getText(String body, boolean full) {
if (body == null)
static String getFullText(File file) throws IOException {
try {
Document d = JsoupEx.parse(file);
return _getText(d, true);
} catch (OutOfMemoryError ex) {
Log.e(ex);
return null;
}
}
Document d = JsoupEx.parse(body);
private static String _getText(Document d, boolean full) {
truncate(d, !full);
String text = d.text();

@ -701,11 +701,13 @@ public class Log {
draft.seen = true;
draft.ui_seen = true;
draft.id = db.message().insertMessage(draft);
Helper.writeText(draft.getFile(context), body);
File file = draft.getFile(context);
Helper.writeText(file, body);
db.message().setMessageContent(draft.id,
true,
false,
HtmlHelper.getPreview(body),
HtmlHelper.getPreview(file),
null);
attachSettings(context, draft.id, 1);

@ -39,6 +39,7 @@ import androidx.core.content.ContextCompat;
import androidx.lifecycle.Observer;
import androidx.preference.PreferenceManager;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
@ -392,11 +393,12 @@ public class ServiceSend extends ServiceBase {
message.error = null;
message.id = db.message().insertMessage(message);
Helper.writeText(EntityMessage.getFile(this, message.id), body);
File file = EntityMessage.getFile(this, message.id);
Helper.writeText(file, body);
db.message().setMessageContent(message.id,
true,
parts.isPlainOnly(),
HtmlHelper.getPreview(body),
HtmlHelper.getPreview(file),
parts.getWarnings(message.warning));
EntityAttachment.copy(this, id, message.id);

@ -34,6 +34,7 @@ import androidx.core.app.AlarmManagerCompat;
import androidx.core.app.RemoteInput;
import androidx.preference.PreferenceManager;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.Date;
@ -278,11 +279,14 @@ public class ServiceUI extends IntentService {
reply.seen = true;
reply.ui_seen = true;
reply.id = db.message().insertMessage(reply);
Helper.writeText(reply.getFile(this), text);
File file = reply.getFile(this);
Helper.writeText(file, text);
db.message().setMessageContent(reply.id,
true,
plain_only || ref.plain_only,
HtmlHelper.getPreview(text),
HtmlHelper.getPreview(file),
null);
EntityOperation.queue(this, reply, EntityOperation.SEND);

@ -70,8 +70,7 @@ public class WorkerFts extends Worker {
Log.i("FTS index=" + message.id);
File file = message.getFile(getApplicationContext());
String html = Helper.readText(file);
String text = HtmlHelper.getFullText(html);
String text = HtmlHelper.getFullText(file);
try {
sdb.beginTransaction();
FtsDbHelper.insert(sdb, message, text);

Loading…
Cancel
Save