Fixes #4255 - Media details activity shows depictions in random languages, rather than in the user's locale (#4275)

* fixes issue with depiction names in random languages

* minor change

* using if conditions to check

Co-authored-by: Pratham2305 <Pratham2305@users.noreply.github.com>
This commit is contained in:
Pratham Pahariya 2021-03-01 16:20:09 +05:30 committed by GitHub
parent 0a857974f0
commit 93cd89a34b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -615,15 +615,27 @@ public class MediaDetailFragment extends CommonsDaggerSupportFragment implements
*/
private void buildDepictionList(List<IdAndCaptions> idAndCaptions) {
depictionContainer.removeAllViews();
String locale = Locale.getDefault().getLanguage();
for (IdAndCaptions idAndCaption : idAndCaptions) {
depictionContainer.addView(buildDepictLabel(
idAndCaption.getCaptions().values().iterator().next(),
getDepictionCaption(idAndCaption, locale),
idAndCaption.getId(),
depictionContainer
));
}
}
private String getDepictionCaption(IdAndCaptions idAndCaption, String locale) {
//Check if the Depiction Caption is available in user's locale if not then check for english, else show any available.
if(idAndCaption.getCaptions().get(locale) != null) {
return idAndCaption.getCaptions().get(locale);
}
if(idAndCaption.getCaptions().get("en") != null) {
return idAndCaption.getCaptions().get("en");
}
return idAndCaption.getCaptions().values().iterator().next();
}
@OnClick(R.id.mediaDetailLicense)
public void onMediaDetailLicenceClicked(){
String url = media.getLicenseUrl();