Search in sources :

Example 1 with Model

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

the class RestApi method getDeviceCompletion.

/**
 * Calculates completion percentage for the given device using {@link #mCachedModelInfo}.
 */
private int getDeviceCompletion(String deviceId) {
    int folderCount = 0;
    float percentageSum = 0;
    // Syncthing UI limits pending deletes to 95% completion of a device
    int maxPercentage = 100;
    for (Map.Entry<String, Model> modelInfo : mCachedModelInfo.entrySet()) {
        boolean isShared = false;
        for (Folder r : getFolders()) {
            if (r.getDevice(deviceId) != null) {
                isShared = true;
                break;
            }
        }
        if (isShared) {
            long global = modelInfo.getValue().globalBytes;
            long local = modelInfo.getValue().inSyncBytes;
            if (modelInfo.getValue().needFiles == 0 && modelInfo.getValue().needDeletes > 0)
                maxPercentage = 95;
            percentageSum += (global != 0) ? (local * 100f) / global : 100f;
            folderCount++;
        }
    }
    return (folderCount != 0) ? Math.min(Math.round(percentageSum / folderCount), maxPercentage) : 100;
}
Also used : Model(com.nutomic.syncthingandroid.model.Model) Folder(com.nutomic.syncthingandroid.model.Folder) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 2 with Model

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

the class RestApi method getModel.

/**
 * Returns status information about the folder with the given id.
 */
public void getModel(final String folderId, final OnResultListener2<String, Model> listener) {
    new GetRequest(mContext, mUrl, GetRequest.URI_MODEL, mApiKey, ImmutableMap.of("folder", folderId), result -> {
        Model m = new Gson().fromJson(result, Model.class);
        mCachedModelInfo.put(folderId, m);
        listener.onResult(folderId, m);
    });
}
Also used : GetRequest(com.nutomic.syncthingandroid.http.GetRequest) Model(com.nutomic.syncthingandroid.model.Model) Gson(com.google.gson.Gson)

Aggregations

Model (com.nutomic.syncthingandroid.model.Model)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Gson (com.google.gson.Gson)1 GetRequest (com.nutomic.syncthingandroid.http.GetRequest)1 Folder (com.nutomic.syncthingandroid.model.Folder)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1