From b5463ae721d6379c6b348ace6c1d3f8323441170 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 10 Jul 2024 21:26:45 +0200 Subject: [PATCH] Improved temporary new messages logic --- .../eu/faircode/email/ServiceSynchronize.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index d5f8caf3f8..1587297e87 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -137,7 +137,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences static final int DEFAULT_BACKOFF_POWER = 3; // 2^3=8 seconds (totally 8+2x20=48 seconds) - private static final long MSG_DELAY = 15 * 1000L; // milliseconds + private static final long MSG_START_DELAY = 15 * 1000L; // milliseconds + private static final long MSG_STOP_DELAY = 1000L + 500L; // milliseconds private static final long BACKUP_DELAY = 30 * 1000L; // milliseconds private static final long PURGE_DELAY = 30 * 1000L; // milliseconds private static final int QUIT_DELAY = 10; // seconds @@ -754,12 +755,21 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences final TwoStateOwner cowner = new TwoStateOwner(this, "liveSynchronizing"); + final Runnable updateStop = new Runnable() { + @Override + public void run() { + Log.i("Stop new messages"); + cowner.stop(); + } + }; + final Runnable updateNew = new Runnable() { @Override public void run() { - Log.i("Update new messages"); + Log.i("Start new messages"); cowner.restart(); - getMainHandler().postDelayed(this, MSG_DELAY); + getMainHandler().postDelayed(updateStop, MSG_STOP_DELAY); + getMainHandler().postDelayed(this, MSG_START_DELAY); } }; @@ -804,10 +814,12 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences if (syncing == 0) { getMainHandler().removeCallbacks(updateNew); + getMainHandler().removeCallbacks(updateStop); cowner.start(); } else { cowner.stop(); - getMainHandler().postDelayed(updateNew, MSG_DELAY); + if (!getMainHandler().hasCallbacks(updateNew)) + getMainHandler().postDelayed(updateNew, MSG_START_DELAY); } if (!changed)