From 5fc374d1acb53d7710d05dde889002b3003946aa Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 12 Sep 2019 22:06:08 +0200 Subject: [PATCH] Made send dialog optional --- .../eu/faircode/email/FragmentCompose.java | 46 +++++++++++++++---- app/src/main/res/layout/dialog_send.xml | 10 ++++ app/src/main/res/menu/menu_compose.xml | 5 ++ app/src/main/res/values/strings.xml | 1 + 4 files changed, 53 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentCompose.java b/app/src/main/java/eu/faircode/email/FragmentCompose.java index 6fcd5d8e23..5db374670b 100644 --- a/app/src/main/java/eu/faircode/email/FragmentCompose.java +++ b/app/src/main/java/eu/faircode/email/FragmentCompose.java @@ -461,7 +461,7 @@ public class FragmentCompose extends FragmentBase { onActionDiscard(); break; case R.id.action_send: - onActionCheck(); + onActionCheck(false); break; default: onAction(action); @@ -935,6 +935,9 @@ public class FragmentCompose extends FragmentBase { case R.id.menu_answer: onMenuAnswer(); return true; + case R.id.menu_send: + onActionCheck(true); + return true; default: return super.onOptionsItemSelected(item); } @@ -1087,8 +1090,15 @@ public class FragmentCompose extends FragmentBase { } } - private void onActionCheck() { - onAction(R.id.action_check); + private void onActionCheck(boolean dialog) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + if (dialog) + prefs.edit().remove("send_dialog").apply(); + boolean send_dialog = prefs.getBoolean("send_dialog", true); + + Bundle extras = new Bundle(); + extras.putBoolean("dialog", dialog || send_dialog); + onAction(R.id.action_check, extras); } private void onEncrypt() { @@ -1755,6 +1765,10 @@ public class FragmentCompose extends FragmentBase { } private void onAction(int action) { + onAction(action, null); + } + + private void onAction(int action, Bundle extras) { EntityIdentity identity = (EntityIdentity) spIdentity.getSelectedItem(); if (identity == null) throw new IllegalArgumentException(getString(R.string.title_from_missing)); @@ -1765,8 +1779,8 @@ public class FragmentCompose extends FragmentBase { Bundle args = new Bundle(); args.putLong("id", working); args.putInt("action", action); - args.putLong("account", identity == null ? -1 : identity.account); - args.putLong("identity", identity == null ? -1 : identity.id); + args.putLong("account", identity.account); + args.putLong("identity", identity.id); args.putString("extra", etExtra.getText().toString().trim()); args.putString("to", etTo.getText().toString().trim()); args.putString("cc", etCc.getText().toString().trim()); @@ -1774,6 +1788,8 @@ public class FragmentCompose extends FragmentBase { args.putString("subject", etSubject.getText().toString().trim()); args.putString("body", HtmlHelper.toHtml(etBody.getText())); args.putBoolean("empty", isEmpty()); + if (extras != null) + args.putBundle("extras", extras); Log.i("Run execute id=" + working); actionLoader.execute(this, args, "compose:action:" + action); @@ -2902,10 +2918,17 @@ public class FragmentCompose extends FragmentBase { // Do nothing } else if (action == R.id.action_check) { - FragmentDialogSend fragment = new FragmentDialogSend(); - fragment.setArguments(args); - fragment.setTargetFragment(FragmentCompose.this, REQUEST_SEND); - fragment.show(getFragmentManager(), "compose:send"); + boolean dialog = args.getBundle("extras").getBoolean("dialog"); + boolean remind_subject = args.getBoolean("remind_subject", false); + boolean remind_attachment = args.getBoolean("remind_attachment", false); + + if (dialog || remind_subject || remind_attachment) { + FragmentDialogSend fragment = new FragmentDialogSend(); + fragment.setArguments(args); + fragment.setTargetFragment(FragmentCompose.this, REQUEST_SEND); + fragment.show(getFragmentManager(), "compose:send"); + } else + onAction(R.id.action_send); } else if (action == R.id.action_send) { autosave = false; @@ -3576,6 +3599,7 @@ public class FragmentCompose extends FragmentBase { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); int send_delayed = prefs.getInt("send_delayed", 0); + boolean send_dialog = prefs.getBoolean("send_dialog", true); final int[] sendDelayedValues = getResources().getIntArray(R.array.sendDelayedValues); final String[] sendDelayedNames = getResources().getStringArray(R.array.sendDelayedNames); @@ -3589,12 +3613,14 @@ public class FragmentCompose extends FragmentBase { final ImageButton ibSendAt = dview.findViewById(R.id.ibSendAt); final TextView tvRemindSubject = dview.findViewById(R.id.tvRemindSubject); final TextView tvRemindAttachment = dview.findViewById(R.id.tvRemindAttachment); + final CheckBox cbNotAgain = dview.findViewById(R.id.cbNotAgain); tvTo.setText(null); tvVia.setText(null); tvSendAt.setText(null); tvRemindSubject.setVisibility(remind_subject ? View.VISIBLE : View.GONE); tvRemindAttachment.setVisibility(remind_attachment ? View.VISIBLE : View.GONE); + cbNotAgain.setVisibility(send_dialog ? View.VISIBLE : View.GONE); DB db = DB.getInstance(getContext()); db.message().liveMessage(id).observe(getViewLifecycleOwner(), new Observer() { @@ -3699,6 +3725,8 @@ public class FragmentCompose extends FragmentBase { @Override public void onClick(DialogInterface dialog, int which) { getArguments().putBoolean("encrypt", cbEncrypt.isChecked()); + if (cbNotAgain.isChecked()) + prefs.edit().putBoolean("send_dialog", false).apply(); sendResult(Activity.RESULT_OK); } }) diff --git a/app/src/main/res/layout/dialog_send.xml b/app/src/main/res/layout/dialog_send.xml index bb022a5c73..deafef102a 100644 --- a/app/src/main/res/layout/dialog_send.xml +++ b/app/src/main/res/layout/dialog_send.xml @@ -141,5 +141,15 @@ android:textColor="?attr/colorWarning" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/tvRemindSubject" /> + + \ No newline at end of file diff --git a/app/src/main/res/menu/menu_compose.xml b/app/src/main/res/menu/menu_compose.xml index 7bed574e93..ed07235d6b 100644 --- a/app/src/main/res/menu/menu_compose.xml +++ b/app/src/main/res/menu/menu_compose.xml @@ -27,4 +27,9 @@ android:id="@+id/menu_answer" android:title="@string/title_insert_template" app:showAsAction="never" /> + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 41086e302f..b5804d68d9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -558,6 +558,7 @@ Discard Save Send + Send … Send at … No server found at \'%1$s\'