From cbebccb12374ee1ac61ec5a24954e901425da97f Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 28 Jan 2021 16:42:08 +0200 Subject: [PATCH] Small refactoring --- .../data/TravelLocalDataHelper.java | 6 ++--- .../plus/wikivoyage/data/TravelObfHelper.java | 25 +++++++++++++++---- .../explore/travelcards/TravelGpxCard.java | 3 +-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java index ae1c22b587..a95438a77e 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelLocalDataHelper.java @@ -143,10 +143,8 @@ public class TravelLocalDataHelper { @Nullable private TravelArticle getArticle(String title, String lang) { for (TravelArticle article : savedArticles) { - if (article.lang == null && lang == null && article.title != null && article.title.equals(title)) { - return article; - } - if (article.title != null && article.title.equals(title) && article.lang != null && article.lang.equals(lang)) { + if (article.title != null && article.title.equals(title) + && (article.lang != null && article.lang.equals(lang) || article.lang == null && lang == null)) { return article; } } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 69c1506b9b..ab9e926c10 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -48,6 +48,8 @@ import java.util.Map.Entry; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import gnu.trove.iterator.TIntObjectIterator; + import static net.osmand.GPXUtilities.Track; import static net.osmand.GPXUtilities.TrkSegment; import static net.osmand.GPXUtilities.WptPt; @@ -70,8 +72,8 @@ public class TravelObfHelper implements TravelHelper { public static final int ARTICLE_SEARCH_RADIUS = 50000; public static final int GPX_TRACKS_SEARCH_RADIUS = 10000; public static final int MAX_POPULAR_ARTICLES_COUNT = 30; - public static final int REF_KEY = 2; - public static final int NAME_KEY = 1; + public static final String REF_TAG = "ref"; + public static final String NAME_TAG = "name"; private final OsmandApplication app; private final Collator collator; @@ -163,7 +165,7 @@ public class TravelObfHelper implements TravelHelper { private TravelArticle cacheTravelArticles(File file, Amenity amenity, String lang, boolean readPoints, @Nullable GpxReadCallback callback) { TravelArticle article = null; Map articles; - if (amenity.getSubType().equals(ROUTE_TRACK)) { + if (Algorithms.objectEquals(amenity.getSubType(), ROUTE_TRACK)) { articles = readRoutePoint(file, amenity); } else { articles = readArticles(file, amenity); @@ -268,8 +270,8 @@ public class TravelObfHelper implements TravelHelper { @Override public boolean publish(BinaryMapDataObject object) { if (object.getPointsLength() > 1) { - if (object.getObjectNames().get(REF_KEY).equals(ref) - && createTitle(object.getObjectNames().get(NAME_KEY)).equals(article.title)) { + if (getTagValue(object, REF_TAG).equals(ref) + && createTitle(getTagValue(object, NAME_TAG)).equals(article.title)) { segmentList.add(object); } } @@ -310,6 +312,19 @@ public class TravelObfHelper implements TravelHelper { return gpxFile; } + private String getTagValue(BinaryMapDataObject object, String tag) { + BinaryMapIndexReader.MapIndex mi = object.getMapIndex(); + TIntObjectIterator it = object.getObjectNames().iterator(); + while (it.hasNext()) { + it.advance(); + BinaryMapIndexReader.TagValuePair tp = mi.decodeType(it.key()); + if (tp.tag.equals(tag)) { + return it.value(); + } + } + return ""; + } + private String createTitle(String name) { return capitalizeFirstLetter(getGpxTitle(name)); } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java index 515a5f5b06..1bc2409621 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/travelcards/TravelGpxCard.java @@ -13,7 +13,6 @@ import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.track.TrackMenuFragment; -import net.osmand.plus.wikipedia.WikiArticleHelper; import net.osmand.plus.wikivoyage.data.TravelGpx; import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; @@ -43,7 +42,7 @@ public class TravelGpxCard extends BaseTravelCard { holder.title.setText(article.getTitle()); Drawable icon = getActiveIcon(R.drawable.ic_action_user_account_16); holder.user.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null); - holder.user.setText(WikiArticleHelper.getPartialContent(article.user)); + holder.user.setText(article.user); AndroidUtils.setBackground(app, holder.user, nightMode, R.drawable.btn_border_bg_light, R.drawable.btn_border_bg_dark); holder.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app)); holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app));