Allow resizing of inline and attached images separately

pull/172/head
M66B 6 years ago
parent ff7a181dad
commit 830f2b311d

@ -196,6 +196,14 @@ public class ApplicationEx extends Application {
prefs.getBoolean("experiments", false)) prefs.getBoolean("experiments", false))
editor.putBoolean("quick_filter", true); editor.putBoolean("quick_filter", true);
editor.remove("experiments"); 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) { if (BuildConfig.DEBUG && false) {

@ -2508,11 +2508,14 @@ public class FragmentCompose extends FragmentBase {
private static void resizeAttachment(Context context, EntityAttachment attachment) throws IOException { private static void resizeAttachment(Context context, EntityAttachment attachment) throws IOException {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); 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); 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))) { ("image/jpeg".equals(attachment.type) || "image/png".equals(attachment.type))) {
BitmapFactory.Options options = new BitmapFactory.Options(); BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; options.inJustDecodeBounds = true;

@ -52,7 +52,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
private SwitchCompat swQuoteReply; private SwitchCompat swQuoteReply;
private SwitchCompat swPlainOnly; private SwitchCompat swPlainOnly;
private SwitchCompat swUsenetSignature; private SwitchCompat swUsenetSignature;
private SwitchCompat swAutoResize; private SwitchCompat swResizeImages;
private SwitchCompat swResizeAttachments;
private Spinner spAutoResize; private Spinner spAutoResize;
private TextView tvAutoResize; private TextView tvAutoResize;
private SwitchCompat swReceipt; private SwitchCompat swReceipt;
@ -63,7 +64,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
"keyboard", "suggest_sent", "suggested_received", "keyboard", "suggest_sent", "suggested_received",
"prefix_once", "extended_reply", "quote_reply", "prefix_once", "extended_reply", "quote_reply",
"plain_only", "usenet_signature", "plain_only", "usenet_signature",
"autoresize", "receipt_default", "resize", "lookup_mx", "send_delayed" "resize_images", "resize_attachments", "receipt_default", "resize", "lookup_mx", "send_delayed"
}; };
@Override @Override
@ -85,7 +86,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
swQuoteReply = view.findViewById(R.id.swQuoteReply); swQuoteReply = view.findViewById(R.id.swQuoteReply);
swPlainOnly = view.findViewById(R.id.swPlainOnly); swPlainOnly = view.findViewById(R.id.swPlainOnly);
swUsenetSignature = view.findViewById(R.id.swUsenetSignature); 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); spAutoResize = view.findViewById(R.id.spAutoResize);
tvAutoResize = view.findViewById(R.id.tvAutoResize); tvAutoResize = view.findViewById(R.id.tvAutoResize);
swReceipt = view.findViewById(R.id.swReceipt); 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 @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("autoresize", checked).apply(); prefs.edit().putBoolean("resize_images", checked).apply();
spAutoResize.setEnabled(checked); }
});
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); int[] values = getResources().getIntArray(R.array.resizeValues);
prefs.edit().putInt("resize", values[position]).apply(); prefs.edit().putInt("resize", values[position]).apply();
tvAutoResize.setText(getString(R.string.title_advanced_resize_pixels, values[position])); tvAutoResize.setText(getString(R.string.title_advanced_resize_pixels, values[position]));
spAutoResize.setEnabled(swResizeImages.isChecked() || swResizeAttachments.isChecked());
} }
@Override @Override
@ -266,7 +276,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc
swPlainOnly.setChecked(prefs.getBoolean("plain_only", false)); swPlainOnly.setChecked(prefs.getBoolean("plain_only", false));
swUsenetSignature.setChecked(prefs.getBoolean("usenet_signature", 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 resize = prefs.getInt("resize", FragmentCompose.REDUCED_IMAGE_SIZE);
int[] resizeValues = getResources().getIntArray(R.array.resizeValues); 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])); tvAutoResize.setText(getString(R.string.title_advanced_resize_pixels, resizeValues[pos]));
break; break;
} }
spAutoResize.setEnabled(swAutoResize.isChecked()); spAutoResize.setEnabled(swResizeImages.isChecked() || swResizeAttachments.isChecked());
swReceipt.setChecked(prefs.getBoolean("receipt_default", false)); swReceipt.setChecked(prefs.getBoolean("receipt_default", false));
swLookupMx.setChecked(prefs.getBoolean("lookup_mx", false)); swLookupMx.setChecked(prefs.getBoolean("lookup_mx", false));

@ -142,17 +142,29 @@
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat <androidx.appcompat.widget.SwitchCompat
android:id="@+id/swAutoResize" android:id="@+id/swResizeImages"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:checked="true" android:checked="true"
android:text="@string/title_advanced_autoresize" android:text="@string/title_advanced_resize_images"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swUsenetSignature" app:layout_constraintTop_toBottomOf="@id/swUsenetSignature"
app:switchPadding="12dp" /> app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swResizeAttachments"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:checked="true"
android:text="@string/title_advanced_resize_attachments"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swResizeImages"
app:switchPadding="12dp" />
<Spinner <Spinner
android:id="@+id/spAutoResize" android:id="@+id/spAutoResize"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -160,7 +172,7 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:entries="@array/resizeNames" android:entries="@array/resizeNames"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swAutoResize" /> app:layout_constraintTop_toBottomOf="@id/swResizeAttachments" />
<TextView <TextView
android:id="@+id/tvAutoResize" android:id="@+id/tvAutoResize"

@ -256,7 +256,8 @@
<string name="title_advanced_quote_reply">Quote replied text</string> <string name="title_advanced_quote_reply">Quote replied text</string>
<string name="title_advanced_plain_only">Send plain text only by default</string> <string name="title_advanced_plain_only">Send plain text only by default</string>
<string name="title_advanced_usenet_signature">Usenet signature convention</string> <string name="title_advanced_usenet_signature">Usenet signature convention</string>
<string name="title_advanced_autoresize">Automatically resize attached and embedded images</string> <string name="title_advanced_resize_images">Automatically resize embedded images</string>
<string name="title_advanced_resize_attachments">Automatically resize image attachments</string>
<string name="title_advanced_resize_pixels">&lt; %1$d pixels</string> <string name="title_advanced_resize_pixels">&lt; %1$d pixels</string>
<string name="title_advanced_lookup_mx">Check recipient email addresses before sending</string> <string name="title_advanced_lookup_mx">Check recipient email addresses before sending</string>
<string name="title_advanced_send_delayed">Delay sending messages</string> <string name="title_advanced_send_delayed">Delay sending messages</string>

Loading…
Cancel
Save