Skip to content

Commit

Permalink
Refactor buildGpxFile to support TravelGpx (draft)
Browse files Browse the repository at this point in the history
  • Loading branch information
RZR-UA committed Nov 19, 2024
1 parent 7c66702 commit d346b8b
Showing 1 changed file with 37 additions and 25 deletions.
62 changes: 37 additions & 25 deletions OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import net.osmand.OsmAndCollator;
import net.osmand.PlatformUtil;
import net.osmand.ResultMatcher;
import net.osmand.plus.Version;
import net.osmand.plus.shared.SharedUtil;
import net.osmand.binary.BinaryMapDataObject;
import net.osmand.binary.BinaryMapIndexReader;
Expand Down Expand Up @@ -1087,15 +1088,10 @@ public void saveOrRemoveArticle(@NonNull TravelArticle article, boolean save) {
}
}

@Nullable
private synchronized GpxFile buildGpxFile(@NonNull List<BinaryMapIndexReader> readers, TravelArticle article) {
List<BinaryMapDataObject> segmentList = new ArrayList<>();
Map<String, String> gpxFileExtensions = new HashMap<>();
List<Amenity> pointList = new ArrayList<>();
List<String> pgNames = new ArrayList<>();
List<String> pgIcons = new ArrayList<>();
List<String> pgColors = new ArrayList<>();
List<String> pgBackgrounds = new ArrayList<>();
private void fetchSegmentsAndPoints(List<BinaryMapIndexReader> readers, TravelArticle article,
List<BinaryMapDataObject> segmentList, List<Amenity> pointList,
Map<String, String> gpxFileExtensions, List<String> pgNames,
List<String> pgIcons, List<String> pgColors, List<String> pgBackgrounds) {
for (BinaryMapIndexReader reader : readers) {
try {
if (article.file != null && !article.file.equals(reader.getFile())) {
Expand All @@ -1116,7 +1112,6 @@ public boolean publish(BinaryMapDataObject object) {
}
return false;
}

@Override
public boolean isCancelled() {
return false;
Expand All @@ -1127,7 +1122,6 @@ public boolean isCancelled() {
}
reader.searchMapIndex(sr);
}

BinaryMapIndexReader.SearchRequest<Amenity> pointRequest = BinaryMapIndexReader.buildSearchPoiRequest(
0, 0, Algorithms.emptyIfNull(article.title), 0, Integer.MAX_VALUE, 0, Integer.MAX_VALUE,
getSearchFilter(article.getMainFilterString(), article.getPointFilterString()),
Expand All @@ -1154,6 +1148,8 @@ public boolean publish(Amenity amenity) {
} else if (OBF_POINTS_GROUPS_BACKGROUNDS.equals(key)) {
pgBackgrounds.addAll(values);
}
} else {
// TODO detect relation_gpx==yes and store tags with osm_ prefix
}
}
} else if (ROUTE_TRACK_POINT.equals(amenity.getSubType())) {
Expand All @@ -1167,7 +1163,6 @@ public boolean publish(Amenity amenity) {
}
return false;
}

@Override
public boolean isCancelled() {
return false;
Expand All @@ -1188,9 +1183,36 @@ public boolean isCancelled() {
LOG.error(e.getMessage());
}
}
GpxFile gpxFile = null;
String description = article.getDescription();
String title = FileUtils.isValidFileName(description) ? description : article.getTitle();
}

@Nullable
private synchronized GpxFile buildGpxFile(@NonNull List<BinaryMapIndexReader> readers, TravelArticle article) {
List<BinaryMapDataObject> segmentList = new ArrayList<>();
Map<String, String> gpxFileExtensions = new HashMap<>();
List<Amenity> pointList = new ArrayList<>();
List<String> pgNames = new ArrayList<>();
List<String> pgIcons = new ArrayList<>();
List<String> pgColors = new ArrayList<>();
List<String> pgBackgrounds = new ArrayList<>();

fetchSegmentsAndPoints(readers, article, segmentList, pointList, gpxFileExtensions,
pgNames, pgIcons, pgColors, pgBackgrounds);

GpxFile gpxFile;

if (article instanceof TravelGpx) {
gpxFile = new GpxFile(Version.getFullVersion(app));
// TODO set activity, name, description, etc (gpxFileExtensions)
} else {
String description = article.getDescription();
String title = FileUtils.isValidFileName(description) ? description : article.getTitle();
gpxFile = new GpxFile(title, article.getLang(), article.getContent());
}

if (!Algorithms.isEmpty(article.getImageTitle())) {
gpxFile.getMetadata().setLink(TravelArticle.getImageUrl(article.getImageTitle(), false));
}

if (!segmentList.isEmpty()) {
boolean hasAltitude = false;
Track track = new Track();
Expand All @@ -1216,10 +1238,6 @@ public boolean isCancelled() {
}
track.getSegments().add(trkSegment);
}
gpxFile = new GpxFile(title, article.getLang(), article.getContent());
if (!Algorithms.isEmpty(article.getImageTitle())) {
gpxFile.getMetadata().setLink(TravelArticle.getImageUrl(article.getImageTitle(), false));
}
gpxFile.setTracks(new ArrayList<>());
gpxFile.getTracks().add(track);
gpxFile.setRef(article.ref);
Expand All @@ -1228,12 +1246,6 @@ public boolean isCancelled() {
}
reconstructPointsGroups(gpxFile, pgNames, pgIcons, pgColors, pgBackgrounds); // create groups before points
if (!pointList.isEmpty()) {
if (gpxFile == null) {
gpxFile = new GpxFile(title, article.getLang(), article.getContent());
if (!Algorithms.isEmpty(article.getImageTitle())) {
gpxFile.getMetadata().setLink(TravelArticle.getImageUrl(article.getImageTitle(), false));
}
}
for (Amenity wayPoint : pointList) {
gpxFile.addPoint(article.createWptPt(wayPoint, article.getLang()));
}
Expand Down

0 comments on commit d346b8b

Please sign in to comment.