From 93093ea42838fc2bac09b0ff04d791d5e7840b00 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Tue, 26 Jan 2021 19:02:55 +0300 Subject: [PATCH] Added progress bar while reading travel article gpx --- .../fragment_wikivoyage_article_dialog.xml | 8 + .../TrackActivityFragmentAdapter.java | 2 +- .../WikivoyageArticleDialogFragment.java | 42 ++++- .../WikivoyageArticleNavigationFragment.java | 6 +- .../plus/wikivoyage/data/TravelArticle.java | 1 + .../plus/wikivoyage/data/TravelDbHelper.java | 18 +- .../plus/wikivoyage/data/TravelHelper.java | 21 ++- .../data/TravelLocalDataHelper.java | 2 +- .../plus/wikivoyage/data/TravelObfHelper.java | 162 +++++++++++------- .../menu/WikivoyageWptPtMenuController.java | 6 +- 10 files changed, 181 insertions(+), 87 deletions(-) diff --git a/OsmAnd/res/layout/fragment_wikivoyage_article_dialog.xml b/OsmAnd/res/layout/fragment_wikivoyage_article_dialog.xml index 76fe893831..1643d43234 100644 --- a/OsmAnd/res/layout/fragment_wikivoyage_article_dialog.xml +++ b/OsmAnd/res/layout/fragment_wikivoyage_article_dialog.xml @@ -145,6 +145,14 @@ tools:drawableStart="@drawable/ic_action_markers_dark" android:paddingEnd="@dimen/bottom_sheet_content_padding_small" /> + + 0) { - trackButton.setVisibility(View.VISIBLE); - trackButton.setText(getString(R.string.shared_string_gpx_points) + " (" + gpxFile.getPointsSize() + ")"); - } else { - trackButton.setVisibility(View.GONE); - } TravelLocalDataHelper ldh = getMyApplication().getTravelHelper().getBookmarksHelper(); ldh.addToHistory(article); @@ -327,6 +336,21 @@ public class WikivoyageArticleDialogFragment extends WikiArticleBaseDialogFragme contentWebView.loadDataWithBaseURL(getBaseUrl(), createHtmlContent(), "text/html", "UTF-8", null); } + private void updateTrackButton(boolean processing, @Nullable GPXFile gpxFile) { + if (processing) { + trackButton.setVisibility(View.GONE); + gpxProgress.setVisibility(View.VISIBLE); + } else { + if (gpxFile != null && gpxFile.getPointsSize() > 0) { + trackButton.setVisibility(View.VISIBLE); + trackButton.setText(getString(R.string.shared_string_gpx_points) + " (" + gpxFile.getPointsSize() + ")"); + } else { + trackButton.setVisibility(View.GONE); + } + gpxProgress.setVisibility(View.GONE); + } + } + @NonNull @Override protected String createHtmlContent() { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleNavigationFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleNavigationFragment.java index 1018874d26..98500afa01 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleNavigationFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/article/WikivoyageArticleNavigationFragment.java @@ -20,6 +20,7 @@ import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.base.MenuBottomSheetDialogFragment; @@ -75,14 +76,15 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr return; } - article = getMyApplication().getTravelHelper().getArticleById(articleId, selectedLang); + OsmandApplication app = requiredMyApplication(); + article = app.getTravelHelper().getArticleById(articleId, selectedLang, false, null); if (article == null) { return; } parentsList = new ArrayList<>(Arrays.asList(article.getAggregatedPartOf().split(","))); Map> navigationMap - = getMyApplication().getTravelHelper().getNavigationMap(article); + = app.getTravelHelper().getNavigationMap(article); items.add(new TitleItem(getString(R.string.shared_string_navigation))); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java index cf38b7265f..952b85be4d 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java @@ -44,6 +44,7 @@ public class TravelArticle { String aggregatedPartOf; long lastModified; + boolean gpxFileReading; boolean gpxFileRead; @NonNull diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java index 38380015c3..b53605a0bb 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java @@ -549,7 +549,7 @@ public class TravelDbHelper implements TravelHelper { @Override @Nullable - public TravelArticle getArticleById(@NonNull TravelArticleIdentifier articleId, @NonNull String lang) { + public TravelArticle getArticleById(@NonNull TravelArticleIdentifier articleId, @NonNull String lang, boolean readGpx, @Nullable GpxReadCallback callback) { TravelArticle res = null; SQLiteConnection conn = openConnection(); String routeId = articleId.routeId; @@ -566,24 +566,27 @@ public class TravelDbHelper implements TravelHelper { if (res == null) { res = localDataHelper.getSavedArticle(articleId.file, articleId.routeId, lang); } + if (res != null && callback != null) { + callback.onGpxFileRead(res.gpxFile); + } return res; } @Nullable @Override - public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull final String lang) { - return getArticleByTitle(title, new QuadRect(), lang); + public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull final String lang, boolean readGpx, @Nullable GpxReadCallback callback) { + return getArticleByTitle(title, new QuadRect(), lang, readGpx, callback); } @Nullable @Override - public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull LatLon latLon, @NonNull final String lang) { - return getArticleByTitle(title, new QuadRect(), lang); + public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull LatLon latLon, @NonNull final String lang, boolean readGpx, @Nullable GpxReadCallback callback) { + return getArticleByTitle(title, new QuadRect(), lang, readGpx, callback); } @Nullable @Override - public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull QuadRect rect, @NonNull final String lang) { + public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull QuadRect rect, @NonNull final String lang, boolean readGpx, @Nullable GpxReadCallback callback) { TravelArticle res = null; SQLiteConnection conn = openConnection(); if (conn != null) { @@ -596,6 +599,9 @@ public class TravelDbHelper implements TravelHelper { cursor.close(); } } + if (res != null && callback != null) { + callback.onGpxFileRead(res.gpxFile); + } return res; } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java index 87b5bc1e95..967138b0bd 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelHelper.java @@ -3,6 +3,8 @@ package net.osmand.plus.wikivoyage.data; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import net.osmand.GPXUtilities; +import net.osmand.GPXUtilities.GPXFile; import net.osmand.data.LatLon; import net.osmand.data.QuadRect; import net.osmand.plus.wikivoyage.data.TravelArticle.TravelArticleIdentifier; @@ -14,6 +16,11 @@ import java.util.Map; public interface TravelHelper { + interface GpxReadCallback { + void onGpxFileReading(); + void onGpxFileRead(@Nullable GPXFile gpxFile); + } + TravelLocalDataHelper getBookmarksHelper(); void initializeDataOnAppStartup(); @@ -29,19 +36,19 @@ public interface TravelHelper { List getPopularArticles(); @NonNull - Map> getNavigationMap(@NonNull final TravelArticle article); + Map> getNavigationMap(@NonNull TravelArticle article); @Nullable - TravelArticle getArticleById(@NonNull TravelArticleIdentifier articleId, @NonNull String lang); + TravelArticle getArticleById(@NonNull TravelArticleIdentifier articleId, @NonNull String lang, boolean readGpx, @Nullable GpxReadCallback callback); @Nullable - public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull final String lang); + TravelArticle getArticleByTitle(@NonNull String title, @NonNull String lang, boolean readGpx, @Nullable GpxReadCallback callback); @Nullable - public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull LatLon latLon, @NonNull final String lang); + TravelArticle getArticleByTitle(@NonNull String title, @NonNull LatLon latLon, @NonNull String lang, boolean readGpx, @Nullable GpxReadCallback callback); @Nullable - TravelArticle getArticleByTitle(@NonNull String title, @NonNull QuadRect rect, @NonNull String lang); + TravelArticle getArticleByTitle(@NonNull String title, @NonNull QuadRect rect, @NonNull String lang, boolean readGpx, @Nullable GpxReadCallback callback); @Nullable TravelArticleIdentifier getArticleId(@NonNull String title, @NonNull String lang); @@ -50,10 +57,10 @@ public interface TravelHelper { ArrayList getArticleLangs(@NonNull TravelArticleIdentifier articleId); @NonNull - String getGPXName(@NonNull final TravelArticle article); + String getGPXName(@NonNull TravelArticle article); @NonNull - File createGpxFile(@NonNull final TravelArticle article); + File createGpxFile(@NonNull TravelArticle article); // TODO: this method should be deleted once TravelDBHelper is deleted @Nullable diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java index 2c59c16ed2..02ee5a32c8 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java @@ -420,7 +420,7 @@ public class TravelLocalDataHelper { if (cursor.moveToFirst()) { do { TravelArticle dbArticle = readSavedArticle(cursor); - TravelArticle article = context.getTravelHelper().getArticleById(dbArticle.generateIdentifier(), dbArticle.lang); + TravelArticle article = context.getTravelHelper().getArticleById(dbArticle.generateIdentifier(), dbArticle.lang, false, null); if (article != null && article.getLastModified() > dbArticle.getLastModified()) { updateSavedArticle(dbArticle, article); res.add(article); diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 9a2c80940c..9ea963db81 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -1,5 +1,6 @@ package net.osmand.plus.wikivoyage.data; +import android.os.AsyncTask; import android.text.TextUtils; import androidx.annotation.NonNull; @@ -97,9 +98,19 @@ public class TravelObfHelper implements TravelHelper { location, POPULAR_ARTICLES_SEARCH_RADIUS, -1, getSearchFilter(false), null); List amenities = reader.searchPoi(req); if (amenities.size() > 0) { + Collections.sort(amenities, new Comparator() { + @Override + public int compare(Amenity a1, Amenity a2) { + int d1 = (int) (MapUtils.getDistance(a1.getLocation().getLatitude(), a1.getLocation().getLongitude(), + location.getLatitude(), location.getLongitude())); + int d2 = (int) (MapUtils.getDistance(a2.getLocation().getLatitude(), a2.getLocation().getLongitude(), + location.getLatitude(), location.getLongitude())); + return d1 < d2 ? -1 : (d1 == d2 ? 0 : 1); + } + }); for (Amenity amenity : amenities) { if (!Algorithms.isEmpty(amenity.getName(lang))) { - TravelArticle article = cacheTravelArticles(reader.getFile(), amenity, lang, false); + TravelArticle article = cacheTravelArticles(reader.getFile(), amenity, lang, false, null); if (article != null) { popularArticles.add(article); if (popularArticles.size() >= MAX_POPULAR_ARTICLES_COUNT) { @@ -108,16 +119,6 @@ public class TravelObfHelper implements TravelHelper { } } } - Collections.sort(popularArticles, new Comparator() { - @Override - public int compare(TravelArticle article1, TravelArticle article2) { - int d1 = (int) (MapUtils.getDistance(article1.getLat(), article1.getLon(), - location.getLatitude(), location.getLongitude())); - int d2 = (int) (MapUtils.getDistance(article2.getLat(), article2.getLon(), - location.getLatitude(), location.getLongitude())); - return d1 < d2 ? -1 : (d1 == d2 ? 0 : 1); - } - }); } } catch (Exception e) { LOG.error(e.getMessage(), e); @@ -128,13 +129,13 @@ public class TravelObfHelper implements TravelHelper { } @Nullable - private TravelArticle cacheTravelArticles(File file, Amenity amenity, String lang, boolean readPoints) { + private TravelArticle cacheTravelArticles(File file, Amenity amenity, String lang, boolean readPoints, @Nullable GpxReadCallback callback) { TravelArticle article = null; - Map articles = readArticles(file, amenity, false); + Map articles = readArticles(file, amenity); if (!Algorithms.isEmpty(articles)) { TravelArticleIdentifier newArticleId = articles.values().iterator().next().generateIdentifier(); cachedArticles.put(newArticleId, articles); - article = getCachedArticle(newArticleId, lang, readPoints); + article = getCachedArticle(newArticleId, lang, readPoints, callback); } return article; } @@ -155,17 +156,17 @@ public class TravelObfHelper implements TravelHelper { } @NonNull - private Map readArticles(@NonNull File file, @NonNull Amenity amenity, boolean readPoints) { + private Map readArticles(@NonNull File file, @NonNull Amenity amenity) { Map articles = new HashMap<>(); Set langs = getLanguages(amenity); for (String lang : langs) { - articles.put(lang, readArticle(file, amenity, lang, readPoints)); + articles.put(lang, readArticle(file, amenity, lang)); } return articles; } @NonNull - private TravelArticle readArticle(@NonNull File file, @NonNull Amenity amenity, @NonNull String lang, boolean readPoints) { + private TravelArticle readArticle(@NonNull File file, @NonNull Amenity amenity, @NonNull String lang) { TravelArticle res = new TravelArticle(); res.file = file; String title = amenity.getName(lang); @@ -182,29 +183,11 @@ public class TravelObfHelper implements TravelHelper { res.lang = lang; res.contentsJson = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.CONTENT_JSON, lang)); res.aggregatedPartOf = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.IS_AGGR_PART, lang)); - if (readPoints) { - res.gpxFile = buildGpxFile(res); - res.gpxFileRead = true; - } return res; } - private GPXFile buildGpxFile(@NonNull TravelArticle article) { - GPXFile gpxFile = null; - List pointList = getPointList(article); - if (!Algorithms.isEmpty(pointList)) { - gpxFile = new GPXFile(article.getTitle(), article.getLang(), article.getContent()); - gpxFile.metadata.link = TravelArticle.getImageUrl(article.getImageTitle(), false); - for (Amenity amenity : pointList) { - WptPt wptPt = createWptPt(amenity, article.getLang()); - gpxFile.addPoint(wptPt); - } - } - return gpxFile; - } - @NonNull - private List getPointList(@NonNull final TravelArticle article) { + private synchronized List getPointList(@NonNull final TravelArticle article) { final List pointList = new ArrayList<>(); final String lang = article.getLang(); for (BinaryMapIndexReader reader : getReaders()) { @@ -312,7 +295,7 @@ public class TravelObfHelper implements TravelHelper { for (Amenity amenity : entry.getValue()) { Set nameLangs = getLanguages(amenity); if (nameLangs.contains(appLang)) { - TravelArticle article = readArticle(file, amenity, appLang, false); + TravelArticle article = readArticle(file, amenity, appLang); ArrayList langs = new ArrayList<>(nameLangs); Collections.sort(langs, new Comparator() { @Override @@ -481,20 +464,28 @@ public class TravelObfHelper implements TravelHelper { LOG.error(e.getMessage()); } if (!Algorithms.isEmpty(amenities)) { - article = readArticle(reader.getFile(), amenities.get(0), lang, false); + article = readArticle(reader.getFile(), amenities.get(0), lang); } } return article; } @Override - public TravelArticle getArticleById(@NonNull TravelArticleIdentifier articleId, @NonNull String lang) { - TravelArticle article = getCachedArticle(articleId, lang, true); - return article == null ? localDataHelper.getSavedArticle(articleId.file, articleId.routeId, lang) : article; + public TravelArticle getArticleById(@NonNull TravelArticleIdentifier articleId, @NonNull String lang, + boolean readGpx, @Nullable GpxReadCallback callback) { + TravelArticle article = getCachedArticle(articleId, lang, readGpx, callback); + if (article == null) { + article = localDataHelper.getSavedArticle(articleId.file, articleId.routeId, lang); + if (article != null && callback != null && readGpx) { + callback.onGpxFileRead(article.gpxFile); + } + } + return article; } @Nullable - private TravelArticle getCachedArticle(@NonNull TravelArticleIdentifier articleId, @NonNull String lang, boolean forceReadPoints) { + private TravelArticle getCachedArticle(@NonNull TravelArticleIdentifier articleId, @NonNull String lang, + boolean forceReadPoints, @Nullable GpxReadCallback callback) { TravelArticle article = null; Map articles = cachedArticles.get(articleId); if (articles != null) { @@ -511,16 +502,24 @@ public class TravelObfHelper implements TravelHelper { } } if (article == null && articles == null) { - article = findArticleById(articleId, lang); + article = findArticleById(articleId, lang, callback); } - if (article != null && !article.gpxFileRead && forceReadPoints && !Algorithms.isEmpty(lang)) { - article.gpxFile = buildGpxFile(article); - article.gpxFileRead = true; + if (article != null && forceReadPoints && !Algorithms.isEmpty(lang)) { + readGpxFile(article, callback); } return article; } - private TravelArticle findArticleById(@NonNull final TravelArticleIdentifier articleId, final String lang) { + private void readGpxFile(@NonNull TravelArticle article, @Nullable GpxReadCallback callback) { + if (!article.gpxFileRead) { + new GpxFileReader(article, callback).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } else if (callback != null) { + callback.onGpxFileRead(article.gpxFile); + } + } + + private TravelArticle findArticleById(@NonNull final TravelArticleIdentifier articleId, + final String lang, @Nullable GpxReadCallback callback) { TravelArticle article = null; final boolean isDbArticle = articleId.file != null && articleId.file.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT); final List amenities = new ArrayList<>(); @@ -563,7 +562,7 @@ public class TravelObfHelper implements TravelHelper { LOG.error(e.getMessage()); } if (!Algorithms.isEmpty(amenities)) { - article = cacheTravelArticles(reader.getFile(), amenities.get(0), lang, true); + article = cacheTravelArticles(reader.getFile(), amenities.get(0), lang, true, callback); } } return article; @@ -571,20 +570,23 @@ public class TravelObfHelper implements TravelHelper { @Nullable @Override - public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull final String lang) { - return getArticleByTitle(title, new QuadRect(), lang); + public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull final String lang, + boolean readGpx, @Nullable GpxReadCallback callback) { + return getArticleByTitle(title, new QuadRect(), lang, readGpx, callback); } @Nullable @Override - public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull LatLon latLon, @NonNull final String lang) { - QuadRect rect = latLon != null ? MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), ARTICLE_SEARCH_RADIUS) : new QuadRect(); - return getArticleByTitle(title, rect, lang); + public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull LatLon latLon, + @NonNull final String lang, boolean readGpx, @Nullable GpxReadCallback callback) { + QuadRect rect = MapUtils.calculateLatLonBbox(latLon.getLatitude(), latLon.getLongitude(), ARTICLE_SEARCH_RADIUS); + return getArticleByTitle(title, rect, lang, readGpx, callback); } @Nullable @Override - public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull QuadRect rect, @NonNull final String lang) { + public TravelArticle getArticleByTitle(@NonNull final String title, @NonNull QuadRect rect, + @NonNull final String lang, boolean readGpx, @Nullable GpxReadCallback callback) { TravelArticle article = null; final List amenities = new ArrayList<>(); int x = 0; @@ -627,7 +629,7 @@ public class TravelObfHelper implements TravelHelper { LOG.error(e.getMessage()); } if (!Algorithms.isEmpty(amenities)) { - article = cacheTravelArticles(reader.getFile(), amenities.get(0), lang, true); + article = cacheTravelArticles(reader.getFile(), amenities.get(0), lang, readGpx, callback); } } return article; @@ -654,7 +656,7 @@ public class TravelObfHelper implements TravelHelper { } } if (a == null) { - TravelArticle article = getArticleByTitle(title, lang); + TravelArticle article = getArticleByTitle(title, lang, false, null); if (article != null) { a = article; } @@ -666,7 +668,7 @@ public class TravelObfHelper implements TravelHelper { @Override public ArrayList getArticleLangs(@NonNull TravelArticleIdentifier articleId) { ArrayList res = new ArrayList<>(); - TravelArticle article = getArticleById(articleId, ""); + TravelArticle article = getArticleById(articleId, "", false, null); if (article != null) { Map articles = cachedArticles.get(article.generateIdentifier()); if (articles != null) { @@ -683,14 +685,14 @@ public class TravelObfHelper implements TravelHelper { @NonNull @Override - public String getGPXName(@NonNull final TravelArticle article) { + public String getGPXName(@NonNull TravelArticle article) { return article.getTitle().replace('/', '_').replace('\'', '_') .replace('\"', '_') + IndexConstants.GPX_FILE_EXT; } @NonNull @Override - public File createGpxFile(@NonNull final TravelArticle article) { + public File createGpxFile(@NonNull TravelArticle article) { final GPXFile gpx = article.getGpxFile(); File file = app.getAppPath(IndexConstants.GPX_TRAVEL_DIR + getGPXName(article)); writeGpxFile(file, gpx); @@ -706,4 +708,46 @@ public class TravelObfHelper implements TravelHelper { public String getWikivoyageFileName() { return WORLD_WIKIVOYAGE_FILE_NAME; } + + private class GpxFileReader extends AsyncTask { + + private final TravelArticle article; + private final GpxReadCallback callback; + + public GpxFileReader(@NonNull TravelArticle article, @Nullable GpxReadCallback callback) { + this.article = article; + this.callback = callback; + } + + @Override + protected void onPreExecute() { + if (callback != null) { + callback.onGpxFileReading(); + } + } + + @Override + protected GPXFile doInBackground(Void... voids) { + GPXFile gpxFile = null; + List pointList = getPointList(article); + if (!Algorithms.isEmpty(pointList)) { + gpxFile = new GPXFile(article.getTitle(), article.getLang(), article.getContent()); + gpxFile.metadata.link = TravelArticle.getImageUrl(article.getImageTitle(), false); + for (Amenity amenity : pointList) { + WptPt wptPt = createWptPt(amenity, article.getLang()); + gpxFile.addPoint(wptPt); + } + } + return gpxFile; + } + + @Override + protected void onPostExecute(GPXFile gpxFile) { + article.gpxFileRead = true; + article.gpxFile = gpxFile; + if (callback != null) { + callback.onGpxFileRead(gpxFile); + } + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuController.java b/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuController.java index 6f3ee2fd43..84507da899 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuController.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/menu/WikivoyageWptPtMenuController.java @@ -10,6 +10,7 @@ import net.osmand.GPXUtilities.WptPt; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController; @@ -38,13 +39,14 @@ public class WikivoyageWptPtMenuController extends WptPtMenuController { } private static TravelArticle getTravelArticle(@NonNull MapActivity mapActivity, @NonNull WptPt wpt) { - SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedGPXFile(wpt); + OsmandApplication app = mapActivity.getMyApplication(); + SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedGPXFile(wpt); GPXFile gpxFile = selectedGpxFile != null ? selectedGpxFile.getGpxFile() : null; Metadata metadata = gpxFile != null ? gpxFile.metadata : null; String title = metadata != null ? metadata.getArticleTitle() : null; String lang = metadata != null ? metadata.getArticleLang() : null; if (!TextUtils.isEmpty(title) && !TextUtils.isEmpty(lang)) { - return mapActivity.getMyApplication().getTravelHelper().getArticleByTitle(title, new LatLon(wpt.lat, wpt.lon), lang); + return app.getTravelHelper().getArticleByTitle(title, new LatLon(wpt.lat, wpt.lon), lang, false, null); } return null; }