use of org.robolectric.res.Plural in project robolectric by robolectric.
the class ShadowResourcesImpl method getQuantityString.
@Implementation
public String getQuantityString(int resId, int quantity) throws Resources.NotFoundException {
ShadowAssetManager shadowAssetManager = shadowOf(realResourcesImpl.getAssets());
TypedResource typedResource = shadowAssetManager.getResourceTable().getValue(resId, RuntimeEnvironment.getQualifiers());
if (typedResource != null && typedResource instanceof PluralResourceLoader.PluralRules) {
PluralResourceLoader.PluralRules pluralRules = (PluralResourceLoader.PluralRules) typedResource;
Plural plural = pluralRules.find(quantity);
if (plural == null) {
return null;
}
TypedResource<?> resolvedTypedResource = shadowAssetManager.resolve(new TypedResource<>(plural.getString(), ResType.CHAR_SEQUENCE, pluralRules.getXmlContext()), RuntimeEnvironment.getQualifiers(), resId);
return resolvedTypedResource == null ? null : resolvedTypedResource.asString();
} else {
return null;
}
}
Aggregations