Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion app/src/main/java/org/schabi/newpipe/util/Localization.java
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,24 @@ private static double round(final double value, final int scale) {
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);
}

Expand Down