use of im.actor.core.modules.settings.entity.SettingsSyncAction in project actor-platform by actorapp.
the class SettingsSyncActor method onReceive.
@Override
public void onReceive(Object message) {
if (message instanceof ChangeSettings) {
ChangeSettings changeSettings = (ChangeSettings) message;
SettingsSyncAction action = new SettingsSyncAction(changeSettings.getKey(), changeSettings.getValue());
syncState.getPendingActions().add(action);
saveState();
performSync(action);
} else {
super.onReceive(message);
}
}
use of im.actor.core.modules.settings.entity.SettingsSyncAction in project actor-platform by actorapp.
the class SettingsSyncActor method preStart.
@Override
public void preStart() {
super.preStart();
syncState = new SettingsSyncState();
byte[] data = preferences().getBytes(SYNC_STATE);
if (data != null) {
try {
syncState = SettingsSyncState.fromBytes(data);
} catch (IOException e) {
e.printStackTrace();
}
}
for (SettingsSyncAction action : syncState.getPendingActions()) {
performSync(action);
}
if (!preferences().getBool(SYNC_STATE_LOADED, false)) {
// TODO: Avoid race conditions
request(new RequestGetParameters(), new RpcCallback<ResponseGetParameters>() {
@Override
public void onResult(ResponseGetParameters response) {
for (ApiParameter p : response.getParameters()) {
context().getSettingsModule().onUpdatedSetting(p.getKey(), p.getValue());
}
context().getSettingsModule().notifySettingsChanged();
preferences().putBool(SYNC_STATE_LOADED, true);
context().getConductor().getConductor().onSettingsLoaded();
}
@Override
public void onError(RpcException e) {
// Ignore
}
});
} else {
context().getConductor().getConductor().onSettingsLoaded();
}
}
Aggregations