From b7fc960f2bc649b46f7f419864ac640c6072e5ce Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 30 Jan 2019 08:28:00 +0000 Subject: [PATCH] Ask edit reference --- .../eu/faircode/email/FragmentCompose.java | 151 +++++++++++------- app/src/main/res/values/strings.xml | 1 + 2 files changed, 94 insertions(+), 58 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index e3991e04f8..29599c3280 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -292,70 +292,14 @@ public class FragmentCompose extends FragmentBase { ibReferenceEdit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Bundle args = new Bundle(); - args.putLong("id", working); - args.putString("body", Html.toHtml(etBody.getText())); - - new SimpleTask() { - @Override - protected void onPreExecute(Bundle args) { - ibReferenceEdit.setEnabled(false); - } - - @Override - protected void onPostExecute(Bundle args) { - ibReferenceEdit.setEnabled(true); - } - - @Override - protected Void onExecute(Context context, Bundle args) throws Throwable { - long id = args.getLong("id"); - String body = args.getString("body"); - - File file = EntityMessage.getFile(context, id); - File ref = EntityMessage.getRefFile(context, id); - - BufferedReader in = null; - BufferedWriter out = null; - try { - out = new BufferedWriter(new FileWriter(file)); - out.write(body); - - in = new BufferedReader(new FileReader(ref)); - String str; - while ((str = in.readLine()) != null) - out.write(str); - } finally { - if (out != null) - out.close(); - if (in != null) - in.close(); - } - - ref.delete(); - - return null; - } - - @Override - protected void onExecuted(Bundle args, Void data) { - showDraft(working); - } - - @Override - protected void onException(Bundle args, Throwable ex) { - Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex); - } - }.execute(FragmentCompose.this, args, "compose:refedit"); + onReferenceEdit(); } }); ibReferenceImages.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - show_images = true; - onAction(R.id.action_save); - showDraft(working); + onReferenceImages(); } }); @@ -530,6 +474,97 @@ public class FragmentCompose extends FragmentBase { return view; } + private void onReferenceEdit() { + final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + if (prefs.getBoolean("edit_ref_confirmed", false)) { + onReferenceEditConfirmed(); + return; + } + + final View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_ask_again, null); + final TextView tvMessage = dview.findViewById(R.id.tvMessage); + final CheckBox cbNotAgain = dview.findViewById(R.id.cbNotAgain); + + tvMessage.setText(getText(R.string.title_ask_edit_ref)); + + new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner()) + .setView(dview) + .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (cbNotAgain.isChecked()) + prefs.edit().putBoolean("edit_ref_confirmed", true).apply(); + onReferenceEditConfirmed(); + } + }) + .setNegativeButton(android.R.string.cancel, null) + .show(); + } + + private void onReferenceEditConfirmed() { + Bundle args = new Bundle(); + args.putLong("id", working); + args.putString("body", Html.toHtml(etBody.getText())); + + new SimpleTask() { + @Override + protected void onPreExecute(Bundle args) { + ibReferenceEdit.setEnabled(false); + } + + @Override + protected void onPostExecute(Bundle args) { + ibReferenceEdit.setEnabled(true); + } + + @Override + protected Void onExecute(Context context, Bundle args) throws Throwable { + long id = args.getLong("id"); + String body = args.getString("body"); + + File file = EntityMessage.getFile(context, id); + File ref = EntityMessage.getRefFile(context, id); + + BufferedReader in = null; + BufferedWriter out = null; + try { + out = new BufferedWriter(new FileWriter(file)); + out.write(body); + + in = new BufferedReader(new FileReader(ref)); + String str; + while ((str = in.readLine()) != null) + out.write(str); + } finally { + if (out != null) + out.close(); + if (in != null) + in.close(); + } + + ref.delete(); + + return null; + } + + @Override + protected void onExecuted(Bundle args, Void data) { + showDraft(working); + } + + @Override + protected void onException(Bundle args, Throwable ex) { + Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex); + } + }.execute(FragmentCompose.this, args, "compose:refedit"); + } + + private void onReferenceImages() { + show_images = true; + onAction(R.id.action_save); + showDraft(working); + } + @Override public void onDestroyView() { adapter = null; diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8e9d034055..a5d1a70ce1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -334,6 +334,7 @@ Discard draft? Showing the original message can leak privacy sensitive information Showing images can leak privacy sensitive information + Edit reformatted replied/forwarded message text? Synchronization will take place on next account connection Fix