Prevent reload on download change

This commit is contained in:
M66B 2018-12-25 08:37:19 +00:00
parent 27686c9a8b
commit e7fac3cbcb
4 changed files with 28 additions and 20 deletions

View File

@ -47,11 +47,6 @@ public interface DaoFolder {
" WHERE account.synchronize AND folder.synchronize AND unified")
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" +
", COUNT(message.id) AS messages" +
", 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 + "'")
EntityFolder getOutbox();
@Query("SELECT download FROM folder WHERE id = :id")
boolean getFolderDownload(long id);
@Insert
long insertFolder(EntityFolder folder);

View File

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

View File

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

View File

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