From f98dc7a60c0626024ac6af66018cd0cdfc5e11a6 Mon Sep 17 00:00:00 2001 From: M66B Date: Thu, 7 Mar 2024 19:58:56 +0100 Subject: [PATCH] Added send retry max setting --- .../faircode/email/FragmentOptionsSend.java | 32 ++++++++++++- .../java/eu/faircode/email/ServiceSend.java | 9 +++- .../main/res/layout/fragment_options_send.xml | 46 +++++++++++++++++++ app/src/main/res/values/strings.xml | 2 + 4 files changed, 86 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java index 8caaf9b116..440eb676d7 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptionsSend.java @@ -127,6 +127,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc private SwitchCompat swLookupMx; private SwitchCompat swReplyMove; private SwitchCompat swReplyMoveInbox; + private EditText etSendRetryMax; private final static List RESET_OPTIONS = Collections.unmodifiableList(Arrays.asList( "keyboard", "keyboard_no_fullscreen", @@ -146,7 +147,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc "format_flowed", "usenet_signature", "remove_signatures", "receipt_default", "receipt_type", "receipt_legacy", "forward_new", - "lookup_mx", "reply_move", "reply_move_inbox" + "lookup_mx", "reply_move", "reply_move_inbox", + "send_retry_max" )); @Override @@ -219,6 +221,7 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc swLookupMx = view.findViewById(R.id.swLookupMx); swReplyMove = view.findViewById(R.id.swReplyMove); swReplyMoveInbox = view.findViewById(R.id.swReplyMoveInbox); + etSendRetryMax = view.findViewById(R.id.etSendRetryMax); List fonts = StyleHelper.getFonts(getContext(), false); @@ -762,6 +765,27 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc } }); + etSendRetryMax.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + // Do nothing + } + + @Override + public void onTextChanged(CharSequence s, int start, int before, int count) { + // Do nothing + } + + @Override + public void afterTextChanged(Editable s) { + Integer count = Helper.parseInt(s.toString()); + if (count == null) + prefs.edit().remove("send_retry_max").apply(); + else + prefs.edit().putInt("send_retry_max", count).apply(); + } + }); + // Initialize FragmentDialogTheme.setBackground(getContext(), view, false); @@ -798,6 +822,8 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc return; if ("purge_contact_age".equals(key) || "purge_contact_freq".equals(key)) return; + if ("send_retry_max".equals(key)) + return; getMainHandler().removeCallbacks(update); getMainHandler().postDelayed(update, FragmentOptions.DELAY_SETOPTIONS); @@ -938,6 +964,10 @@ public class FragmentOptionsSend extends FragmentBase implements SharedPreferenc swReplyMove.setChecked(prefs.getBoolean("reply_move", false)); swReplyMoveInbox.setChecked(prefs.getBoolean("reply_move_inbox", true)); swReplyMoveInbox.setEnabled(swReplyMove.isChecked()); + + int send_retry_max = prefs.getInt("send_retry_max", 0); + etSendRetryMax.setText(send_retry_max > 0 ? Integer.toString(send_retry_max) : null); + etSendRetryMax.setHint(Integer.toString(ServiceSend.RETRY_MAX_DEFAULT)); } catch (Throwable ex) { Log.e(ex); } diff --git a/app/src/main/java/eu/faircode/email/ServiceSend.java b/app/src/main/java/eu/faircode/email/ServiceSend.java index 8ecb0acd16..e5eaf3957e 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSend.java +++ b/app/src/main/java/eu/faircode/email/ServiceSend.java @@ -79,6 +79,7 @@ import biweekly.component.VEvent; import biweekly.property.Method; public class ServiceSend extends ServiceBase implements SharedPreferences.OnSharedPreferenceChangeListener { + private int retry_max = RETRY_MAX_DEFAULT; private TupleUnsent lastUnsent = null; private Network lastActive = null; private boolean lastSuitable = false; @@ -91,7 +92,6 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar private static final ExecutorService executor = Helper.getBackgroundExecutor(1, "send"); - private static final int RETRY_MAX = 3; private static final long RETRY_WAIT = 5000L; // milliseconds private static final int CONNECTIVITY_DELAY = 5000; // milliseconds private static final int PROGRESS_UPDATE_INTERVAL = 1000; // milliseconds @@ -100,12 +100,17 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar static final int PI_SEND = 1; static final int PI_FIX = 2; + static final int RETRY_MAX_DEFAULT = 3; + @Override public void onCreate() { EntityLog.log(this, "Service send create"); super.onCreate(); startForeground(NotificationHelper.NOTIFICATION_SEND, getNotificationService(false)); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + retry_max = prefs.getInt("send_retry_max", RETRY_MAX_DEFAULT); + owner = new TwoStateOwner(this, "send"); PowerManager pm = Helper.getSystemService(this, PowerManager.class); @@ -471,7 +476,7 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar (ex instanceof AuthenticationFailedException && !ConnectionHelper.isIoError(ex)) || ex instanceof SendFailedException || ex instanceof IllegalArgumentException); - int tries_left = (unrecoverable ? 0 : RETRY_MAX - op.tries); + int tries_left = (unrecoverable ? 0 : retry_max - op.tries); db.operation().setOperationError(op.id, Log.formatThrowable(ex)); if (message != null) { diff --git a/app/src/main/res/layout/fragment_options_send.xml b/app/src/main/res/layout/fragment_options_send.xml index c3b799dca7..4c96de1fb5 100644 --- a/app/src/main/res/layout/fragment_options_send.xml +++ b/app/src/main/res/layout/fragment_options_send.xml @@ -1112,6 +1112,52 @@ android:textStyle="italic" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@id/swReplyMoveInbox" /> + + + + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bea0cf69d9..27fd8d0861 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -499,6 +499,8 @@ On discard draft, permanently delete draft On replying to a message, save the reply in the same folder Also for messages in the inbox + Maximum send attempts + Sending will be retried on connectivity changes Automatically create links Send plain text only by default