1
0
Fork 0
mirror of https://github.com/M66B/FairEmail.git synced 2025-01-01 04:35:57 +00:00

Fixed polling without schedule

This commit is contained in:
M66B 2020-01-10 12:12:14 +01:00
parent 9306d4e1e9
commit 9d3eb2d270
2 changed files with 14 additions and 13 deletions

View file

@ -148,8 +148,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("schedule", checked).apply(); prefs.edit().putBoolean("schedule", checked).apply();
if (checked) ServiceSynchronize.reschedule(getContext());
ServiceSynchronize.reschedule(getContext());
} }
}); });

View file

@ -1548,21 +1548,23 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.cancel(pi); am.cancel(pi);
boolean enabled;
long[] schedule = getSchedule(context); long[] schedule = getSchedule(context);
if (schedule == null) if (schedule == null)
return; enabled = true;
else {
long now = new Date().getTime();
long next = (now < schedule[0] ? schedule[0] : schedule[1]);
enabled = (now >= schedule[0] && now < schedule[1]);
long now = new Date().getTime(); Log.i("Schedule now=" + new Date(now));
long next = (now < schedule[0] ? schedule[0] : schedule[1]); Log.i("Schedule start=" + new Date(schedule[0]));
boolean enabled = (now >= schedule[0] && now < schedule[1]); Log.i("Schedule end=" + new Date(schedule[1]));
Log.i("Schedule next=" + new Date(next));
Log.i("Schedule enabled=" + enabled);
Log.i("Schedule now=" + new Date(now)); AlarmManagerCompat.setAndAllowWhileIdle(am, AlarmManager.RTC_WAKEUP, next, pi);
Log.i("Schedule start=" + new Date(schedule[0])); }
Log.i("Schedule end=" + new Date(schedule[1]));
Log.i("Schedule next=" + new Date(next));
Log.i("Schedule enabled=" + enabled);
AlarmManagerCompat.setAndAllowWhileIdle(am, AlarmManager.RTC_WAKEUP, next, pi);
WorkerPoll.init(context, enabled); WorkerPoll.init(context, enabled);
} }