[Android] Use a more readable duration format in InfoActivity

Nicolas Pomepuy git at videolan.org
Tue Sep 24 16:29:44 CEST 2019


vlc-android | branch: 3.2.x | Nicolas Pomepuy <nicolas.pomepuy at gmail.com> | Tue Sep 17 11:52:03 2019 +0200| [79bce0fb158c54b097a09852f8fdd56a3bbb4952] | committer: Geoffrey Métais

Use a more readable duration format in InfoActivity

Refs #1032

(cherry picked from commit 79cae0959089b950c58228f6d8902697503e33c5)

> https://code.videolan.org/videolan/vlc-android/commit/79bce0fb158c54b097a09852f8fdd56a3bbb4952
---

 .../src/org/videolan/medialibrary/Tools.java       | 34 ++++++++++++++--------
 .../src/org/videolan/vlc/gui/InfoActivity.kt       |  2 +-
 2 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/medialibrary/src/org/videolan/medialibrary/Tools.java b/medialibrary/src/org/videolan/medialibrary/Tools.java
index 3ed456255..f83a1a31e 100644
--- a/medialibrary/src/org/videolan/medialibrary/Tools.java
+++ b/medialibrary/src/org/videolan/medialibrary/Tools.java
@@ -5,6 +5,8 @@ import android.net.Uri;
 import android.os.Environment;
 import android.text.TextUtils;
 
+import androidx.annotation.Nullable;
+
 import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper;
 import org.videolan.medialibrary.media.MediaLibraryItem;
 
@@ -12,8 +14,6 @@ import java.text.DecimalFormat;
 import java.text.NumberFormat;
 import java.util.Locale;
 
-import androidx.annotation.Nullable;
-
 public class Tools {
 
     private static final String TAG = "VLC/Tools";
@@ -40,8 +40,8 @@ public class Tools {
         long lastTime = media.getTime();
         if (lastTime == 0L) return "";
         return String.format("%s / %s",
-                millisToString(lastTime, true, false),
-                millisToString(media.getLength(), true, false));
+                millisToString(lastTime, true, false, false),
+                millisToString(media.getLength(), true, false, false));
     }
 
     /**
@@ -50,7 +50,7 @@ public class Tools {
      * @return formated string (hh:)mm:ss
      */
     public static String millisToString(long millis) {
-        return millisToString(millis, false, true);
+        return millisToString(millis, false, true, false);
     }
 
     /**
@@ -59,7 +59,17 @@ public class Tools {
      * @return formated string "[hh]h[mm]min" / "[mm]min[s]s"
      */
     public static String millisToText(long millis) {
-        return millisToString(millis, true, true);
+        return millisToString(millis, true, true, false);
+    }
+
+    /**
+     * Convert time to a string with large formatting
+     *
+     * @param millis e.g.time/length from file
+     * @return formated string "[hh]h [mm]min " / "[mm]min [s]s"
+     */
+    public static String millisToTextLarge(long millis) {
+        return millisToString(millis, true, true, true);
     }
 
     public static String getResolution(AbstractMediaWrapper media) {
@@ -92,7 +102,7 @@ public class Tools {
         }
     }
 
-    public static String millisToString(long millis, boolean text, boolean seconds) {
+    public static String millisToString(long millis, boolean text, boolean seconds, boolean large) {
         sb.setLength(0);
         if (millis < 0) {
             millis = -millis;
@@ -108,16 +118,16 @@ public class Tools {
 
         if (text) {
             if (hours > 0)
-                sb.append(hours).append('h');
+                sb.append(hours).append('h').append(large ? " " : "");
             if (min > 0)
-                sb.append(min).append("min");
+                sb.append(min).append("min").append(large ? " " : "");
             if ((seconds || sb.length() == 0) && sec > 0)
-                sb.append(sec).append("s");
+                sb.append(sec).append("s").append(large ? " " : "");
         } else {
             if (hours > 0)
-                sb.append(hours).append(':').append(format.format(min)).append(':').append(format.format(sec));
+                sb.append(hours).append(':').append(large ? " " : "").append(format.format(min)).append(':').append(large ? " " : "").append(format.format(sec));
             else
-                sb.append(min).append(':').append(format.format(sec));
+                sb.append(min).append(':').append(large ? " " : "").append(format.format(sec));
         }
         return sb.toString();
     }
diff --git a/vlc-android/src/org/videolan/vlc/gui/InfoActivity.kt b/vlc-android/src/org/videolan/vlc/gui/InfoActivity.kt
index 6ff43d540..9af4c4144 100644
--- a/vlc-android/src/org/videolan/vlc/gui/InfoActivity.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/InfoActivity.kt
@@ -112,7 +112,7 @@ class InfoActivity : AudioPlayerContainerActivity(), View.OnClickListener, PathA
         val nbTracks = tracks?.size ?: 0
         if (nbTracks > 0) for (media in tracks!!) length += media.length
         if (length > 0)
-            binding.length = Tools.millisToText(length)
+            binding.length = Tools.millisToTextLarge(length)
 
         if (item is AbstractMediaWrapper) {
             val media = item as AbstractMediaWrapper



More information about the Android mailing list