mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-04-20 22:01:24 +00:00
Fix inconsistency in getQuantity and add docs
`getQuantity()` was being called in a couple of 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
This commit is contained in:
@@ -426,12 +426,24 @@ public final class Localization {
|
||||
return new BigDecimal(value).setScale(scale, RoundingMode.HALF_UP).doubleValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* A wrapper around {@code context.getResources().getQuantityString()} with some safeguard.
|
||||
*
|
||||
* @param context the Android context
|
||||
* @param pluralId the ID of the plural resource
|
||||
* @param zeroCaseStringId the resource ID of the string to use in case {@code count=0},
|
||||
* or 0 if the plural resource should be used in the zero case too
|
||||
* @param count the number that should be used to pick the correct plural form
|
||||
* @param formattedCount the formatting parameter to substitute inside the plural resource,
|
||||
* ideally just {@code count} converted to string
|
||||
* @return the formatted string with the correct pluralization
|
||||
*/
|
||||
private static String getQuantity(@NonNull final Context context,
|
||||
@PluralsRes final int pluralId,
|
||||
@StringRes final int zeroCaseStringId,
|
||||
final long count,
|
||||
final String formattedCount) {
|
||||
if (count == 0) {
|
||||
if (count == 0 && zeroCaseStringId != 0) {
|
||||
return context.getString(zeroCaseStringId);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user