mirror of https://github.com/M66B/FairEmail.git
Eval enabled
This commit is contained in:
parent
30c58b8e22
commit
71bc0bcefb
|
@ -196,20 +196,22 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onChanged(List<TupleAccountNetworkState> accountNetworkStates) {
|
public void onChanged(List<TupleAccountNetworkState> accountNetworkStates) {
|
||||||
boolean running = false;
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(ServiceSynchronize.this);
|
||||||
|
boolean enabled = prefs.getBoolean("enabled", true);
|
||||||
|
|
||||||
|
boolean runService = false;
|
||||||
for (TupleAccountNetworkState current : accountNetworkStates) {
|
for (TupleAccountNetworkState current : accountNetworkStates) {
|
||||||
if (current.accountState.shouldRun())
|
if (enabled && current.accountState.shouldRun())
|
||||||
running = true;
|
runService = true;
|
||||||
|
|
||||||
int index = accountStates.indexOf(current);
|
int index = accountStates.indexOf(current);
|
||||||
if (index < 0) {
|
if (index < 0) {
|
||||||
if (current.shouldRun())
|
if (enabled && current.shouldRun())
|
||||||
start(current);
|
start(current);
|
||||||
} else {
|
} else {
|
||||||
TupleAccountNetworkState prev = accountStates.get(index);
|
TupleAccountNetworkState prev = accountStates.get(index);
|
||||||
accountStates.remove(index);
|
accountStates.remove(index);
|
||||||
|
if (enabled) {
|
||||||
if (current.reload ||
|
if (current.reload ||
|
||||||
!prev.accountState.equals(current.accountState) ||
|
!prev.accountState.equals(current.accountState) ||
|
||||||
prev.shouldRun() != current.shouldRun()) {
|
prev.shouldRun() != current.shouldRun()) {
|
||||||
|
@ -220,12 +222,16 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
if (current.shouldRun())
|
if (current.shouldRun())
|
||||||
start(prev);
|
start(prev);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (prev.shouldRun())
|
||||||
|
stop(prev);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
accountStates.add(current);
|
accountStates.add(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!running)
|
if (!runService)
|
||||||
stopSelf();
|
stopSelf();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,14 +434,16 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final List<String> POST_EVAL =
|
private static final List<String> POST_EVAL =
|
||||||
Collections.unmodifiableList(Arrays.asList("metered", "roaming", "rlah"));
|
Collections.unmodifiableList(Arrays.asList("enabled"));
|
||||||
private static final List<String> POST_RELOAD =
|
private static final List<String> POST_RELOAD =
|
||||||
Collections.unmodifiableList(Arrays.asList("socks_enabled", "socks_proxy", "subscribed_only", "debug"));
|
Collections.unmodifiableList(Arrays.asList(
|
||||||
|
"metered", "roaming", "rlah",
|
||||||
|
"socks_enabled", "socks_proxy", "subscribed_only", "debug"));
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||||
if (POST_EVAL.contains(key))
|
if (POST_EVAL.contains(key))
|
||||||
liveAccountNetworkState.post(true);
|
liveAccountNetworkState.post(false);
|
||||||
else if (POST_RELOAD.contains(key))
|
else if (POST_RELOAD.contains(key))
|
||||||
liveAccountNetworkState.post(true);
|
liveAccountNetworkState.post(true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue