diff --git a/app/src/main/java/eu/faircode/email/DaoAttachment.java b/app/src/main/java/eu/faircode/email/DaoAttachment.java index d9824d8806..d260f9390e 100644 --- a/app/src/main/java/eu/faircode/email/DaoAttachment.java +++ b/app/src/main/java/eu/faircode/email/DaoAttachment.java @@ -157,6 +157,10 @@ public interface DaoAttachment { " WHERE id = :id") int deleteAttachment(long id); + @Query("DELETE FROM attachment" + + " WHERE message = :message") + int deleteAttachments(long message); + @Query("DELETE FROM attachment" + " WHERE message = :message" + " AND (encryption IS NULL OR encryption NOT IN (:keep))") diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 9b94318d6d..5def9e937f 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -240,6 +240,7 @@ public class FragmentCompose extends FragmentBase { private ImageButton ibBccAdd; private EditText etSubject; private ImageButton ibCcBcc; + private ImageButton ibRemoveAttachments; private RecyclerView rvAttachment; private TextView tvNoInternetAttachments; private TextView tvDsn; @@ -320,6 +321,7 @@ public class FragmentCompose extends FragmentBase { private static final int REQUEST_LINK = 12; private static final int REQUEST_DISCARD = 13; private static final int REQUEST_SEND = 14; + private static final int REQUEST_REMOVE_ATTACHMENTS = 15; private static ExecutorService executor = Helper.getBackgroundExecutor(1, "compose"); @@ -356,6 +358,7 @@ public class FragmentCompose extends FragmentBase { ibBccAdd = view.findViewById(R.id.ibBccAdd); etSubject = view.findViewById(R.id.etSubject); ibCcBcc = view.findViewById(R.id.ibCcBcc); + ibRemoveAttachments = view.findViewById(R.id.ibRemoveAttachments); rvAttachment = view.findViewById(R.id.rvAttachment); tvNoInternetAttachments = view.findViewById(R.id.tvNoInternetAttachments); tvDsn = view.findViewById(R.id.tvDsn); @@ -1206,6 +1209,20 @@ public class FragmentCompose extends FragmentBase { grpAddresses.setVisibility(cc_bcc ? View.VISIBLE : View.GONE); + ibRemoveAttachments.setVisibility(View.GONE); + ibRemoveAttachments.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Bundle args = new Bundle(); + args.putString("question", getString(R.string.title_ask_delete_attachments)); + + FragmentDialogAsk fragment = new FragmentDialogAsk(); + fragment.setArguments(args); + fragment.setTargetFragment(FragmentCompose.this, REQUEST_REMOVE_ATTACHMENTS); + fragment.show(getParentFragmentManager(), "compose:discard"); + } + }); + rvAttachment.setHasFixedSize(false); LinearLayoutManager llm = new LinearLayoutManager(getContext()); rvAttachment.setLayoutManager(llm); @@ -2543,6 +2560,10 @@ public class FragmentCompose extends FragmentBase { onAction(R.id.action_send, extras, "sendnow"); } break; + case REQUEST_REMOVE_ATTACHMENTS: + if (resultCode == RESULT_OK) + onRemoveAttachments(); + break; } } catch (Throwable ex) { Log.e(ex); @@ -3868,6 +3889,28 @@ public class FragmentCompose extends FragmentBase { onAction(R.id.action_delete, "delete"); } + private void onRemoveAttachments() { + Bundle args = new Bundle(); + args.putLong("id", working); + + new SimpleTask() { + @Override + protected Void onExecute(Context context, Bundle args) throws Throwable { + long id = args.getLong("id"); + + DB db = DB.getInstance(context); + db.attachment().deleteAttachments(id); + + return null; + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Log.unexpectedError(getParentFragmentManager(), ex); + } + }.execute(FragmentCompose.this, args, "attachments:remove"); + } + private void onExit() { if (state == State.LOADED) { state = State.NONE; @@ -5162,6 +5205,7 @@ public class FragmentCompose extends FragmentBase { } }); + ibRemoveAttachments.setVisibility(attachments.size() > 2 ? View.VISIBLE : View.GONE); grpAttachments.setVisibility(attachments.size() > 0 ? View.VISIBLE : View.GONE); boolean downloading = false; diff --git a/app/src/main/res/layout/fragment_compose.xml b/app/src/main/res/layout/fragment_compose.xml index a21e3c5fc6..1193d5c82f 100644 --- a/app/src/main/res/layout/fragment_compose.xml +++ b/app/src/main/res/layout/fragment_compose.xml @@ -240,14 +240,27 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/etSubject" /> + + + app:layout_constraintTop_toBottomOf="@+id/ibRemoveAttachments" + app:layout_goneMarginTop="6dp" /> I understand that permanently deleting messages is irreversible Delete reply template permanently? Delete rule permanently? + Remove all attachments? Discard draft? Showing the original message can leak privacy sensitive information Displaying the original message on a dark background is not possible as it may make dark texts and images invisible