Show body size

pull/162/head
M66B 5 years ago
parent b3f34ec0c9
commit 23df3a100a

File diff suppressed because it is too large Load Diff

@ -1098,8 +1098,13 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (!message.duplicate)
tvSizeEx.setAlpha(message.content ? 1.0f : Helper.LOW_LIGHT);
tvSizeExTitle.setVisibility(!show_addresses || message.size == null ? View.GONE : View.VISIBLE);
tvSizeEx.setVisibility(!show_addresses || message.size == null ? View.GONE : View.VISIBLE);
tvSizeEx.setText(message.size == null ? null : Helper.humanReadableByteCount(message.size, true));
tvSizeEx.setVisibility(!show_addresses || (message.size == null && message.total == null) ? View.GONE : View.VISIBLE);
StringBuilder size = new StringBuilder();
size
.append(message.size == null ? "-" : Helper.humanReadableByteCount(message.size, true))
.append("/")
.append(message.total == null ? "-" : Helper.humanReadableByteCount(message.total, true));
tvSizeEx.setText(size.toString());
tvSubjectEx.setVisibility(show_addresses ? View.VISIBLE : View.GONE);
tvSubjectEx.setText(message.subject);
@ -3531,6 +3536,10 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
same = false;
Log.i("size changed id=" + next.id);
}
if (!Objects.equals(prev.total, next.total)) {
same = false;
Log.i("total changed id=" + next.id);
}
if (!Objects.equals(prev.attachments, next.attachments)) {
same = false;
Log.i("attachments changed id=" + next.id);

@ -1438,7 +1438,8 @@ class Core {
message.list_post = helper.getListPost();
message.unsubscribe = helper.getListUnsubscribe();
message.subject = helper.getSubject();
message.size = helper.getSize();
message.size = parts.getBodySize();
message.total = helper.getSize();
message.content = false;
message.received = helper.getReceived();
message.sent = helper.getSent();
@ -2008,9 +2009,6 @@ class Core {
dup.uid = uid;
dup.thread = thread;
if (dup.size == null)
dup.size = helper.getSize();
if (EntityFolder.SENT.equals(folder.type)) {
dup.received = helper.getReceived();
dup.sent = helper.getSent();
@ -2057,7 +2055,8 @@ class Core {
message.list_post = helper.getListPost();
message.unsubscribe = helper.getListUnsubscribe();
message.subject = helper.getSubject();
message.size = helper.getSize();
message.size = parts.getBodySize();
message.total = helper.getSize();
message.content = false;
message.received = helper.getReceived();
message.sent = helper.getSent();

@ -58,7 +58,7 @@ import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 105,
version = 106,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -1041,6 +1041,14 @@ public abstract class DB extends RoomDatabase {
db.execSQL("ALTER TABLE `message` ADD COLUMN `priority` INTEGER");
}
})
.addMigrations(new Migration(105, 106) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
Log.i("DB migration from version " + startVersion + " to " + endVersion);
db.execSQL("ALTER TABLE `message` ADD COLUMN `total` INTEGER");
db.execSQL("UPDATE `message` SET total = size");
}
})
.build();
}

