From 8d781844a2fce44fd116831146d800daf73b6efe Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Sun, 12 Oct 2014 13:46:26 +0300 Subject: [PATCH] Use inSyncBytes instead of localBytes to calculate sync progress (fixes #93). Also rename variable to clarify. --- .../syncthingandroid/syncthing/RestApi.java | 14 ++++++-------- .../syncthingandroid/util/FoldersAdapter.java | 12 ++++++------ 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java index 0d137836..30c93792 100644 --- a/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java +++ b/src/main/java/com/nutomic/syncthingandroid/syncthing/RestApi.java @@ -548,8 +548,8 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, return; Long now = System.currentTimeMillis(); - Long difference = (now - mPreviousConnectionTime) / 1000; - if (difference < 1) { + Long timeElapsed = (now - mPreviousConnectionTime) / 1000; + if (timeElapsed < 1) { listener.onReceiveConnections(mPreviousConnections); return; } @@ -573,12 +573,10 @@ public class RestApi implements SyncthingService.OnWebGuiAvailableListener, ? mPreviousConnections.get(deviceId) : new Connection(); mPreviousConnectionTime = now; - if (difference != 0) { - c.InBits = Math.max(0, 8 * - (conn.getLong("InBytesTotal") - prev.InBytesTotal) / difference); - c.OutBits = Math.max(0, 8 * - (conn.getLong("OutBytesTotal") - prev.OutBytesTotal) / difference); - } + c.InBits = Math.max(0, 8 * + (conn.getLong("InBytesTotal") - prev.InBytesTotal) / timeElapsed); + c.OutBits = Math.max(0, 8 * + (conn.getLong("OutBytesTotal") - prev.OutBytesTotal) / timeElapsed); connections.put(deviceId, c); diff --git a/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java b/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java index 47570707..6009d519 100644 --- a/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java +++ b/src/main/java/com/nutomic/syncthingandroid/util/FoldersAdapter.java @@ -47,14 +47,14 @@ public class FoldersAdapter extends ArrayAdapter state.setTextColor(getContext().getResources().getColor(R.color.text_green)); directory.setText((folder.Path)); if (model != null) { + int percentage = (model.globalBytes != 0) + ? (int) Math.floor(100 * model.inSyncBytes / model.globalBytes) + : 100; state.setText(getContext().getString(R.string.folder_progress_format, model.state, - (model.globalBytes <= 0) - ? 100 - : (int) ((model.localBytes / (float) model.globalBytes) * 100) - )); + percentage)); items.setText(getContext() - .getString(R.string.files, model.localFiles, model.globalFiles)); - size.setText(RestApi.readableFileSize(getContext(), model.localBytes) + " / " + + .getString(R.string.files, model.inSyncFiles, model.globalFiles)); + size.setText(RestApi.readableFileSize(getContext(), model.inSyncBytes) + " / " + RestApi.readableFileSize(getContext(), model.globalBytes)); if (folder.Invalid.equals("")) { invalid.setText(model.invalid);