Use updated settings from event.

This commit is contained in:
akwizgran
2018-09-05 12:04:56 +01:00
parent 7b116f15df
commit 3388682dda

View File

@@ -96,7 +96,7 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
@Override @Override
public void startService() { public void startService() {
// only load the setting here, because database isn't open before // only load the setting here, because database isn't open before
loadLockableSetting(); loadSettings();
} }
@Override @Override
@@ -170,19 +170,24 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
@Override @Override
public void eventOccurred(Event event) { public void eventOccurred(Event event) {
if (event instanceof SettingsUpdatedEvent) { if (event instanceof SettingsUpdatedEvent) {
SettingsUpdatedEvent e = (SettingsUpdatedEvent) event; SettingsUpdatedEvent s = (SettingsUpdatedEvent) event;
String namespace = e.getNamespace(); if (s.getNamespace().equals(SETTINGS_NAMESPACE)) {
if (namespace.equals(SETTINGS_NAMESPACE)) { applySettings(s.getSettings());
loadLockableSetting();
} }
} }
} }
private void loadLockableSetting() { private void loadSettings() {
dbExecutor.execute(() -> { dbExecutor.execute(() -> {
try { try {
Settings settings = applySettings(settingsManager.getSettings(SETTINGS_NAMESPACE));
settingsManager.getSettings(SETTINGS_NAMESPACE); } catch (DbException e) {
logException(LOG, WARNING, e);
}
});
}
private void applySettings(Settings settings) {
// is the app lockable? // is the app lockable?
lockableSetting = settings.getBoolean(PREF_SCREEN_LOCK, false); lockableSetting = settings.getBoolean(PREF_SCREEN_LOCK, false);
boolean newValue = hasScreenLock(appContext) && lockableSetting; boolean newValue = hasScreenLock(appContext) && lockableSetting;
@@ -190,12 +195,6 @@ public class LockManagerImpl implements LockManager, Service, EventListener {
// what is the timeout in minutes? // what is the timeout in minutes?
timeoutMinutes = settings.getInt(PREF_SCREEN_LOCK_TIMEOUT, timeoutMinutes = settings.getInt(PREF_SCREEN_LOCK_TIMEOUT,
timeoutDefault); timeoutDefault);
} catch (DbException e) {
logException(LOG, WARNING, e);
lockableSetting = false;
lockable.postValue(false);
}
});
} }
private boolean timeoutEnabled() { private boolean timeoutEnabled() {