OSDN Git Service

Eleven: Change playlist to the new layout, rip out dead code
[android-x86/packages-apps-Eleven.git] / src / com / cyngn / eleven / utils / MusicUtils.java
index d4067ba..edd741e 100644 (file)
@@ -190,13 +190,13 @@ public final class MusicUtils {
      * @param secs The track in seconds.
      * @return Duration of a track that's properly formatted.
      */
-    public static final String makeTimeString(final Context context, long secs) {
+    public static final String makeShortTimeString(final Context context, long secs) {
         long hours, mins;
 
         hours = secs / 3600;
-        secs -= hours * 3600;
+        secs %= 3600;
         mins = secs / 60;
-        secs -= mins * 60;
+        secs %= 60;
 
         final String durationFormat = context.getResources().getString(
                 hours == 0 ? R.string.durationformatshort : R.string.durationformatlong);
@@ -204,6 +204,34 @@ public final class MusicUtils {
     }
 
     /**
+     * * Used to create a formatted time string in the format of #d #h #m #s
+     *
+     * @param context The {@link Context} to use.
+     * @param secs The duration seconds.
+     * @return Duration properly formatted in #d #h #m #s format
+     */
+    public static final String makeLongTimeString(final Context context, long secs) {
+        long days, hours, mins;
+
+        days = secs / (3600 * 24);
+        secs %= (3600 * 24);
+        hours = secs / 3600;
+        secs %= 3600;
+        mins = secs / 60;
+        secs %= 60;
+
+        int stringId = R.string.duration_mins;
+        if (days != 0) {
+            stringId = R.string.duration_days;
+        } else if (hours != 0) {
+            stringId = R.string.duration_hours;
+        }
+
+        final String durationFormat = context.getResources().getString(stringId);
+        return String.format(durationFormat, days, hours, mins, secs);
+    }
+
+    /**
      * Changes to the next track
      */
     public static void next() {
@@ -1288,6 +1316,7 @@ public final class MusicUtils {
             try {
                 return mService.duration();
             } catch (final RemoteException ignored) {
+            } catch (final IllegalStateException ignored) {
             }
         }
         return 0;