Skip to content

Commit 999501b

Browse files
committed
Fix StringFormatter
otherwise all numbers are concated
1 parent 11151b6 commit 999501b

1 file changed

Lines changed: 18 additions & 14 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/helper/PlayerHelper.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
import java.text.NumberFormat;
5454
import java.util.ArrayList;
5555
import java.util.Collections;
56-
import java.util.Formatter;
5756
import java.util.HashSet;
5857
import java.util.List;
5958
import java.util.Locale;
@@ -62,13 +61,13 @@
6261
import java.util.concurrent.TimeUnit;
6362

6463
public final class PlayerHelper {
65-
private static PlayerHelperFormatters formatters;
64+
private static PlayerHelperFormatters formattersInstance;
6665

6766
private static PlayerHelperFormatters formatters(final Context context) {
68-
if (formatters == null) {
69-
formatters = PlayerHelperFormatters.create(context);
67+
if (formattersInstance == null) {
68+
formattersInstance = PlayerHelperFormatters.create(context);
7069
}
71-
return formatters;
70+
return formattersInstance;
7271
}
7372

7473
@Retention(SOURCE)
@@ -101,13 +100,14 @@ public static String getTimeString(@NonNull final Context context, final int mil
101100
final int hours = (milliSeconds % 86400000) / 3600000;
102101
final int days = (milliSeconds % (86400000 * 7)) / 86400000;
103102

104-
final Formatter stringFormatter = formatters(context).string();
105-
return (days > 0
106-
? stringFormatter.format("%d:%02d:%02d:%02d", days, hours, minutes, seconds)
107-
: hours > 0
108-
? stringFormatter.format("%d:%02d:%02d", hours, minutes, seconds)
109-
: stringFormatter.format("%02d:%02d", minutes, seconds)
110-
).toString();
103+
final PlayerHelperFormatters formatters = formatters(context);
104+
if (days > 0) {
105+
return formatters.stringFormat("%d:%02d:%02d:%02d", days, hours, minutes, seconds);
106+
}
107+
108+
return hours > 0
109+
? formatters.stringFormat("%d:%02d:%02d", hours, minutes, seconds)
110+
: formatters.stringFormat("%02d:%02d", minutes, seconds);
111111
}
112112

113113
@NonNull
@@ -492,7 +492,7 @@ public static int retrieveSeekDurationFromPreferences(final Player player) {
492492
// endregion
493493

494494
record PlayerHelperFormatters(
495-
Formatter string,
495+
Locale locale,
496496
NumberFormat speed,
497497
NumberFormat pitch) {
498498

@@ -501,9 +501,13 @@ static PlayerHelperFormatters create(final Context context) {
501501

502502
final DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(locale);
503503
return new PlayerHelperFormatters(
504-
new Formatter(locale),
504+
locale,
505505
new DecimalFormat("0.##x", dfs),
506506
new DecimalFormat("##%", dfs));
507507
}
508+
509+
String stringFormat(final String format, final Object... args) {
510+
return String.format(locale, format, args);
511+
}
508512
}
509513
}

0 commit comments

Comments
 (0)