Skip to content

Commit

Permalink
Implement click-on-search-results for Travel Obf
Browse files Browse the repository at this point in the history
  • Loading branch information
RZR-UA committed Nov 19, 2024
1 parent a5a4267 commit 61b03eb
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void openTrack(MapActivity mapActivity) {
String name = amenity.getTagContent(Amenity.ROUTE_NAME);
TravelArticle article = travelHelper.getArticleByTitle(name, lang, true, null);
if (article != null) {
travelHelper.openTrackMenu(article, mapActivity, name, amenity.getLocation());
travelHelper.openTrackMenu(article, mapActivity, name, amenity.getLocation(), false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@
import androidx.fragment.app.FragmentActivity;

import net.osmand.IndexConstants;
import net.osmand.data.Amenity;
import net.osmand.data.PointDescription;
import net.osmand.plus.wikivoyage.data.TravelGpx;
import net.osmand.plus.wikivoyage.data.TravelHelper;
import net.osmand.shared.gpx.GpxFile;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
Expand Down Expand Up @@ -175,27 +178,42 @@ public boolean isShowResult() {
public void showResult(SearchResult searchResult) {
showResult = false;
if (searchResult.objectType == ObjectType.GPX_TRACK) {
GPXInfo gpxInfo = (GPXInfo) searchResult.relatedObject;
if (dialogFragment.getSearchType().isTargetPoint()) {
File file = gpxInfo.getFile();
if (file != null) {
selectTrack(file);
}
} else {
showTrackMenuFragment(gpxInfo);
}
showGpxTrackResult(searchResult);
} else if (searchResult.location != null) {
Pair<PointDescription, Object> pair = QuickSearchListItem.getPointDescriptionObject(app, searchResult);
showResultWithLocation(searchResult);
}
}

private void showResultWithLocation(SearchResult searchResult) {
Pair<PointDescription, Object> pair = QuickSearchListItem.getPointDescriptionObject(app, searchResult);

dialogFragment.hideToolbar();
dialogFragment.hide();
dialogFragment.hideToolbar();
dialogFragment.hide();

if (pair.second instanceof Amenity && ((Amenity) pair.second).isRouteTrack()) {
Amenity amenity = (Amenity) pair.second;
TravelHelper travelHelper = app.getTravelHelper();
TravelGpx travelGpx = travelHelper.searchGpx(amenity.getLocation(), amenity.getRouteId(), amenity.getRef());
travelHelper.openTrackMenu(travelGpx, getMapActivity(), amenity.getRouteId(), amenity.getLocation(), true);
} else {
showOnMap(getMapActivity(), dialogFragment,
searchResult.location.getLatitude(), searchResult.location.getLongitude(),
searchResult.preferredZoom, pair.first, pair.second);
}
}

private void showGpxTrackResult(SearchResult searchResult) {
GPXInfo gpxInfo = (GPXInfo) searchResult.relatedObject;
if (dialogFragment.getSearchType().isTargetPoint()) {
File file = gpxInfo.getFile();
if (file != null) {
selectTrack(file);
}
} else {
showTrackMenuFragment(gpxInfo);
}
}

private void selectTrack(@NonNull File file) {
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(file.getAbsolutePath());
if (selectedGpxFile != null) {
Expand Down
5 changes: 3 additions & 2 deletions OsmAnd/src/net/osmand/plus/track/helpers/GpxUiHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,8 @@ public static void saveAndOpenGpx(@NonNull MapActivity mapActivity,
@NonNull GpxFile gpxFile,
@NonNull WptPt selectedPoint,
@Nullable GpxTrackAnalysis analyses,
@Nullable RouteKey routeKey) {
@Nullable RouteKey routeKey,
boolean adjustMapPosition) {
SaveGpxHelper.saveGpx(file, gpxFile, errorMessage -> {
if (errorMessage == null) {
OsmandApplication app = mapActivity.getMyApplication();
Expand All @@ -634,7 +635,7 @@ public static void saveAndOpenGpx(@NonNull MapActivity mapActivity,
GpxTrackAnalysis trackAnalysis = analyses != null ? analyses : selectedGpxFile.getTrackAnalysis(app);
SelectedGpxPoint selectedGpxPoint = new SelectedGpxPoint(selectedGpxFile, selectedPoint);
Bundle bundle = new Bundle();
bundle.putBoolean(TrackMenuFragment.ADJUST_MAP_POSITION, false);
bundle.putBoolean(TrackMenuFragment.ADJUST_MAP_POSITION, adjustMapPosition);
TrackMenuFragment.showInstance(mapActivity, selectedGpxFile, selectedGpxPoint,
trackAnalysis, routeKey, bundle);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private void saveAndOpenGpx(@NonNull GpxFile gpxFile, @NonNull Pair<RouteKey, Qu
String name = getObjectName(pair).getName();
String fileName = Algorithms.convertToPermittedFileName(name.endsWith(GPX_FILE_EXT) ? name : name + GPX_FILE_EXT);
File file = new File(FileUtils.getTempDir(app), fileName);
GpxUiHelper.saveAndOpenGpx(activity, file, gpxFile, wptPt, null, pair.first);
GpxUiHelper.saveAndOpenGpx(activity, file, gpxFile, wptPt, null, pair.first, false);
}
}

Expand Down
4 changes: 2 additions & 2 deletions OsmAnd/src/net/osmand/plus/views/layers/POIMapLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -609,14 +609,14 @@ public boolean showMenuAction(@Nullable Object object) {
if (article == null) {
return true;
}
travelHelper.openTrackMenu(article, mapActivity, name, amenity.getLocation());
travelHelper.openTrackMenu(article, mapActivity, name, amenity.getLocation(), false);
return true;
} else if (amenity.isRouteTrack()) {
TravelGpx travelGpx = travelHelper.searchGpx(amenity.getLocation(), amenity.getRouteId(), amenity.getRef());
if (travelGpx == null) {
return true;
}
travelHelper.openTrackMenu(travelGpx, mapActivity, amenity.getRouteId(), amenity.getLocation());
travelHelper.openTrackMenu(travelGpx, mapActivity, amenity.getRouteId(), amenity.getLocation(), false);
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public boolean showMenuAction(@Nullable Object object) {

WptPt wptPt = selectedGpxPoint.getSelectedPoint();
TravelHelper travelHelper = app.getTravelHelper();
travelHelper.openTrackMenu(travelGpx, mapActivity, travelGpx.getRouteId(), new LatLon(wptPt.getLat(), wptPt.getLon()));
travelHelper.openTrackMenu(travelGpx, mapActivity, travelGpx.getRouteId(),
new LatLon(wptPt.getLat(), wptPt.getLon()), false);
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -725,8 +725,7 @@ public TravelGpx searchGpx(@NonNull LatLon location, @Nullable String fileName,

@Override
public void openTrackMenu(@NonNull TravelArticle article, @NonNull MapActivity mapActivity,
@NonNull String gpxFileName, @NonNull LatLon location) {

@NonNull String gpxFileName, @NonNull LatLon location, boolean adjustMapPosition) {
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ interface GpxReadCallback {
TravelGpx searchGpx(@NonNull LatLon location, @Nullable String fileName, @Nullable String ref);

void openTrackMenu(@NonNull TravelArticle article, @NonNull MapActivity mapActivity,
@NonNull String gpxFileName, @NonNull LatLon location);
@NonNull String gpxFileName, @NonNull LatLon location, boolean adjustMapPosition);

@NonNull
String getGPXName(@NonNull TravelArticle article);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ private TravelArticle getCachedArticle(@NonNull TravelArticleIdentifier articleI

@Override
public void openTrackMenu(@NonNull TravelArticle article, @NonNull MapActivity mapActivity,
@NonNull String gpxFileName, @NonNull LatLon latLon) {
@NonNull String gpxFileName, @NonNull LatLon latLon, boolean adjustMapPosition) {
GpxReadCallback callback = new GpxReadCallback() {
@Override
public void onGpxFileReading() {
Expand All @@ -726,7 +726,7 @@ public void onGpxFileRead(@Nullable GpxFile gpxFile) {

String name = gpxFileName.endsWith(GPX_FILE_EXT) ? gpxFileName : gpxFileName + GPX_FILE_EXT;
File file = new File(FileUtils.getTempDir(app), name);
GpxUiHelper.saveAndOpenGpx(mapActivity, file, gpxFile, wptPt, article.getAnalysis(), null);
GpxUiHelper.saveAndOpenGpx(mapActivity, file, gpxFile, wptPt, article.getAnalysis(), null, adjustMapPosition);
}
}
};
Expand Down

0 comments on commit 61b03eb

Please sign in to comment.