Merge pull request #5459 from osmandapp/PaulsBranch

Pauls branch
This commit is contained in:
vshcherb 2018-05-22 10:01:04 +02:00 committed by GitHub
commit 2866e6a5eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 10 additions and 2 deletions

View file

@ -42,6 +42,7 @@ public class WikiArticleHelper {
private static final int PARTIAL_CONTENT_PHRASES = 3;
private static final String PAGE_PREFIX_HTTP = "http://";
private static final String PAGE_PREFIX_HTTPS = "https://";
private static final String PAGE_PREFIX_FILE = "file://";
private static final String WIKIVOAYAGE_DOMAIN = ".wikivoyage.org/wiki/";
public static final String WIKI_DOMAIN = ".wikipedia.org/wiki/";
@ -59,6 +60,11 @@ public class WikiArticleHelper {
this.nightMode = nightMode;
}
public static String normalizeFileUrl(String url) {
return url.startsWith(PAGE_PREFIX_FILE) ?
url.replace(PAGE_PREFIX_FILE, PAGE_PREFIX_HTTPS) : url;
}
public static class WikiArticleSearchTask extends AsyncTask<Void, Void, List<Amenity>> {
private ProgressDialog dialog;

View file

@ -33,6 +33,7 @@ public class WikipediaWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
url = WikiArticleHelper.normalizeFileUrl(url);
if ((url.contains(WIKI_DOMAIN) || url.contains(WIKI_DOMAIN_COM)) && article != null) {
wikiArticleHelper.showWikiArticle(article.getLocation(), url);
} else if (url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS)) {

View file

@ -58,6 +58,7 @@ public class WikivoyageWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
url = WikiArticleHelper.normalizeFileUrl(url);
boolean isWebPage = url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS);
if (url.contains(WIKIVOAYAGE_DOMAIN) && isWebPage) {
String lang = WikiArticleHelper.getLang(url);
@ -69,7 +70,7 @@ public class WikivoyageWebViewClient extends WebViewClient {
WikiArticleHelper.warnAboutExternalLoad(url, activity, nightMode);
}
return true;
} else if (url.contains(WIKI_DOMAIN) && isWebPage) {
} else if (url.contains(WIKI_DOMAIN) && isWebPage && article != null) {
wikiArticleHelper.showWikiArticle(new LatLon(article.getLat(), article.getLon()), url);
} else if (isWebPage) {
WikiArticleHelper.warnAboutExternalLoad(url, activity, nightMode);

View file

@ -296,10 +296,10 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme
if (article == null) {
return;
}
webViewClient.setArticle(article);
articleToolbarText.setText(article.getTitle());
if (article.getGpxFile() != null && article.getGpxFile().getPointsSize() > 0) {
trackButton.setText(getString(R.string.shared_string_gpx_points) + " (" + article.getGpxFile().getPointsSize() + ")");
webViewClient.setArticle(article);
}
TravelLocalDataHelper ldh = getMyApplication().getTravelDbHelper().getLocalDataHelper();