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;
}
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);
});
}
Aggregations