Small refactoring
This commit is contained in:
parent
bc5ad1a032
commit
cbebccb123
3 changed files with 23 additions and 11 deletions
|
@ -143,10 +143,8 @@ public class TravelLocalDataHelper {
|
||||||
@Nullable
|
@Nullable
|
||||||
private TravelArticle getArticle(String title, String lang) {
|
private TravelArticle getArticle(String title, String lang) {
|
||||||
for (TravelArticle article : savedArticles) {
|
for (TravelArticle article : savedArticles) {
|
||||||
if (article.lang == null && lang == null && article.title != null && article.title.equals(title)) {
|
if (article.title != null && article.title.equals(title)
|
||||||
return article;
|
&& (article.lang != null && article.lang.equals(lang) || article.lang == null && lang == null)) {
|
||||||
}
|
|
||||||
if (article.title != null && article.title.equals(title) && article.lang != null && article.lang.equals(lang)) {
|
|
||||||
return article;
|
return article;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,8 @@ import java.util.Map.Entry;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
import gnu.trove.iterator.TIntObjectIterator;
|
||||||
|
|
||||||
import static net.osmand.GPXUtilities.Track;
|
import static net.osmand.GPXUtilities.Track;
|
||||||
import static net.osmand.GPXUtilities.TrkSegment;
|
import static net.osmand.GPXUtilities.TrkSegment;
|
||||||
import static net.osmand.GPXUtilities.WptPt;
|
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 ARTICLE_SEARCH_RADIUS = 50000;
|
||||||
public static final int GPX_TRACKS_SEARCH_RADIUS = 10000;
|
public static final int GPX_TRACKS_SEARCH_RADIUS = 10000;
|
||||||
public static final int MAX_POPULAR_ARTICLES_COUNT = 30;
|
public static final int MAX_POPULAR_ARTICLES_COUNT = 30;
|
||||||
public static final int REF_KEY = 2;
|
public static final String REF_TAG = "ref";
|
||||||
public static final int NAME_KEY = 1;
|
public static final String NAME_TAG = "name";
|
||||||
|
|
||||||
private final OsmandApplication app;
|
private final OsmandApplication app;
|
||||||
private final Collator collator;
|
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) {
|
private TravelArticle cacheTravelArticles(File file, Amenity amenity, String lang, boolean readPoints, @Nullable GpxReadCallback callback) {
|
||||||
TravelArticle article = null;
|
TravelArticle article = null;
|
||||||
Map<String, TravelArticle> articles;
|
Map<String, TravelArticle> articles;
|
||||||
if (amenity.getSubType().equals(ROUTE_TRACK)) {
|
if (Algorithms.objectEquals(amenity.getSubType(), ROUTE_TRACK)) {
|
||||||
articles = readRoutePoint(file, amenity);
|
articles = readRoutePoint(file, amenity);
|
||||||
} else {
|
} else {
|
||||||
articles = readArticles(file, amenity);
|
articles = readArticles(file, amenity);
|
||||||
|
@ -268,8 +270,8 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
@Override
|
@Override
|
||||||
public boolean publish(BinaryMapDataObject object) {
|
public boolean publish(BinaryMapDataObject object) {
|
||||||
if (object.getPointsLength() > 1) {
|
if (object.getPointsLength() > 1) {
|
||||||
if (object.getObjectNames().get(REF_KEY).equals(ref)
|
if (getTagValue(object, REF_TAG).equals(ref)
|
||||||
&& createTitle(object.getObjectNames().get(NAME_KEY)).equals(article.title)) {
|
&& createTitle(getTagValue(object, NAME_TAG)).equals(article.title)) {
|
||||||
segmentList.add(object);
|
segmentList.add(object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -310,6 +312,19 @@ public class TravelObfHelper implements TravelHelper {
|
||||||
return gpxFile;
|
return gpxFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getTagValue(BinaryMapDataObject object, String tag) {
|
||||||
|
BinaryMapIndexReader.MapIndex mi = object.getMapIndex();
|
||||||
|
TIntObjectIterator<String> 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) {
|
private String createTitle(String name) {
|
||||||
return capitalizeFirstLetter(getGpxTitle(name));
|
return capitalizeFirstLetter(getGpxTitle(name));
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,6 @@ import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.track.TrackMenuFragment;
|
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.TravelGpx;
|
||||||
import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper;
|
import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper;
|
||||||
|
|
||||||
|
@ -43,7 +42,7 @@ public class TravelGpxCard extends BaseTravelCard {
|
||||||
holder.title.setText(article.getTitle());
|
holder.title.setText(article.getTitle());
|
||||||
Drawable icon = getActiveIcon(R.drawable.ic_action_user_account_16);
|
Drawable icon = getActiveIcon(R.drawable.ic_action_user_account_16);
|
||||||
holder.user.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null);
|
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);
|
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.distance.setText(OsmAndFormatter.getFormattedDistance(article.totalDistance, app));
|
||||||
holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app));
|
holder.diffElevationUp.setText(OsmAndFormatter.getFormattedAlt(article.diffElevationUp, app));
|
||||||
|
|
Loading…
Reference in a new issue