Search in sources :

Example 1 with RequestGetParameters

use of im.actor.core.api.rpc.RequestGetParameters 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();
    }
}
Also used : SettingsSyncState(im.actor.core.modules.settings.entity.SettingsSyncState) SettingsSyncAction(im.actor.core.modules.settings.entity.SettingsSyncAction) ApiParameter(im.actor.core.api.ApiParameter) RpcException(im.actor.core.network.RpcException) IOException(java.io.IOException) RequestGetParameters(im.actor.core.api.rpc.RequestGetParameters) ResponseGetParameters(im.actor.core.api.rpc.ResponseGetParameters)

Aggregations

ApiParameter (im.actor.core.api.ApiParameter)1 RequestGetParameters (im.actor.core.api.rpc.RequestGetParameters)1 ResponseGetParameters (im.actor.core.api.rpc.ResponseGetParameters)1 SettingsSyncAction (im.actor.core.modules.settings.entity.SettingsSyncAction)1 SettingsSyncState (im.actor.core.modules.settings.entity.SettingsSyncState)1 RpcException (im.actor.core.network.RpcException)1 IOException (java.io.IOException)1