@ -52,7 +52,7 @@ public interface DaoMessage {
", SUM(1 - message.ui_flagged) AS unflagged" +
", SUM(CASE WHEN folder.type = '" + EntityFolder.DRAFTS + "' THEN 1 ELSE 0 END) AS drafts" +
", COUNT(DISTINCT CASE WHEN message.msgid IS NULL THEN message.id ELSE message.msgid END) AS visible" +
", SUM(message.size) AS totalSize" +
", SUM(message.total) AS totalSize" +
", MAX(CASE WHEN" +
" ((:found AND folder.type <> '" + EntityFolder.ARCHIVE + "' AND folder.type <> '" + EntityFolder.DRAFTS + "')" +
" OR (NOT :found AND :type IS NULL AND folder.unified)" +
@ -101,7 +101,7 @@ public interface DaoMessage {
", SUM(1 - message.ui_flagged) AS unflagged" +
", SUM(CASE WHEN folder.type = '" + EntityFolder.DRAFTS + "' THEN 1 ELSE 0 END) AS drafts" +
", COUNT(DISTINCT CASE WHEN message.msgid IS NULL THEN message.id ELSE message.msgid END) AS visible" +
", SUM(message.size) AS totalSize" +
", SUM(message.total) AS totalSize" +
", MAX(CASE WHEN folder.id = :folder THEN message.received ELSE 0 END) AS dummy" +
" FROM (SELECT * FROM message ORDER BY received DESC) AS message" +
" JOIN account ON account.id = message.account" +
@ -144,7 +144,7 @@ public interface DaoMessage {
", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" +
", CASE WHEN folder.type = '" + EntityFolder.DRAFTS + "' THEN 1 ELSE 0 END AS drafts" +
", 1 AS visible" +
", message.size AS totalSize" +
", message.total AS totalSize" +
" FROM message" +
" JOIN account ON account.id = message.account" +
" LEFT JOIN identity ON identity.id = message.identity" +
@ -244,7 +244,7 @@ public interface DaoMessage {
", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" +
", CASE WHEN folder.type = '" + EntityFolder.DRAFTS + "' THEN 1 ELSE 0 END AS drafts" +
", 1 AS visible" +
", message.size AS totalSize" +
", message.total AS totalSize" +
" FROM message" +
" JOIN account ON account.id = message.account" +
" LEFT JOIN identity ON identity.id = message.identity" +
@ -277,7 +277,7 @@ public interface DaoMessage {
", 0 AS unflagged" +
", 0 AS drafts" +
", 1 AS visible" +
", message.size AS totalSize" +
", message.total AS totalSize" +
" FROM message" +
" JOIN account ON account.id = message.account" +
" LEFT JOIN identity ON identity.id = message.identity" +
@ -421,8 +421,8 @@ public interface DaoMessage {
@Query("UPDATE message SET content = :content, plain_only = :plain_only, preview = :preview, warning = :warning WHERE id = :id")
int setMessageContent(long id, boolean content, Boolean plain_only, String preview, String warning);
@Query("UPDATE message SET size = :size WHERE id = :id")
int setMessageSize(long id, Long size);
@Query("UPDATE message SET size = :size, total = :total WHERE id = :id")
int setMessageSize(long id, Long size, Long total);
@Query("UPDATE message SET headers = :headers WHERE id = :id")
int setMessageHeaders(long id, String headers);

@ -118,6 +118,7 @@ public class EntityMessage implements Serializable {
public Boolean raw;
public String subject;
public Long size;
public Long total;
@NonNull
public Integer attachments = 0; // performance
@NonNull
@ -279,6 +280,7 @@ public class EntityMessage implements Serializable {
Objects.equals(this.raw, other.raw) &&
Objects.equals(this.subject, other.subject) &&
Objects.equals(this.size, other.size) &&
Objects.equals(this.total, other.total) &&
Objects.equals(this.attachments, other.attachments) &&
this.content == other.content &&
Objects.equals(this.plain_only, other.plain_only) &&

@ -225,7 +225,7 @@ public class EntityOperation {
} catch (IOException ex) {
Log.e(ex);
db.message().setMessageContent(tmpid, false, null, null, null);
db.message().setMessageSize(message.id, null);
db.message().setMessageSize(message.id, null, null);
}
EntityAttachment.copy(context, message.id, tmpid);

@ -892,6 +892,17 @@ public class MessageHelper {
return (html == null);
}
Long getBodySize() throws MessagingException {
Part part = (html == null ? plain : html);
if (part == null)
return null;
int size = part.getSize();
if (size < 0)
return null;
else
return (long) size;
}
String getHtml(Context context) throws MessagingException, IOException {
if (plain == null && html == null) {
Log.i("No body part");

@ -419,6 +419,13 @@ public class ServiceSend extends ServiceBase {
HtmlHelper.getPreview(body),
parts.getWarnings(message.warning));
Long total = null;
List<EntityAttachment> attachments = db.attachment().getAttachments(sid);
for (EntityAttachment attachment : attachments)
if (attachment.size != null)
total = (total == null ? 0 : total) + attachment.size;
db.message().setMessageSize(sid, (long) body.length(), total);
db.message().setMessageSent(sid, time);
db.message().setMessageUiHide(sid, false);

Loading…
Cancel
Save