Auto prolong oneshot

This commit is contained in:
M66B
2019-06-01 08:44:46 +02:00
parent 0816a5deb1
commit 6fa14c93e7
2 changed files with 26 additions and 3 deletions

View File

@@ -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<TupleAccountStats>() {
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;
}
});