diff options
Diffstat (limited to 'app/src/main/java/com/wuhei/reccoon/Formats.java')
| -rw-r--r-- | app/src/main/java/com/wuhei/reccoon/Formats.java | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/app/src/main/java/com/wuhei/reccoon/Formats.java b/app/src/main/java/com/wuhei/reccoon/Formats.java new file mode 100644 index 0000000..37e0909 --- /dev/null +++ b/app/src/main/java/com/wuhei/reccoon/Formats.java @@ -0,0 +1,67 @@ +package com.wuhei.reccoon; + +import java.util.Locale; + +/** Small formatting helpers shared by the activities. */ +public final class Formats { + + private Formats() { + } + + /** Turns {@code reccoon-2026-09-24-153000-00001.wav} into a readable label. */ + public static String prettyName(String fileName) { + if (fileName == null) { + return ""; + } + String core = fileName; + if (core.startsWith("reccoon-")) { + core = core.substring("reccoon-".length()); + } + if (core.endsWith(".wav")) { + core = core.substring(0, core.length() - 4); + } + String[] parts = core.split("-"); + if (parts.length >= 4) { + String date = parts[0] + "-" + parts[1] + "-" + parts[2]; + String time = parts[3]; + String sequence = parts.length >= 5 ? parts[4] : ""; + if (time.length() == 6) { + time = time.substring(0, 2) + ":" + time.substring(2, 4) + ":" + time.substring(4); + } + return date + " " + time + (sequence.isEmpty() ? "" : " #" + sequence); + } + return core; + } + + public static String duration(long millis) { + long totalSeconds = Math.max(0, millis) / 1000; + long hours = totalSeconds / 3600; + long minutes = (totalSeconds % 3600) / 60; + long seconds = totalSeconds % 60; + if (hours > 0) { + return String.format(Locale.US, "%d:%02d:%02d", hours, minutes, seconds); + } + return String.format(Locale.US, "%d:%02d", minutes, seconds); + } + + public static String size(long bytes) { + double mb = bytes / 1048576.0; + if (mb >= 1) { + return String.format(Locale.US, "%.1f MB", mb); + } + return String.format(Locale.US, "%d KB", bytes / 1024); + } + + public static String humanBytes(long bytes) { + double mb = bytes / 1048576.0; + if (mb >= 1) { + return String.format(Locale.US, "%.0f MB", mb); + } + return String.format(Locale.US, "%.0f KB", bytes / 1024.0); + } + + /** mm:ss or h:mm:ss from milliseconds. */ + public static String clock(int millis) { + return duration(millis); + } +} |
