From 830f2b311dba9f133a3aaf52c25989077de352d0 Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 7 Jan 2020 15:49:34 +0100 Subject: [PATCH] Allow resizing of inline and attached images separately --- .../java/eu/faircode/email/ApplicationEx.java | 8 ++++++ .../eu/faircode/email/FragmentCompose.java | 7 +++-- .../faircode/email/FragmentOptionsSend.java | 27 +++++++++++++------ .../main/res/layout/fragment_options_send.xml | 18 ++++++++++--- app/src/main/res/values/strings.xml | 3 ++- 5 files changed, 49 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ApplicationEx.java b/app/src/main/java/eu/faircode/email/ApplicationEx.java index 5df49dbab4..6cdfa6659d 100644 --- a/app/src/main/java/eu/faircode/email/ApplicationEx.java +++ b/app/src/main/java/eu/faircode/email/ApplicationEx.java @@ -196,6 +196,14 @@ public class ApplicationEx extends Application { prefs.getBoolean("experiments", false)) editor.putBoolean("quick_filter", true); editor.remove("experiments"); + + } else if (version < 889) { + if (prefs.contains("autoresize")) { + boolean autoresize = prefs.getBoolean("autoresize", true); + editor.putBoolean("resize_images", autoresize); + editor.putBoolean("resize_attachments", autoresize); + editor.remove("autoresize"); + } } if (BuildConfig.DEBUG && false) { diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index b4f4293695..fd935470c7 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -2508,11 +2508,14 @@ public class FragmentCompose extends FragmentBase { private static void resizeAttachment(Context context, EntityAttachment attachment) throws IOException { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - boolean autoresize = prefs.getBoolean("autoresize", true); + boolean resize_images = prefs.getBoolean("resize_images", true); + boolean resize_attachments = prefs.getBoolean("resize_attachments", true); File file = attachment.getFile(context); - if (autoresize && file.exists() /* upload cancelled */ && + if (((resize_images && Part.INLINE.equals(attachment.disposition)) || + (resize_attachments && Part.ATTACHMENT.equals(attachment.disposition))) && + file.exists() /* upload cancelled */ && ("image/jpeg".equals(attachment.type) || "image/png".equals(attachment.type))) { BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java index 8b95cd7cf6..6f9238e502 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java @@ -52,7 +52,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc private SwitchCompat swQuoteReply; private SwitchCompat swPlainOnly; private SwitchCompat swUsenetSignature; - private SwitchCompat swAutoResize; + private SwitchCompat swResizeImages; + private SwitchCompat swResizeAttachments; private Spinner spAutoResize; private TextView tvAutoResize; private SwitchCompat swReceipt; @@ -63,7 +64,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc "keyboard", "suggest_sent", "suggested_received", "prefix_once", "extended_reply", "quote_reply", "plain_only", "usenet_signature", - "autoresize", "receipt_default", "resize", "lookup_mx", "send_delayed" + "resize_images", "resize_attachments", "receipt_default", "resize", "lookup_mx", "send_delayed" }; @Override @@ -85,7 +86,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc swQuoteReply = view.findViewById(R.id.swQuoteReply); swPlainOnly = view.findViewById(R.id.swPlainOnly); swUsenetSignature = view.findViewById(R.id.swUsenetSignature); - swAutoResize = view.findViewById(R.id.swAutoResize); + swResizeImages = view.findViewById(R.id.swResizeImages); + swResizeAttachments = view.findViewById(R.id.swResizeAttachments); spAutoResize = view.findViewById(R.id.spAutoResize); tvAutoResize = view.findViewById(R.id.tvAutoResize); swReceipt = view.findViewById(R.id.swReceipt); @@ -162,11 +164,18 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc } }); - swAutoResize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + swResizeImages.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - prefs.edit().putBoolean("autoresize", checked).apply(); - spAutoResize.setEnabled(checked); + prefs.edit().putBoolean("resize_images", checked).apply(); + } + }); + + swResizeAttachments.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + prefs.edit().putBoolean("resize_attachments", checked).apply(); + spAutoResize.setEnabled(swResizeImages.isChecked() || swResizeAttachments.isChecked()); } }); @@ -176,6 +185,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc int[] values = getResources().getIntArray(R.array.resizeValues); prefs.edit().putInt("resize", values[position]).apply(); tvAutoResize.setText(getString(R.string.title_advanced_resize_pixels, values[position])); + spAutoResize.setEnabled(swResizeImages.isChecked() || swResizeAttachments.isChecked()); } @Override @@ -266,7 +276,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc swPlainOnly.setChecked(prefs.getBoolean("plain_only", false)); swUsenetSignature.setChecked(prefs.getBoolean("usenet_signature", false)); - swAutoResize.setChecked(prefs.getBoolean("autoresize", true)); + swResizeImages.setChecked(prefs.getBoolean("resize_images", true)); + swResizeAttachments.setChecked(prefs.getBoolean("resize_attachments", true)); int resize = prefs.getInt("resize", FragmentCompose.REDUCED_IMAGE_SIZE); int[] resizeValues = getResources().getIntArray(R.array.resizeValues); @@ -276,7 +287,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc tvAutoResize.setText(getString(R.string.title_advanced_resize_pixels, resizeValues[pos])); break; } - spAutoResize.setEnabled(swAutoResize.isChecked()); + spAutoResize.setEnabled(swResizeImages.isChecked() || swResizeAttachments.isChecked()); swReceipt.setChecked(prefs.getBoolean("receipt_default", false)); swLookupMx.setChecked(prefs.getBoolean("lookup_mx", false)); diff --git a/app/src/main/res/layout/fragment_options_send.xml b/app/src/main/res/layout/fragment_options_send.xml index 6da82d740e..014dcd152c 100644 --- a/app/src/main/res/layout/fragment_options_send.xml +++ b/app/src/main/res/layout/fragment_options_send.xml @@ -142,17 +142,29 @@ app:switchPadding="12dp" /> + + + app:layout_constraintTop_toBottomOf="@id/swResizeAttachments" /> Quote replied text Send plain text only by default Usenet signature convention - Automatically resize attached and embedded images + Automatically resize embedded images + Automatically resize image attachments < %1$d pixels Check recipient email addresses before sending Delay sending messages