changed object article to LatLon

This commit is contained in:
Chumva 2018-05-10 11:26:56 +03:00
parent 7fd6f9d43f
commit ca4d2d47a3
3 changed files with 14 additions and 21 deletions

View file

@ -296,7 +296,7 @@ public class AmenityMenuBuilder extends MenuBuilder {
if (text.contains(".wikipedia.org/w")) { if (text.contains(".wikipedia.org/w")) {
if (Version.isPaidVersion(app)) { if (Version.isPaidVersion(app)) {
WikipediaArticleHelper wikipediaArticleHelper = new WikipediaArticleHelper(mapActivity, !light); WikipediaArticleHelper wikipediaArticleHelper = new WikipediaArticleHelper(mapActivity, !light);
wikipediaArticleHelper.getWikiArticle(amenity, text); wikipediaArticleHelper.showWikiArticle(amenity.getLocation(), text);
} else { } else {
WikipediaArticleWikiLinkFragment.showInstance(mapActivity.getSupportFragmentManager(), text); WikipediaArticleWikiLinkFragment.showInstance(mapActivity.getSupportFragmentManager(), text);
} }

View file

@ -22,7 +22,6 @@ import net.osmand.plus.download.DownloadResources;
import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.IndexItem;
import net.osmand.plus.resources.AmenityIndexRepositoryBinary; import net.osmand.plus.resources.AmenityIndexRepositoryBinary;
import net.osmand.plus.wikivoyage.article.WikivoyageArticleWikiLinkFragment; import net.osmand.plus.wikivoyage.article.WikivoyageArticleWikiLinkFragment;
import net.osmand.plus.wikivoyage.data.TravelArticle;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
@ -58,20 +57,20 @@ public class WikipediaArticleHelper {
private CallbackWithObject<String> callback; private CallbackWithObject<String> callback;
private WeakReference<MapActivity> weakMapActivity; private WeakReference<MapActivity> weakMapActivity;
private Object article; private LatLon articleLatLon;
private String regionName; private String regionName;
private String url; private String url;
private String lang; private String lang;
private String name; private String name;
private boolean isNightMode; private boolean isNightMode;
WikiArticleSearchTask(Object article, WikiArticleSearchTask(LatLon articleLatLon,
String regionName, String regionName,
MapActivity mapActivity, MapActivity mapActivity,
boolean nightMode, boolean nightMode,
String url, String url,
final CallbackWithObject<String> callback) { final CallbackWithObject<String> callback) {
this.article = article; this.articleLatLon = articleLatLon;
this.regionName = regionName; this.regionName = regionName;
weakMapActivity = new WeakReference<>(mapActivity); weakMapActivity = new WeakReference<>(mapActivity);
this.isNightMode = nightMode; this.isNightMode = nightMode;
@ -97,16 +96,9 @@ public class WikipediaArticleHelper {
if (application != null && !isCancelled()) { if (application != null && !isCancelled()) {
IndexItem item = null; IndexItem item = null;
try { try {
if (article != null) { if (articleLatLon != null) {
if (article instanceof TravelArticle) { item = DownloadResources.findSmallestIndexItemAt(application,
TravelArticle travelArticle = (TravelArticle) article; articleLatLon, DownloadActivityType.WIKIPEDIA_FILE);
item = DownloadResources.findSmallestIndexItemAt(application,
new LatLon(travelArticle.getLat(), travelArticle.getLon()), DownloadActivityType.WIKIPEDIA_FILE);
} else if (article instanceof Amenity) {
Amenity amenityArticle = (Amenity) article;
item = DownloadResources.findSmallestIndexItemAt(application,
amenityArticle.getLocation(), DownloadActivityType.WIKIPEDIA_FILE);
}
} }
} catch (IOException e) { } catch (IOException e) {
Log.e(TAG, e.getMessage(), e); Log.e(TAG, e.getMessage(), e);
@ -188,11 +180,11 @@ public class WikipediaArticleHelper {
return null; return null;
} }
public void getWikiArticle(Object article, String url) { public void showWikiArticle(LatLon articleLatLon, String url) {
if (article == null) { if (articleLatLon == null) {
return; return;
} }
articleSearchTask = new WikiArticleSearchTask(article, regionName, mapActivity, nightMode, url, new CallbackWithObject<String>() { articleSearchTask = new WikiArticleSearchTask(articleLatLon, regionName, mapActivity, nightMode, url, new CallbackWithObject<String>() {
@Override @Override
public boolean processResult(String s) { public boolean processResult(String s) {
regionName = s; regionName = s;

View file

@ -12,6 +12,7 @@ import android.util.Log;
import android.webkit.WebView; import android.webkit.WebView;
import android.webkit.WebViewClient; import android.webkit.WebViewClient;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -64,8 +65,8 @@ public class WikivoyageWebViewClient extends WebViewClient {
public boolean shouldOverrideUrlLoading(WebView view, String url) { public boolean shouldOverrideUrlLoading(WebView view, String url) {
boolean isWebPage = url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS); boolean isWebPage = url.startsWith(PAGE_PREFIX_HTTP) || url.startsWith(PAGE_PREFIX_HTTPS);
if (url.contains(WIKIVOAYAGE_DOMAIN) && isWebPage) { if (url.contains(WIKIVOAYAGE_DOMAIN) && isWebPage) {
String lang = wikipediaArticleHelper.getLang(url); String lang = WikipediaArticleHelper.getLang(url);
String articleName = wikipediaArticleHelper.getArticleNameFromUrl(url, lang); String articleName = WikipediaArticleHelper.getArticleNameFromUrl(url, lang);
long articleId = app.getTravelDbHelper().getArticleId(articleName, lang); long articleId = app.getTravelDbHelper().getArticleId(articleName, lang);
if (articleId != 0) { if (articleId != 0) {
WikivoyageArticleDialogFragment.showInstance(app, fragmentManager, articleId, lang); WikivoyageArticleDialogFragment.showInstance(app, fragmentManager, articleId, lang);
@ -74,7 +75,7 @@ public class WikivoyageWebViewClient extends WebViewClient {
} }
return true; return true;
} else if (url.contains(WIKI_DOMAIN) && isWebPage) { } else if (url.contains(WIKI_DOMAIN) && isWebPage) {
wikipediaArticleHelper.getWikiArticle(article, url); wikipediaArticleHelper.showWikiArticle(new LatLon(article.getLat(), article.getLon()), url);
} else if (isWebPage) { } else if (isWebPage) {
warnAboutExternalLoad(url, context, nightMode); warnAboutExternalLoad(url, context, nightMode);
} else if (url.startsWith(PREFIX_GEO)) { } else if (url.startsWith(PREFIX_GEO)) {