Skip to content

Commit

Permalink
Show remaining bytes for devices (fixes #897)
Browse files Browse the repository at this point in the history
  • Loading branch information
Catfriend1 committed Jul 13, 2022
1 parent 25b67d8 commit a2fb2dd
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,24 @@ public int getDeviceCompletion(String deviceId) {
}
}

public double getDeviceNeedBytes(String deviceId) {
synchronized(mDeviceFolderMapLock) {
if (!mDeviceFolderMap.containsKey(deviceId)) {
LogV("getDeviceNeedBytes: Cache miss for deviceId=[" + deviceId + "]");
return 0;
}

double sumNeedBytes = 0;
HashMap<String, RemoteCompletionInfo> folderMap = mDeviceFolderMap.get(deviceId).getValue();
if (folderMap != null) {
for (Map.Entry<String, RemoteCompletionInfo> folder : folderMap.entrySet()) {
sumNeedBytes += folder.getValue().needBytes;
}
}
return sumNeedBytes;
}
}

/**
* Set completionInfo within the completion[deviceId][folderId] model.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
*/
public class RemoteCompletionInfo {
public double completion = 100;
public double needBytes = 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ private void onFolderCompletion(final Map<String, Object> eventData) {
mRestApi.setRemoteCompletionInfo(
(String) eventData.get("device"), // deviceId
(String) eventData.get("folder"), // folderId
(Double) eventData.get("needBytes"),
(Double) eventData.get("completion")
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,11 @@ public final int getRemoteDeviceCompletion(
return mRemoteCompletion.getDeviceCompletion(deviceId);
}

public final double getRemoteDeviceNeedBytes(
final String deviceId) {
return mRemoteCompletion.getDeviceNeedBytes(deviceId);
}

public final Connection getTotalConnectionStatistic() {
if (!mPreviousConnections.isPresent()) {
return new Connection();
Expand Down Expand Up @@ -1057,6 +1062,7 @@ public void setLocalFolderLastItemFinished(final String folderId,

public void setRemoteCompletionInfo(final String deviceId,
final String folderId,
final Double needBytes,
final Double completion) {
final Folder folder = getFolderByID(folderId);
if (folder == null) {
Expand All @@ -1075,8 +1081,10 @@ public void setRemoteCompletionInfo(final String deviceId,
LogV("setRemoteCompletionInfo: Paused folder \"" + folderId + "\" - got " +
remoteCompletionInfo.completion + "%, passing on 100%");
remoteCompletionInfo.completion = 100;
remoteCompletionInfo.needBytes = 0;
} else {
remoteCompletionInfo.completion = completion;
remoteCompletionInfo.needBytes = needBytes;
}
mRemoteCompletion.setCompletionInfo(deviceId, folderId, remoteCompletionInfo);
onTotalSyncCompletionChange();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static void copyDeviceId(Context context, String id) {
* <p>
* Based on http://stackoverflow.com/a/5599842
*/
public static String readableFileSize(Context context, long bytes) {
public static String readableFileSize(Context context, double bytes) {
final String[] units = context.getResources().getStringArray(R.array.file_size_units);
if (bytes <= 0) return "0 " + units[0];
int digitGroups = (int) (Math.log10(bytes) / Math.log10(1024));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ private void updateDeviceStatusView(ItemDeviceListBinding binding, Device device

final Connection conn = mRestApi.getRemoteDeviceStatus(device.deviceID);
final int completion = mRestApi.getRemoteDeviceCompletion(device.deviceID);
final double needBytes = mRestApi.getRemoteDeviceNeedBytes(device.deviceID);

if (conn.connected) {
binding.status.setVisibility(VISIBLE);
Expand Down Expand Up @@ -154,7 +155,12 @@ private void updateDeviceStatusView(ItemDeviceListBinding binding, Device device
}
} else {
binding.progressBar.setProgress(completion);
binding.status.setText(mContext.getString(R.string.device_syncing, completion));
binding.status.setText(
mContext.getString(R.string.device_syncing_percent_bytes,
completion,
Util.readableFileSize(getContext(), needBytes)
)
);
binding.status.setTextColor(ContextCompat.getColor(getContext(), R.color.text_blue));
}
return;
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ Please report any problems you encounter via Github.</string>

<!-- Indicates that the device is currently syncing. Parameter is sync percentage -->
<string name="device_syncing">Syncing (%1$d%%)</string>
<string name="device_syncing_percent_bytes">Syncing (%1$d%%, %2$s)</string>

<!-- Indicates that there is no connection to the device -->
<string name="device_disconnected">Disconnected</string>
Expand Down

0 comments on commit a2fb2dd

Please sign in to comment.