Search in sources :

Example 1 with Config

use of com.nutomic.syncthingandroid.model.Config in project syncthing-android by syncthing.

the class RestApi method onWebGuiAvailable.

/**
 * Gets local device ID, syncthing version and config, then calls all OnApiAvailableListeners.
 */
@Override
public void onWebGuiAvailable() {
    mAvailableCount.set(0);
    new GetRequest(mContext, mUrl, GetRequest.URI_VERSION, mApiKey, null, result -> {
        JsonObject json = new JsonParser().parse(result).getAsJsonObject();
        mVersion = json.get("version").getAsString();
        Log.i(TAG, "Syncthing version is " + mVersion);
        tryIsAvailable();
    });
    new GetRequest(mContext, mUrl, GetRequest.URI_CONFIG, mApiKey, null, result -> {
        mConfig = new Gson().fromJson(result, Config.class);
        if (mConfig == null) {
            throw new RuntimeException("config is null: " + result);
        }
        tryIsAvailable();
    });
    getSystemInfo(info -> {
        mLocalDeviceId = info.myID;
        tryIsAvailable();
    });
}
Also used : BuildConfig(com.nutomic.syncthingandroid.BuildConfig) Config(com.nutomic.syncthingandroid.model.Config) GetRequest(com.nutomic.syncthingandroid.http.GetRequest) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) JsonParser(com.google.gson.JsonParser)

Example 2 with Config

use of com.nutomic.syncthingandroid.model.Config in project syncthing-android by syncthing.

the class RestApi method onReloadConfigComplete.

private void onReloadConfigComplete(String result) {
    Boolean configParseSuccess;
    synchronized (mConfigLock) {
        mConfig = new Gson().fromJson(result, Config.class);
        configParseSuccess = mConfig != null;
    }
    if (!configParseSuccess) {
        throw new RuntimeException("config is null: " + result);
    }
    Log.v(TAG, "onReloadConfigComplete: Successfully parsed configuration.");
    if (BuildConfig.DEBUG) {
        Log.v(TAG, "mConfig.remoteIgnoredDevices = " + new Gson().toJson(mConfig.remoteIgnoredDevices));
    }
    // Update cached device and folder information stored in the mCompletion model.
    mCompletion.updateFromConfig(getDevices(true), getFolders());
}
Also used : BuildConfig(com.nutomic.syncthingandroid.BuildConfig) Config(com.nutomic.syncthingandroid.model.Config) Gson(com.google.gson.Gson)

Aggregations

Gson (com.google.gson.Gson)2 BuildConfig (com.nutomic.syncthingandroid.BuildConfig)2 Config (com.nutomic.syncthingandroid.model.Config)2 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 GetRequest (com.nutomic.syncthingandroid.http.GetRequest)1