Merge pull request #10467 from osmandapp/fix_wikioyage_links

Fix wikivoyage links
This commit is contained in:
alex-osm 2020-12-24 14:56:52 +03:00 committed by GitHub
commit 3f6916b990
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View file

@ -46,7 +46,7 @@ public class WikiArticleHelper {
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 WIKIVOYAGE_DOMAIN = ".wikivoyage.org/wiki/";
public static final String WIKI_DOMAIN = ".wikipedia.org/wiki/";
public static final String WIKI_DOMAIN_COM = ".wikipedia.com/wiki/";
@ -245,7 +245,7 @@ public class WikiArticleHelper {
}
public static String getArticleNameFromUrl(String url, String lang) {
String domain = url.contains(WIKIVOAYAGE_DOMAIN) ? WIKIVOAYAGE_DOMAIN :
String domain = url.contains(WIKIVOYAGE_DOMAIN) ? WIKIVOYAGE_DOMAIN :
url.contains(WIKI_DOMAIN) ? WIKI_DOMAIN : WIKI_DOMAIN_COM;
String articleName = "";

View file

@ -27,6 +27,7 @@ import net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity;
import java.io.File;
import java.util.List;
import static net.osmand.plus.wikipedia.WikiArticleHelper.WIKIVOYAGE_DOMAIN;
import static net.osmand.plus.wikipedia.WikiArticleHelper.WIKI_DOMAIN;
@ -48,7 +49,6 @@ public class WikivoyageWebViewClient extends WebViewClient {
private static final String PREFIX_GEO = "geo:";
private static final String PAGE_PREFIX_HTTP = "http://";
private static final String PAGE_PREFIX_HTTPS = "https://";
private static final String WIKIVOAYAGE_DOMAIN = ".wikivoyage.org/wiki/";
private WikiArticleHelper wikiArticleHelper;
@ -64,11 +64,11 @@ public class WikivoyageWebViewClient extends WebViewClient {
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) {
if (url.contains(WIKIVOYAGE_DOMAIN) && isWebPage) {
String lang = WikiArticleHelper.getLang(url);
String articleName = WikiArticleHelper.getArticleNameFromUrl(url, lang);
String articleId = app.getTravelHelper().getArticleId(articleName, lang);
if (articleId.isEmpty()) {
if (!articleId.isEmpty()) {
WikivoyageArticleDialogFragment.showInstance(app, fragmentManager, articleId, lang);
} else {
WikiArticleHelper.warnAboutExternalLoad(url, activity, nightMode);