Fix duration overflow and time unit plurals

This commit is contained in:
Martin Fietz 2015-08-02 17:43:41 +02:00
parent 759a7bb5ac
commit 65d470043b
4 changed files with 22 additions and 13 deletions

View File

@ -476,7 +476,7 @@ public class QueueFragment extends Fragment {
// refresh information bar
String info = queue.size() + getString(R.string.episodes_suffix);
if(queue.size() > 0) {
int duration = 0;
long duration = 0;
for(FeedItem item : queue) {
if(item.getMedia() != null) {
duration += item.getMedia().getDuration();

View File

@ -449,7 +449,7 @@ public class PreferenceController {
entries[x] = res.getString(R.string.pref_smart_mark_as_played_disabled);
} else {
Integer v = Integer.parseInt(values[x]);
entries[x] = v + " " + res.getString(R.string.time_unit_seconds);
entries[x] = res.getQuantityString(R.plurals.time_unit_seconds, v);
}
}
pref.setEntries(entries);

View File

@ -26,7 +26,7 @@ public final class Converter {
/** Determines the length of the number for best readability.*/
private static final int NUM_LENGTH = 1024;
private static final int DAYS_MIL = 86400000;
private static final int HOURS_MIL = 3600000;
private static final int MINUTES_MIL = 60000;
private static final int SECONDS_MIL = 1000;
@ -104,18 +104,18 @@ public final class Converter {
}
/** Converts milliseconds to a localized string containing hours and minutes */
public static String getDurationStringLocalized(Context context, int duration) {
int h = duration / HOURS_MIL;
int rest = duration - h * HOURS_MIL;
public static String getDurationStringLocalized(Context context, long duration) {
int h = (int)(duration / HOURS_MIL);
int rest = (int)(duration - h * HOURS_MIL);
int m = rest / MINUTES_MIL;
String result = "";
if(h > 0) {
String hours = context.getString(R.string.time_unit_hours);
result += h + " " + hours + " ";
String hours = context.getResources().getQuantityString(R.plurals.time_unit_hours, h, h);
result += hours + " ";
}
String minutes = context.getString(R.string.time_unit_minutes);
result += m + " " + minutes;
String minutes = context.getResources().getQuantityString(R.plurals.time_unit_minutes, m, m);
result += minutes;
return result;
}

View File

@ -380,9 +380,18 @@
<string name="sleep_timer_label">Sleep timer</string>
<string name="time_left_label">Time left:\u0020</string>
<string name="time_dialog_invalid_input">Invalid input, time has to be an integer</string>
<string name="time_unit_seconds">seconds</string>
<string name="time_unit_minutes">minutes</string>
<string name="time_unit_hours">hours</string>
<plurals name="time_unit_seconds">
<item quantity="one">1 second</item>
<item quantity="other">%d seconds</item>
</plurals>
<plurals name="time_unit_minutes">
<item quantity="one">1 minute</item>
<item quantity="other">%d minutes</item>
</plurals>
<plurals name="time_unit_hours">
<item quantity="one">1 hour</item>
<item quantity="other">%d hours</item>
</plurals>
<!-- gpodder.net -->
<string name="gpodnet_taglist_header">CATEGORIES</string>