Skip to content

Commit f01aa87

Browse files
authored
Fix inconsistency in getQuantity and add docs
`getQuantity()` was being called in many places with `zeroCaseStringId=0`, but that wasn't documented anywhere, and if `count==0` then `getString(zeroCaseStringId /* == 0 */)` would be returned which doesn't make sense
1 parent 56fb31d commit f01aa87

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

app/src/main/java/org/schabi/newpipe/util/Localization.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,23 @@ private static double round(final double value, final int scale) {
426426
return new BigDecimal(value).setScale(scale, RoundingMode.HALF_UP).doubleValue();
427427
}
428428

429+
/**
430+
* A wrapper around {@code context.getResources().getQuantityString()} with some safeguard.
431+
*
432+
* @param context the Android context
433+
* @param pluralId the ID of the plural resource
434+
* @param zeroCaseStringId the resource ID of the string to use in case {@code count=0},
435+
* or 0 if the plural resource should be used in the zero case too
436+
* @param count the number that should be used to pick the correct plural form
437+
* @param formattedCount the formatting parameter to substitute inside the plural resource,
438+
* ideally just {@code count} converted to string
439+
*/
429440
private static String getQuantity(@NonNull final Context context,
430441
@PluralsRes final int pluralId,
431442
@StringRes final int zeroCaseStringId,
432443
final long count,
433444
final String formattedCount) {
434-
if (count == 0) {
445+
if (count == 0 && zeroCaseStringId != 0) {
435446
return context.getString(zeroCaseStringId);
436447
}
437448

0 commit comments

Comments
 (0)