commit
c71e424088
1 changed files with 27 additions and 1 deletions
|
@ -4,6 +4,7 @@ package net.osmand.plus.wikivoyage;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -41,6 +42,7 @@ public class WikivoyageWebViewClient extends WebViewClient {
|
||||||
private TravelArticle article;
|
private TravelArticle article;
|
||||||
private boolean nightMode;
|
private boolean nightMode;
|
||||||
|
|
||||||
|
private static final String GEO_PARAMS = "?lat=";
|
||||||
private static final String PREFIX_GEO = "geo:";
|
private static final String PREFIX_GEO = "geo:";
|
||||||
private static final String PAGE_PREFIX_HTTP = "http://";
|
private static final String PAGE_PREFIX_HTTP = "http://";
|
||||||
private static final String PAGE_PREFIX_HTTPS = "https://";
|
private static final String PAGE_PREFIX_HTTPS = "https://";
|
||||||
|
@ -71,7 +73,10 @@ public class WikivoyageWebViewClient extends WebViewClient {
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else if (url.contains(WIKI_DOMAIN) && isWebPage && article != null) {
|
} else if (url.contains(WIKI_DOMAIN) && isWebPage && article != null) {
|
||||||
wikiArticleHelper.showWikiArticle(new LatLon(article.getLat(), article.getLon()), url);
|
LatLon articleCoordinates = parseCoordinates(url);
|
||||||
|
url = url.contains(GEO_PARAMS) ? url.substring(0, url.indexOf(GEO_PARAMS)) : url;
|
||||||
|
wikiArticleHelper.showWikiArticle(articleCoordinates == null ?
|
||||||
|
new LatLon(article.getLat(), article.getLon()) : articleCoordinates, url);
|
||||||
} else if (isWebPage) {
|
} else if (isWebPage) {
|
||||||
WikiArticleHelper.warnAboutExternalLoad(url, activity, nightMode);
|
WikiArticleHelper.warnAboutExternalLoad(url, activity, nightMode);
|
||||||
} else if (url.startsWith(PREFIX_GEO)) {
|
} else if (url.startsWith(PREFIX_GEO)) {
|
||||||
|
@ -123,6 +128,27 @@ public class WikivoyageWebViewClient extends WebViewClient {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private LatLon parseCoordinates(@NonNull String url) {
|
||||||
|
if (url.contains(GEO_PARAMS)) {
|
||||||
|
String geoPart = url.substring(url.indexOf(GEO_PARAMS));
|
||||||
|
int firstValueStart = geoPart.indexOf("=");
|
||||||
|
int firstValueEnd = geoPart.indexOf("&");
|
||||||
|
int secondValueStart = geoPart.indexOf("=", firstValueEnd);
|
||||||
|
if (firstValueStart != -1 && firstValueEnd != -1 && secondValueStart != -1
|
||||||
|
&& firstValueEnd > firstValueStart) {
|
||||||
|
String lat = geoPart.substring(firstValueStart + 1, firstValueEnd);
|
||||||
|
String lon = geoPart.substring(secondValueStart + 1);
|
||||||
|
try {
|
||||||
|
return new LatLon(Double.parseDouble(lat), Double.parseDouble(lon));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
Log.w(TAG, e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public void setArticle(@NonNull TravelArticle article) {
|
public void setArticle(@NonNull TravelArticle article) {
|
||||||
this.article = article;
|
this.article = article;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue