From a0b735c4166bf9014662a961e03d2e13c0a62cd3 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 15 Apr 2020 08:52:01 +0200 Subject: [PATCH] Refactoring --- .../eu/faircode/email/AdapterAttachment.java | 2 +- .../java/eu/faircode/email/AdapterMessage.java | 3 ++- .../java/eu/faircode/email/EntityAttachment.java | 4 ++++ .../java/eu/faircode/email/FragmentCompose.java | 16 ++++++++-------- 4 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/AdapterAttachment.java b/app/src/main/java/eu/faircode/email/AdapterAttachment.java index 9e8482a00c..f0f4fa575f 100644 --- a/app/src/main/java/eu/faircode/email/AdapterAttachment.java +++ b/app/src/main/java/eu/faircode/email/AdapterAttachment.java @@ -146,7 +146,7 @@ public class AdapterAttachment extends RecyclerView.Adapter a = new ArrayList<>(); for (EntityAttachment attachment : attachments) { - boolean inline = ((attachment.isInline() && attachment.isImage()) || attachment.encryption != null); + boolean inline = (attachment.isEncryption() || + (attachment.isInline() && attachment.isImage())); if (inline) has_inline = true; if (attachment.progress == null && !attachment.available) diff --git a/app/src/main/java/eu/faircode/email/EntityAttachment.java b/app/src/main/java/eu/faircode/email/EntityAttachment.java index dc4e21bb4c..aad308da54 100644 --- a/app/src/main/java/eu/faircode/email/EntityAttachment.java +++ b/app/src/main/java/eu/faircode/email/EntityAttachment.java @@ -116,6 +116,10 @@ public class EntityAttachment { return IMAGE_TYPES.contains(getMimeType()); } + boolean isEncryption() { + return (encryption != null); + } + File getFile(Context context) { return getFile(context, id, name); } diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 3c4e7c225e..f907cf7b05 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -2001,7 +2001,7 @@ public class FragmentCompose extends FragmentBase { // Get/clean attachments List attachments = db.attachment().getAttachments(draft.id); for (EntityAttachment attachment : new ArrayList<>(attachments)) - if (attachment.encryption != null) { + if (attachment.isEncryption()) { db.attachment().deleteAttachment(attachment.id); attachments.remove(attachment); } @@ -3449,7 +3449,7 @@ public class FragmentCompose extends FragmentBase { int sequence = 0; List attachments = db.attachment().getAttachments(ref.id); for (EntityAttachment attachment : attachments) - if (attachment.encryption == null && + if (!attachment.isEncryption() && ("forward".equals(action) || "editasnew".equals(action) || (cid.contains(attachment.cid) || (attachment.isInline() && attachment.isImage())))) { @@ -3526,7 +3526,7 @@ public class FragmentCompose extends FragmentBase { List attachments = db.attachment().getAttachments(data.draft.id); for (EntityAttachment attachment : attachments) if (attachment.available) { - if (attachment.encryption == null) + if (!attachment.isEncryption()) last_available++; } else EntityOperation.queue(context, data.draft, EntityOperation.ATTACHMENT, attachment.id); @@ -3600,7 +3600,7 @@ public class FragmentCompose extends FragmentBase { boolean downloading = false; boolean inline_images = false; for (EntityAttachment attachment : attachments) { - if (attachment.encryption != null) + if (attachment.isEncryption()) continue; if (attachment.progress != null) downloading = true; @@ -3846,10 +3846,10 @@ public class FragmentCompose extends FragmentBase { List eparts = new ArrayList<>(); for (EntityAttachment attachment : attachments) if (attachment.available) - if (attachment.encryption == null) - available++; - else + if (attachment.isEncryption()) eparts.add(attachment.encryption); + else + available++; if (EntityMessage.PGP_SIGNONLY.equals(draft.ui_encrypt)) { if (!eparts.contains(EntityAttachment.PGP_KEY) || @@ -4063,7 +4063,7 @@ public class FragmentCompose extends FragmentBase { for (EntityAttachment attachment : attachments) if (!attachment.available) throw new IllegalArgumentException(context.getString(R.string.title_attachments_missing)); - else if (!attachment.isInline() && attachment.encryption == null) + else if (!attachment.isInline() && !attachment.isEncryption()) attached++; // Check for missing attachments