mirror of
https://github.com/xpipe-io/xpipe.git
synced 2024-06-28 11:00:28 +12:00
Improve progress display for GB+
This commit is contained in:
parent
92faa26bbc
commit
76379b5a5d
|
@ -445,7 +445,7 @@ final class BrowserFileListComp extends SimpleComp {
|
||||||
if (path.getRawFileEntry().resolved().getKind() == FileKind.DIRECTORY) {
|
if (path.getRawFileEntry().resolved().getKind() == FileKind.DIRECTORY) {
|
||||||
setText("");
|
setText("");
|
||||||
} else {
|
} else {
|
||||||
setText(byteCount(fileSize.longValue(), true));
|
setText(byteCount(fileSize.longValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,8 +47,8 @@ public class BrowserStatusBarComp extends SimpleComp {
|
||||||
if (p == null || p.done()) {
|
if (p == null || p.done()) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
var transferred = HumanReadableFormat.byteCount(p.getTransferred(), false);
|
var transferred = HumanReadableFormat.progressByteCount(p.getTransferred());
|
||||||
var all = HumanReadableFormat.byteCount(p.getTotal(), true);
|
var all = HumanReadableFormat.byteCount(p.getTotal());
|
||||||
var name = (p.getName() != null ? " @ " + p.getName() + " " : "");
|
var name = (p.getName() != null ? " @ " + p.getName() + " " : "");
|
||||||
return transferred + " / " + all + name;
|
return transferred + " / " + all + name;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,17 +16,34 @@ public final class HumanReadableFormat {
|
||||||
public static final DateTimeFormatter DAY_OF_WEEK = DateTimeFormatter.ofPattern("EEE");
|
public static final DateTimeFormatter DAY_OF_WEEK = DateTimeFormatter.ofPattern("EEE");
|
||||||
public static final DateTimeFormatter HOUR_MINUTE = DateTimeFormatter.ofPattern("HH:mm");
|
public static final DateTimeFormatter HOUR_MINUTE = DateTimeFormatter.ofPattern("HH:mm");
|
||||||
|
|
||||||
public static String byteCount(long bytes, boolean precise) {
|
public static String byteCount(long bytes) {
|
||||||
if (-1024 < bytes && bytes < 1024) {
|
var b = 1024;
|
||||||
|
if (-b < bytes && bytes < b) {
|
||||||
return bytes + " B";
|
return bytes + " B";
|
||||||
}
|
}
|
||||||
CharacterIterator ci = new StringCharacterIterator("kMGTPE");
|
CharacterIterator ci = new StringCharacterIterator("kMGTPE");
|
||||||
while (bytes <= -1024 * 1024 || bytes >= 1024 * 1024) {
|
var mb = b * b;
|
||||||
bytes /= 1024;
|
while (bytes <= -mb || bytes >= mb) {
|
||||||
|
bytes /= b;
|
||||||
ci.next();
|
ci.next();
|
||||||
}
|
}
|
||||||
var f = precise ? "%.1f" : "%.0f";
|
var f = "%.1f";
|
||||||
return String.format(f + " %cB", bytes / 1024.0, ci.current());
|
return String.format(f + " %cB", bytes / (double) b, ci.current());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String progressByteCount(long bytes) {
|
||||||
|
var b = 1024;
|
||||||
|
if (-b < bytes && bytes < b) {
|
||||||
|
return bytes + " B";
|
||||||
|
}
|
||||||
|
CharacterIterator ci = new StringCharacterIterator("kMGTPE");
|
||||||
|
var mb = b * b;
|
||||||
|
while (bytes <= -mb || bytes >= mb) {
|
||||||
|
bytes /= b;
|
||||||
|
ci.next();
|
||||||
|
}
|
||||||
|
var f = ci.getIndex() >= 2 ? "%.3f" : "%.0f";
|
||||||
|
return String.format(f + " %cB", bytes / (double) b, ci.current());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String date(LocalDateTime x) {
|
public static String date(LocalDateTime x) {
|
||||||
|
|
Loading…
Reference in a new issue