Prevent reload on download change

pull/147/head
M66B 6 years ago
parent 27686c9a8b
commit e7fac3cbcb

@ -47,11 +47,6 @@ public interface DaoFolder {
" WHERE account.synchronize AND folder.synchronize AND unified") " WHERE account.synchronize AND folder.synchronize AND unified")
List<EntityFolder> getFoldersSynchronizingUnified(); List<EntityFolder> getFoldersSynchronizingUnified();
@Query("SELECT * FROM folder" +
" WHERE account = :account" +
" AND type = '" + EntityFolder.USER + "'")
List<EntityFolder> getUserFolders(long account);
@Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor, account.state AS accountState" + @Query("SELECT folder.*, account.name AS accountName, account.color AS accountColor, account.state AS accountState" +
", COUNT(message.id) AS messages" + ", COUNT(message.id) AS messages" +
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" + ", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +
@ -140,6 +135,9 @@ public interface DaoFolder {
@Query("SELECT * FROM folder WHERE type = '" + EntityFolder.OUTBOX + "'") @Query("SELECT * FROM folder WHERE type = '" + EntityFolder.OUTBOX + "'")
EntityFolder getOutbox(); EntityFolder getOutbox();
@Query("SELECT download FROM folder WHERE id = :id")
boolean getFolderDownload(long id);
@Insert @Insert
long insertFolder(EntityFolder folder); long insertFolder(EntityFolder folder);

@ -96,6 +96,7 @@ public class EntityOperation {
JSONArray jargs = new JSONArray(); JSONArray jargs = new JSONArray();
jargs.put(folder.initialize ? Math.min(EntityFolder.DEFAULT_INIT, folder.keep_days) : folder.sync_days); jargs.put(folder.initialize ? Math.min(EntityFolder.DEFAULT_INIT, folder.keep_days) : folder.sync_days);
jargs.put(folder.keep_days); jargs.put(folder.keep_days);
jargs.put(folder.download);
EntityOperation operation = new EntityOperation(); EntityOperation operation = new EntityOperation();
operation.folder = folder.id; operation.folder = folder.id;

@ -202,8 +202,7 @@ public class FragmentFolder extends FragmentEx {
db.folder().insertFolder(create); db.folder().insertFolder(create);
} else { } else {
reload = (!folder.synchronize.equals(synchronize) || reload = (!folder.synchronize.equals(synchronize) ||
!folder.poll.equals(poll) || !folder.poll.equals(poll));
!folder.download.equals(download));
Calendar cal_keep = Calendar.getInstance(); Calendar cal_keep = Calendar.getInstance();
cal_keep.add(Calendar.DAY_OF_MONTH, -keep_days); cal_keep.add(Calendar.DAY_OF_MONTH, -keep_days);

@ -986,7 +986,8 @@ public class ServiceSynchronize extends LifecycleService {
try { try {
db.beginTransaction(); db.beginTransaction();
downloadMessage(ServiceSynchronize.this, downloadMessage(ServiceSynchronize.this,
folder, ifolder, (IMAPMessage) imessage, message.id); folder, ifolder, (IMAPMessage) imessage,
message.id, db.folder().getFolderDownload(folder.id));
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
db.endTransaction(); db.endTransaction();
@ -1072,7 +1073,8 @@ public class ServiceSynchronize extends LifecycleService {
try { try {
db.beginTransaction(); db.beginTransaction();
downloadMessage(ServiceSynchronize.this, downloadMessage(ServiceSynchronize.this,
folder, ifolder, (IMAPMessage) e.getMessage(), message.id); folder, ifolder, (IMAPMessage) e.getMessage(),
message.id, db.folder().getFolderDownload(folder.id));
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} finally { } finally {
db.endTransaction(); db.endTransaction();
@ -2016,6 +2018,7 @@ public class ServiceSynchronize extends LifecycleService {
try { try {
int sync_days = jargs.getInt(0); int sync_days = jargs.getInt(0);
int keep_days = jargs.getInt(1); int keep_days = jargs.getInt(1);
boolean download = jargs.getBoolean(2);
Log.i(folder.name + " start sync after=" + sync_days + "/" + keep_days); Log.i(folder.name + " start sync after=" + sync_days + "/" + keep_days);
@ -2127,7 +2130,8 @@ public class ServiceSynchronize extends LifecycleService {
db.beginTransaction(); db.beginTransaction();
EntityMessage message = synchronizeMessage( EntityMessage message = synchronizeMessage(
this, this,
folder, ifolder, (IMAPMessage) isub[j], false, true); folder, ifolder, (IMAPMessage) isub[j],
false, true);
ids[from + j] = message.id; ids[from + j] = message.id;
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (MessageRemovedException ex) { } catch (MessageRemovedException ex) {
@ -2173,7 +2177,10 @@ public class ServiceSynchronize extends LifecycleService {
try { try {
db.beginTransaction(); db.beginTransaction();
if (ids[from + j] != null) if (ids[from + j] != null)
downloadMessage(this, folder, ifolder, (IMAPMessage) isub[j], ids[from + j]); downloadMessage(
this,
folder, ifolder, (IMAPMessage) isub[j],
ids[from + j], download);
db.setTransactionSuccessful(); db.setTransactionSuccessful();
} catch (FolderClosedException ex) { } catch (FolderClosedException ex) {
throw ex; throw ex;
@ -2426,7 +2433,10 @@ public class ServiceSynchronize extends LifecycleService {
return message; return message;
} }
private static void downloadMessage(Context context, EntityFolder folder, IMAPFolder ifolder, IMAPMessage imessage, long id) throws MessagingException, IOException { private static void downloadMessage(
Context context,
EntityFolder folder, IMAPFolder ifolder, IMAPMessage imessage,
long id, boolean download) throws MessagingException, IOException {
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id); EntityMessage message = db.message().getMessage(id);
if (message == null) if (message == null)
@ -2435,11 +2445,11 @@ public class ServiceSynchronize extends LifecycleService {
if (message.setContactInfo(context)) if (message.setContactInfo(context))
db.message().updateMessage(message); db.message().updateMessage(message);
if (folder.download) { if (download) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
long download = prefs.getInt("download", 32768); long maxSize = prefs.getInt("download", 32768);
if (download == 0) if (maxSize == 0)
download = Long.MAX_VALUE; maxSize = Long.MAX_VALUE;
List<EntityAttachment> attachments = db.attachment().getAttachments(message.id); List<EntityAttachment> attachments = db.attachment().getAttachments(message.id);
MessageHelper helper = new MessageHelper(imessage); MessageHelper helper = new MessageHelper(imessage);
@ -2448,13 +2458,13 @@ public class ServiceSynchronize extends LifecycleService {
boolean fetch = false; boolean fetch = false;
if (!message.content) if (!message.content)
if (!metered || (message.size != null && message.size < download)) if (!metered || (message.size != null && message.size < maxSize))
fetch = true; fetch = true;
if (!fetch) if (!fetch)
for (EntityAttachment attachment : attachments) for (EntityAttachment attachment : attachments)
if (!attachment.available) if (!attachment.available)
if (!metered || (attachment.size != null && attachment.size < download)) { if (!metered || (attachment.size != null && attachment.size < maxSize)) {
fetch = true; fetch = true;
break; break;
} }
@ -2474,7 +2484,7 @@ public class ServiceSynchronize extends LifecycleService {
} }
if (!message.content) if (!message.content)
if (!metered || (message.size != null && message.size < download)) { if (!metered || (message.size != null && message.size < maxSize)) {
String body = helper.getHtml(); String body = helper.getHtml();
message.write(context, body); message.write(context, body);
db.message().setMessageContent( db.message().setMessageContent(
@ -2486,7 +2496,7 @@ public class ServiceSynchronize extends LifecycleService {
for (int i = 0; i < attachments.size(); i++) { for (int i = 0; i < attachments.size(); i++) {
EntityAttachment attachment = attachments.get(i); EntityAttachment attachment = attachments.get(i);
if (!attachment.available) if (!attachment.available)
if (!metered || (attachment.size != null && attachment.size < download)) { if (!metered || (attachment.size != null && attachment.size < maxSize)) {
if (iattachments == null) if (iattachments == null)
iattachments = helper.getAttachments(); iattachments = helper.getAttachments();
// Attachments of drafts might not have been uploaded yet // Attachments of drafts might not have been uploaded yet

Loading…
Cancel
Save