Merge pull request #5295 from osmandapp/PaulsBranch
Open wiki article in the same language as wikivoyage
This commit is contained in:
commit
4ecdfad6a9
2 changed files with 16 additions and 9 deletions
|
@ -271,17 +271,17 @@ public class WikipediaDialogFragment extends DialogFragment {
|
|||
return (OsmandApplication) getActivity().getApplication();
|
||||
}
|
||||
|
||||
public static boolean showInstance(AppCompatActivity activity, Amenity amenity) {
|
||||
public static boolean showInstance(AppCompatActivity activity, Amenity amenity, String lang) {
|
||||
try {
|
||||
if (!amenity.getType().isWiki()) {
|
||||
return false;
|
||||
}
|
||||
OsmandApplication app = (OsmandApplication) activity.getApplication();
|
||||
String lang = app.getSettings().MAP_PREFERRED_LOCALE.get();
|
||||
|
||||
WikipediaDialogFragment wikipediaDialogFragment = new WikipediaDialogFragment();
|
||||
wikipediaDialogFragment.setAmenity(amenity);
|
||||
wikipediaDialogFragment.setLanguage(lang);
|
||||
wikipediaDialogFragment.setLanguage(lang == null ?
|
||||
app.getSettings().MAP_PREFERRED_LOCALE.get() : lang);
|
||||
wikipediaDialogFragment.setRetainInstance(true);
|
||||
wikipediaDialogFragment.show(activity.getSupportFragmentManager(), TAG);
|
||||
return true;
|
||||
|
@ -289,4 +289,8 @@ public class WikipediaDialogFragment extends DialogFragment {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean showInstance(AppCompatActivity activity, Amenity amenity) {
|
||||
return showInstance(activity, amenity, null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,8 +91,9 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
|
|||
}
|
||||
return true;
|
||||
} else if (url.contains(WIKI_DOMAIN)) {
|
||||
String articleName = getArticleNameFromUrl(url, getLang(url));
|
||||
getWikiArticle(articleName, url);
|
||||
String lang = getLang(url);
|
||||
String articleName = getArticleNameFromUrl(url, lang);
|
||||
getWikiArticle(articleName, lang, url);
|
||||
} else if (url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS)) {
|
||||
warnAboutExternalLoad(url, context, nightMode);
|
||||
} else if (url.startsWith(PREFIX_GEO)) {
|
||||
|
@ -181,14 +182,14 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
|
|||
}
|
||||
}
|
||||
|
||||
private void getWikiArticle(String name, String url) {
|
||||
private void getWikiArticle(String name, String lang, String url) {
|
||||
List<AmenityIndexRepositoryBinary> indexes = app.getResourceManager()
|
||||
.getWikiAmenityRepository(article.getLat(), article.getLon());
|
||||
if (indexes.isEmpty()) {
|
||||
WikivoyageArticleWikiLinkFragment.showInstance(fragmentManager, regionName == null ?
|
||||
"" : regionName, url);
|
||||
} else {
|
||||
articleSearchTask = new WikiArticleSearchTask(name, indexes, (MapActivity) context, nightMode, url);
|
||||
articleSearchTask = new WikiArticleSearchTask(name, lang, indexes, (MapActivity) context, nightMode, url);
|
||||
articleSearchTask.execute();
|
||||
}
|
||||
|
||||
|
@ -274,10 +275,12 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
|
|||
private WeakReference<MapActivity> weakContext;
|
||||
private boolean isNightMode;
|
||||
private String url;
|
||||
private String lang;
|
||||
|
||||
WikiArticleSearchTask(String articleName, List<AmenityIndexRepositoryBinary> indexes,
|
||||
WikiArticleSearchTask(String articleName, String lang, List<AmenityIndexRepositoryBinary> indexes,
|
||||
MapActivity context, boolean isNightMode, String url) {
|
||||
name = articleName;
|
||||
this.lang = lang;
|
||||
this.indexes = indexes;
|
||||
weakContext = new WeakReference<>(context);
|
||||
dialog = createProgressDialog();
|
||||
|
@ -317,7 +320,7 @@ public class WikivoyageWebViewClient extends WebViewClient implements RegionCall
|
|||
if (activity != null && !activity.isActivityDestroyed() && dialog != null) {
|
||||
dialog.dismiss();
|
||||
if (!found.isEmpty()) {
|
||||
WikipediaDialogFragment.showInstance(activity, found.get(0));
|
||||
WikipediaDialogFragment.showInstance(activity, found.get(0), lang);
|
||||
} else {
|
||||
warnAboutExternalLoad(url, weakContext.get(), isNightMode);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue