From ef890934e2f0fe613e1689936ca90ca9a705a69b Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 5 Oct 2019 12:42:04 +0200 Subject: [PATCH] Small improvements --- .../eu/faircode/email/AdapterAttachment.java | 4 +- .../java/eu/faircode/email/AdapterImage.java | 13 ++++-- .../eu/faircode/email/AdapterMessage.java | 43 ++++++++++++------- .../eu/faircode/email/EntityOperation.java | 3 ++ 4 files changed, 42 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterAttachment.java b/app/src/main/java/eu/faircode/email/AdapterAttachment.java index 14ed2eaf72..844b2b2698 100644 --- a/app/src/main/java/eu/faircode/email/AdapterAttachment.java +++ b/app/src/main/java/eu/faircode/email/AdapterAttachment.java @@ -267,7 +267,9 @@ public class AdapterAttachment extends RecyclerView.Adapter @Override protected Void onExecute(Context context, Bundle args) { long id = args.getLong("id"); - long message = args.getLong("message"); + long mid = args.getLong("message"); DB db = DB.getInstance(context); try { db.beginTransaction(); - db.attachment().setProgress(id, 0); + EntityMessage message = db.message().getMessage(mid); + if (message == null || message.uid == null) + return null; - EntityMessage msg = db.message().getMessage(message); - EntityOperation.queue(context, msg, EntityOperation.ATTACHMENT, id); + EntityAttachment attachment = db.attachment().getAttachment(id); + if (attachment == null || attachment.progress != null || attachment.available) + return null; + + EntityOperation.queue(context, message, EntityOperation.ATTACHMENT, id); db.setTransactionSuccessful(); } finally { diff --git a/app/src/main/java/eu/faircode/email/AdapterMessage.java b/app/src/main/java/eu/faircode/email/AdapterMessage.java index c593fdf90f..ba9070aa62 100644 --- a/app/src/main/java/eu/faircode/email/AdapterMessage.java +++ b/app/src/main/java/eu/faircode/email/AdapterMessage.java @@ -2458,19 +2458,19 @@ public class AdapterMessage extends RecyclerView.Adapter() { @Override protected Void onExecute(Context context, Bundle args) { - long id = args.getLong("id"); + long mid = args.getLong("id"); DB db = DB.getInstance(context); try { db.beginTransaction(); - EntityMessage msg = db.message().getMessage(id); - if (msg != null) - for (EntityAttachment attachment : db.attachment().getAttachments(message.id)) - if (attachment.progress == null && !attachment.available) { - db.attachment().setProgress(attachment.id, 0); - EntityOperation.queue(context, msg, EntityOperation.ATTACHMENT, attachment.id); - } + EntityMessage message = db.message().getMessage(mid); + if (message == null || message.uid == null) + return null; + + for (EntityAttachment attachment : db.attachment().getAttachments(message.id)) + if (attachment.progress == null && !attachment.available) + EntityOperation.queue(context, message, EntityOperation.ATTACHMENT, attachment.id); db.setTransactionSuccessful(); } finally { @@ -2621,7 +2621,8 @@ public class AdapterMessage extends RecyclerView.Adapter attachments = db.attachment().getAttachments(message.id); for (EntityAttachment attachment : attachments) - if (!attachment.available && attachment.isInline() && attachment.isImage()) + if (attachment.isInline() && attachment.isImage() && + attachment.progress == null && !attachment.available) EntityOperation.queue(context, message, EntityOperation.ATTACHMENT, attachment.id); db.setTransactionSuccessful(); @@ -3724,12 +3725,18 @@ public class AdapterMessage extends RecyclerView.Adapter