Commit 53fb4a12 authored by Geoffrey Métais's avatar Geoffrey Métais

Make seconds optionnal in millisToStrings helper

parent 0a28c330
......@@ -41,8 +41,8 @@ public class Tools {
if (lastTime == 0L)
return "";
return String.format("%s / %s",
millisToString(lastTime, true),
millisToString(media.getLength(), true));
millisToString(lastTime, true, false),
millisToString(media.getLength(), true, false));
}
/**
......@@ -51,7 +51,7 @@ public class Tools {
* @return formated string (hh:)mm:ss
*/
public static String millisToString(long millis) {
return millisToString(millis, false);
return millisToString(millis, false, true);
}
/**
......@@ -60,7 +60,7 @@ public class Tools {
* @return formated string "[hh]h[mm]min" / "[mm]min[s]s"
*/
public static String millisToText(long millis) {
return millisToString(millis, true);
return millisToString(millis, true, true);
}
public static String getResolution(MediaWrapper media) {
......@@ -95,7 +95,7 @@ public class Tools {
}
}
public static String millisToString(long millis, boolean text) {
public static String millisToString(long millis, boolean text, boolean seconds) {
sb.setLength(0);
if (millis < 0) {
millis = -millis;
......@@ -114,7 +114,7 @@ public class Tools {
sb.append(hours).append('h');
if (min > 0)
sb.append(min).append("min");
if (sec > 0)
if ((seconds || sb.length() == 0) && sec > 0)
sb.append(sec).append("s");
} else {
if (hours > 0)
......
......@@ -8,12 +8,15 @@ public class ToolsTest extends TestCase {
}
public void testMillisToString() throws Exception {
assertEquals("3min30s", Tools.millisToString(210000, true));
assertEquals("3min", Tools.millisToString(180000, true));
assertEquals("1h30min30s", Tools.millisToString(5430000, true));
assertEquals("1h30min", Tools.millisToString(5400000, true));
assertEquals("1h30s", Tools.millisToString(3630000, true));
assertEquals("-32:40", Tools.millisToString(-1960000, false));
assertEquals("3min30s", Tools.millisToString(210000, true, true));
assertEquals("3min", Tools.millisToString(180000, true, true));
assertEquals("1h30min30s", Tools.millisToString(5430000, true, true));
assertEquals("1h30min", Tools.millisToString(5430000, true, false));
assertEquals("1h30min", Tools.millisToString(5400000, true, true));
assertEquals("17s", Tools.millisToString(17000, true, true));
assertEquals("17s", Tools.millisToString(17000, true, false));
assertEquals("1h30s", Tools.millisToString(3630000, true, true));
assertEquals("-32:40", Tools.millisToString(-1960000, false, true));
}
}
\ No newline at end of file
......@@ -119,7 +119,7 @@ public class InfoActivity extends AudioPlayerContainerActivity implements View.O
for (MediaWrapper media : tracks)
length += media.getLength();
if (length > 0)
mBinding.setLength(Tools.millisToString(length, true));
mBinding.setLength(Tools.millisToText(length));
if (mItem.getItemType() == MediaLibraryItem.TYPE_MEDIA) {
MediaWrapper media = (MediaWrapper) mItem;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment