diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 88b49a3559..b85a680a2f 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -107,7 +107,7 @@ public class ServiceSynchronize extends LifecycleService { private static final long RECONNECT_BACKOFF = 90 * 1000L; // milliseconds private static final int ACCOUNT_ERROR_AFTER = 60; // minutes private static final int BACKOFF_ERROR_AFTER = 16; // seconds - private static final long ONESHOT_DURATION = 120 * 1000L; // milliseconds + private static final long ONESHOT_DURATION = 90 * 1000L; // milliseconds private static final long STOP_DELAY = 5000L; // milliseconds static final int PI_ALARM = 1; @@ -129,10 +129,19 @@ public class ServiceSynchronize extends LifecycleService { DB db = DB.getInstance(this); db.account().liveStats().observe(this, new Observer() { + private TupleAccountStats lastStats = null; + @Override public void onChanged(@Nullable TupleAccountStats stats) { - NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); - nm.notify(Helper.NOTIFICATION_SYNCHRONIZE, getNotificationService(stats).build()); + if (stats != null && !stats.equals(lastStats)) { + NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + nm.notify(Helper.NOTIFICATION_SYNCHRONIZE, getNotificationService(stats).build()); + + if (oneshot && stats.operations > 0) + onOneshot(true); + } + + lastStats = stats; } }); diff --git a/app/src/main/java/eu/faircode/email/TupleAccountStats.java b/app/src/main/java/eu/faircode/email/TupleAccountStats.java index a59d72574e..415f4afd96 100644 --- a/app/src/main/java/eu/faircode/email/TupleAccountStats.java +++ b/app/src/main/java/eu/faircode/email/TupleAccountStats.java @@ -19,7 +19,21 @@ package eu.faircode.email; Copyright 2018-2019 by Marcel Bokhorst (M66B) */ +import androidx.annotation.Nullable; + +import java.util.Objects; + public class TupleAccountStats { public Integer accounts = 0; public Integer operations = 0; + + @Override + public boolean equals(@Nullable Object obj) { + if (obj instanceof TupleAccountStats) { + TupleAccountStats other = (TupleAccountStats) obj; + return (Objects.equals(this.accounts, other.accounts) && + Objects.equals(this.operations, other.operations)); + } else + return false; + } }