diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 5c5bc45cae..291d91bcd4 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -97,6 +97,7 @@ import androidx.constraintlayout.widget.Group; import androidx.core.content.FileProvider; import androidx.cursoradapter.widget.SimpleCursorAdapter; import androidx.documentfile.provider.DocumentFile; +import androidx.exifinterface.media.ExifInterface; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentTransaction; @@ -460,7 +461,7 @@ public class FragmentCompose extends FragmentBase { etBody.setInputContentListener(new EditTextCompose.IInputContentListener() { @Override public void onInputContent(Uri uri) { - onAddAttachment(Arrays.asList(uri), true, 0); + onAddAttachment(Arrays.asList(uri), true, 0, false); } }); @@ -1701,7 +1702,7 @@ public class FragmentCompose extends FragmentBase { case REQUEST_ATTACHMENT: case REQUEST_RECORD_AUDIO: if (resultCode == RESULT_OK && data != null) - onAddAttachment(getUris(data), false, 0); + onAddAttachment(getUris(data), false, 0, false); break; case REQUEST_OPENPGP: if (resultCode == RESULT_OK && data != null) @@ -1876,16 +1877,18 @@ public class FragmentCompose extends FragmentBase { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); boolean add_inline = prefs.getBoolean("add_inline", true); boolean resize_images = prefs.getBoolean("resize_images", true); + boolean privacy_images = prefs.getBoolean("privacy_images", false); int resize = prefs.getInt("resize", FragmentCompose.REDUCED_IMAGE_SIZE); - onAddAttachment(uri, add_inline, resize_images ? resize : 0); + onAddAttachment(uri, add_inline, resize_images ? resize : 0, privacy_images); } - private void onAddAttachment(List uris, boolean image, int resize) { + private void onAddAttachment(List uris, boolean image, int resize, boolean privacy) { Bundle args = new Bundle(); args.putLong("id", working); args.putParcelableArrayList("uris", new ArrayList<>(uris)); args.putBoolean("image", image); args.putInt("resize", resize); + args.putBoolean("privacy", privacy); args.putCharSequence("body", etBody.getText()); args.putInt("start", etBody.getSelectionStart()); @@ -1896,13 +1899,14 @@ public class FragmentCompose extends FragmentBase { List uris = args.getParcelableArrayList("uris"); boolean image = args.getBoolean("image"); int resize = args.getInt("resize"); + boolean privacy = args.getBoolean("privacy"); CharSequence body = args.getCharSequence("body"); int start = args.getInt("start"); SpannableStringBuilder s = new SpannableStringBuilder(body); for (Uri uri : uris) { - EntityAttachment attachment = addAttachment(context, id, uri, image, resize); + EntityAttachment attachment = addAttachment(context, id, uri, image, resize, privacy); if (!image) continue; @@ -2710,8 +2714,8 @@ public class FragmentCompose extends FragmentBase { } private static EntityAttachment addAttachment( - Context context, long id, Uri uri, boolean image, int resize) throws IOException { - Log.w("Add attachment uri=" + uri + " image=" + image + " resize=" + resize); + Context context, long id, Uri uri, boolean image, int resize, boolean privacy) throws IOException { + Log.w("Add attachment uri=" + uri + " image=" + image + " resize=" + resize + " privacy=" + privacy); if (!"content".equals(uri.getScheme()) && !Helper.hasPermission(context, Manifest.permission.READ_EXTERNAL_STORAGE)) { @@ -2832,6 +2836,20 @@ public class FragmentCompose extends FragmentBase { if (resize > 0) resizeAttachment(context, attachment, resize); + if (privacy) + try { + ExifInterface exif = new ExifInterface(file.getAbsolutePath()); + exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF, null); + exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, null); + exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF, null); + exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, null); + exif.setAttribute(ExifInterface.TAG_GPS_ALTITUDE_REF, null); + exif.setAttribute(ExifInterface.TAG_GPS_ALTITUDE, null); + exif.saveAttributes(); + } catch (IOException ex) { + Log.w(ex); + } + } catch (Throwable ex) { // Reset progress on failure Log.e(ex); @@ -3446,7 +3464,7 @@ public class FragmentCompose extends FragmentBase { if (uris != null) for (Uri uri : uris) try { - addAttachment(context, data.draft.id, uri, false, 0); + addAttachment(context, data.draft.id, uri, false, 0, false); } catch (IOException ex) { Log.e(ex); } @@ -4697,6 +4715,7 @@ public class FragmentCompose extends FragmentBase { boolean add_inline = prefs.getBoolean("add_inline", true); boolean resize_images = prefs.getBoolean("resize_images", true); int resize = prefs.getInt("resize", FragmentCompose.REDUCED_IMAGE_SIZE); + boolean privacy_images = prefs.getBoolean("privacy_images", false); boolean image_dialog = prefs.getBoolean("image_dialog", true); final ViewGroup dview = (ViewGroup) LayoutInflater.from(getContext()).inflate(R.layout.dialog_add_image, null); @@ -4704,12 +4723,14 @@ public class FragmentCompose extends FragmentBase { final CheckBox cbResize = dview.findViewById(R.id.cbResize); final Spinner spResize = dview.findViewById(R.id.spResize); final TextView tvResize = dview.findViewById(R.id.tvResize); + final CheckBox cbPrivacy = dview.findViewById(R.id.cbPrivacy); final CheckBox cbNotAgain = dview.findViewById(R.id.cbNotAgain); final TextView tvNotAgain = dview.findViewById(R.id.tvNotAgain); rgAction.check(add_inline ? R.id.rbInline : R.id.rbAttach); cbResize.setChecked(resize_images); spResize.setEnabled(resize_images); + cbPrivacy.setChecked(privacy_images); final int[] resizeValues = getResources().getIntArray(R.array.resizeValues); for (int pos = 0; pos < resizeValues.length; pos++) @@ -4747,6 +4768,14 @@ public class FragmentCompose extends FragmentBase { } }); + cbPrivacy.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { + prefs.edit().putBoolean("privacy_images", isChecked).apply(); + spResize.setEnabled(isChecked); + } + }); + cbNotAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { diff --git a/app/src/main/res/layout/dialog_add_image.xml b/app/src/main/res/layout/dialog_add_image.xml index ec0a0caa71..e607bcf7d3 100644 --- a/app/src/main/res/layout/dialog_add_image.xml +++ b/app/src/main/res/layout/dialog_add_image.xml @@ -72,6 +72,17 @@ app:layout_constraintStart_toEndOf="@id/spResize" app:layout_constraintTop_toTopOf="@id/spResize" /> + + + app:layout_constraintTop_toBottomOf="@id/cbPrivacy" /> Insert Attach Resize + Remove location < %1$d pixels Select file Add attachment