Refactoring

This commit is contained in:
M66B 2020-02-23 18:39:42 +01:00
parent bbed4139e3
commit 5c7378cdfa
4 changed files with 10 additions and 6 deletions

View File

@ -243,6 +243,9 @@ public class ApplicationEx extends Application {
editor.putInt("signature_location", 2);
editor.remove("signature_end");
}
} else if (version < 978) {
if (!prefs.contains("poll_interval"))
editor.putInt("poll_interval", 0);
}
if (BuildConfig.DEBUG && false) {

View File

@ -346,7 +346,7 @@ public class FragmentOptionsSynchronize extends FragmentBase implements SharedPr
swEnabled.setChecked(prefs.getBoolean("enabled", true));
int pollInterval = prefs.getInt("poll_interval", 0);
int pollInterval = prefs.getInt("poll_interval", ServiceSynchronize.DEFAULT_POLL_INTERVAL);
int[] pollIntervalValues = getResources().getIntArray(R.array.pollIntervalValues);
for (int pos = 0; pos < pollIntervalValues.length; pos++)
if (pollIntervalValues[pos] == pollInterval) {

View File

@ -106,6 +106,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
private static final long YIELD_DURATION = 200L; // milliseconds
private static final long QUIT_DELAY = 5 * 1000L; // milliseconds
private static final long STILL_THERE_THRESHOLD = 3 * 60 * 1000L; // milliseconds
static final int DEFAULT_POLL_INTERVAL = 0; // minutes
private static final int STILL_THERE_POLL_INTERVAL = 15; // minutes
private static final int CONNECT_BACKOFF_START = 8; // seconds
private static final int CONNECT_BACKOFF_MAX = 64; // seconds (totally 2 minutes)
@ -849,7 +850,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
if (!auto_optimize)
return;
int pollInterval = prefs.getInt("poll_interval", 0);
int pollInterval = prefs.getInt("poll_interval", DEFAULT_POLL_INTERVAL);
if (pollInterval == 0) {
prefs.edit().putInt("poll_interval", STILL_THERE_POLL_INTERVAL).apply();
try {
@ -940,7 +941,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
EntityLog.log(this, account.name + " last connected: " + new Date(account.last_connected));
long now = new Date().getTime();
int pollInterval = prefs.getInt("poll_interval", 0);
int pollInterval = prefs.getInt("poll_interval", DEFAULT_POLL_INTERVAL);
long delayed = now - account.last_connected - account.poll_interval * 60 * 1000L;
long maxDelayed = (pollInterval > 0 && !account.poll_exempted
? pollInterval * ACCOUNT_ERROR_AFTER_POLL : ACCOUNT_ERROR_AFTER) * 60 * 1000L;
@ -1541,7 +1542,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
break;
// Stop retrying when polling
int pollInterval = prefs.getInt("poll_interval", 0);
int pollInterval = prefs.getInt("poll_interval", DEFAULT_POLL_INTERVAL);
if (pollInterval > 0 && !account.poll_exempted)
break;
@ -1703,7 +1704,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSynchronize.this);
boolean enabled = prefs.getBoolean("enabled", true);
int pollInterval = prefs.getInt("poll_interval", 0);
int pollInterval = prefs.getInt("poll_interval", DEFAULT_POLL_INTERVAL);
long[] schedule = getSchedule(ServiceSynchronize.this);
long now = new Date().getTime();

View File

@ -494,7 +494,7 @@ public class ServiceUI extends IntentService {
am.cancel(piSync);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
int pollInterval = prefs.getInt("poll_interval", 0);
int pollInterval = prefs.getInt("poll_interval", ServiceSynchronize.DEFAULT_POLL_INTERVAL);
if (enabled && pollInterval > 0) {
long now = new Date().getTime();
long interval = pollInterval * 60 * 1000L;