From e9bc8f8e7b7502cfcf20a3c6f38c343d264b3f20 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 19 Jan 2023 12:20:53 +0100 Subject: [PATCH] Allow selecting action for answer menu --- .../eu/faircode/email/FragmentMessages.java | 21 ++++++----- .../faircode/email/FragmentOptionsSend.java | 37 +++++++++++++++---- .../main/res/layout/fragment_options_send.xml | 32 +++++++++++++--- app/src/main/res/values/strings.xml | 4 ++ 4 files changed, 72 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index cf211c2528..7b3bc312a0 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -3356,17 +3356,14 @@ public class FragmentMessages extends FragmentBase if (message == null) return; - if (long_press && message.content) { - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); - String answer_action = prefs.getString("answer_action", "reply"); - if ("reply".equals(answer_action) || - "reply_all".equals(answer_action) || - "list".equals(answer_action)) - onMenuReply(message, answer_action, selected); - else - onMenuReply(message, answer_action); - } else + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext()); + String action = prefs.getString( + long_press ? "answer_action" : "answer_single", + long_press ? "reply" : "menu"); + if ("menu".equals(action) || !message.content) onReply(message, selected, fabReply); + else + onMenuReply(message, action); } } @@ -3569,6 +3566,10 @@ public class FragmentMessages extends FragmentBase final Context context = getContext(); if (context == null) return; + if (!"reply".equals(action) && + !"reply_all".equals(action) && + !"list".equals(action)) + selected = null; Intent reply = new Intent(context, ActivityCompose.class) .putExtra("action", action) .putExtra("reference", message.id) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java index c707cec362..4515ff0cfc 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java @@ -78,7 +78,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc private SwitchCompat swAutoSaveDot; private SwitchCompat swDiscardDelete; private Spinner spSendDelayed; - private Spinner spAnswerAction; + private Spinner spAnswerActionSingle; + private Spinner spAnswerActionLong; private Button btnSound; private ViewButtonColor btnComposeColor; @@ -121,7 +122,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc "send_reminders", "send_chips", "send_pending", "auto_save_paragraph", "auto_save_dot", "discard_delete", "send_delayed", - "answer_action", + "answer_single", "answer_action", "sound_sent", "compose_color", "compose_font", "prefix_once", "prefix_count", "alt_re", "alt_fwd", @@ -160,7 +161,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc swAutoSaveDot = view.findViewById(R.id.swAutoSaveDot); swDiscardDelete = view.findViewById(R.id.swDiscardDelete); spSendDelayed = view.findViewById(R.id.spSendDelayed); - spAnswerAction = view.findViewById(R.id.spAnswerAction); + spAnswerActionSingle = view.findViewById(R.id.spAnswerActionSingle); + spAnswerActionLong = view.findViewById(R.id.spAnswerActionLong); btnSound = view.findViewById(R.id.btnSound); btnComposeColor = view.findViewById(R.id.btnComposeColor); @@ -343,7 +345,20 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc } }); - spAnswerAction.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + spAnswerActionSingle.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView adapterView, View view, int position, long id) { + String[] values = getResources().getStringArray(R.array.answerValues); + prefs.edit().putString("answer_single", values[position]).apply(); + } + + @Override + public void onNothingSelected(AdapterView parent) { + prefs.edit().remove("answer_single").apply(); + } + }); + + spAnswerActionLong.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView adapterView, View view, int position, long id) { String[] values = getResources().getStringArray(R.array.answerValues); @@ -352,7 +367,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc @Override public void onNothingSelected(AdapterView parent) { - prefs.edit().remove("sender_ellipsize").apply(); + prefs.edit().remove("answer_action").apply(); } }); @@ -726,12 +741,20 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc break; } + String[] answerValues = getResources().getStringArray(R.array.answerValues); + + String answer_default = prefs.getString("answer_single", "menu"); + for (int pos = 0; pos < answerValues.length; pos++) + if (answerValues[pos].equals(answer_default)) { + spAnswerActionSingle.setSelection(pos); + break; + } + boolean reply_all = prefs.getBoolean("reply_all", false); String answer_action = prefs.getString("answer_action", reply_all ? "reply_all" : "reply"); - String[] answerValues = getResources().getStringArray(R.array.answerValues); for (int pos = 0; pos < answerValues.length; pos++) if (answerValues[pos].equals(answer_action)) { - spAnswerAction.setSelection(pos); + spAnswerActionLong.setSelection(pos); break; } diff --git a/app/src/main/res/layout/fragment_options_send.xml b/app/src/main/res/layout/fragment_options_send.xml index 24fc3f53bc..9bc0099524 100644 --- a/app/src/main/res/layout/fragment_options_send.xml +++ b/app/src/main/res/layout/fragment_options_send.xml @@ -324,7 +324,29 @@ app:layout_constraintTop_toBottomOf="@id/tvSendDelayed" /> + + + + + app:layout_constraintTop_toBottomOf="@id/spAnswerActionSingle" /> + app:layout_constraintTop_toBottomOf="@id/tvAnswerActionLong" />