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:
parent
6b5c1a1fbf
commit
8f2a0352d5
1 changed files with 13 additions and 1 deletions
|
|
@ -426,12 +426,24 @@ public final class Localization {
|
||||||
return new BigDecimal(value).setScale(scale, RoundingMode.HALF_UP).doubleValue();
|
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,
|
private static String getQuantity(@NonNull final Context context,
|
||||||
@PluralsRes final int pluralId,
|
@PluralsRes final int pluralId,
|
||||||
@StringRes final int zeroCaseStringId,
|
@StringRes final int zeroCaseStringId,
|
||||||
final long count,
|
final long count,
|
||||||
final String formattedCount) {
|
final String formattedCount) {
|
||||||
if (count == 0) {
|
if (count == 0 && zeroCaseStringId != 0) {
|
||||||
return context.getString(zeroCaseStringId);
|
return context.getString(zeroCaseStringId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue