added support for right to left layouts

This commit is contained in:
Chumva 2018-05-07 18:47:39 +03:00
parent 9ee379e816
commit bf6d670105

View file

@ -38,7 +38,9 @@ import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.io.File; import java.io.File;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.TreeSet; import java.util.TreeSet;
@ -54,6 +56,7 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
private String lang; private String lang;
private String title; private String title;
private String article; private String article;
private String langSelected;
public void setAmenity(Amenity amenity) { public void setAmenity(Amenity amenity) {
this.amenity = amenity; this.amenity = amenity;
@ -131,6 +134,10 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
@NonNull @NonNull
protected String createHtmlContent() { protected String createHtmlContent() {
StringBuilder sb = new StringBuilder(HEADER_INNER); StringBuilder sb = new StringBuilder(HEADER_INNER);
String[] rtlLanguages = new String[]{"ar", "dv", "he", "iw", "fa", "nqo", "ps", "sd", "ug", "ur", "yi"};
Set<String> rtls = new HashSet<>(Arrays.asList(rtlLanguages));
String bodyTag = rtls.contains(langSelected) ? "<body dir=\"rtl\">\n" : "<body>\n";
sb.append(bodyTag);
String nightModeClass = nightMode ? " nightmode" : ""; String nightModeClass = nightMode ? " nightmode" : "";
sb.append("<div class=\"main"); sb.append("<div class=\"main");
sb.append(nightModeClass); sb.append(nightModeClass);
@ -166,12 +173,11 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
preferredLanguage = getMyApplication().getLanguage(); preferredLanguage = getMyApplication().getLanguage();
} }
String lng = amenity.getContentLanguage("content", preferredLanguage, "en"); langSelected = amenity.getContentLanguage("content", preferredLanguage, "en");
if (Algorithms.isEmpty(lng)) { if (Algorithms.isEmpty(langSelected)) {
lng = "en"; langSelected = "en";
} }
final String langSelected = lng;
article = amenity.getDescription(langSelected); article = amenity.getDescription(langSelected);
title = amenity.getName(langSelected); title = amenity.getName(langSelected);
articleToolbarText.setText(title); articleToolbarText.setText(title);
@ -280,4 +286,4 @@ public class WikipediaDialogFragment extends WikiArticleBaseDialogFragment {
populateArticle(); populateArticle();
} }
} }
} }