Track context menu, after taping "Directions" action show "Select segment" bottom sheet
This commit is contained in:
parent
b04115aad2
commit
595e2070c1
3 changed files with 67 additions and 41 deletions
|
@ -67,7 +67,6 @@ import net.osmand.plus.track.TrackSelectSegmentBottomSheet.OnSegmentSelectedList
|
|||
import net.osmand.plus.views.layers.MapControlsLayer.MapControlsThemeInfoProvider;
|
||||
import net.osmand.plus.widgets.popup.PopUpMenuHelper;
|
||||
import net.osmand.plus.widgets.popup.PopUpMenuItem;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
|
@ -212,24 +211,8 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
|||
if (gpxFile == null || selectingTrack) {
|
||||
setupTracksCard();
|
||||
} else {
|
||||
String fileName = null;
|
||||
File file = null;
|
||||
if (!Algorithms.isEmpty(gpxFile.path)) {
|
||||
file = new File(gpxFile.path);
|
||||
fileName = Algorithms.getFileNameWithoutExtension(file.getName());
|
||||
} else if (!Algorithms.isEmpty(gpxFile.tracks)) {
|
||||
fileName = gpxFile.tracks.get(0).name;
|
||||
}
|
||||
if (Algorithms.isEmpty(fileName)) {
|
||||
fileName = app.getString(R.string.shared_string_gpx_track);
|
||||
}
|
||||
GPXRouteParamsBuilder routeParams = app.getRoutingHelper().getCurrentGPXRoute();
|
||||
if (gpxFile.getNonEmptySegmentsCount() > 1 && routeParams != null && routeParams.getSelectedSegment() != -1) {
|
||||
fileName = fileName + " segment " + (routeParams.getSelectedSegment() + 1);
|
||||
}
|
||||
sortButton.setVisibility(View.GONE);
|
||||
GPXInfo gpxInfo = new GPXInfo(fileName, file != null ? file.lastModified() : 0, file != null ? file.length() : 0);
|
||||
TrackEditCard importTrackCard = new TrackEditCard(mapActivity, gpxInfo);
|
||||
TrackEditCard importTrackCard = new TrackEditCard(mapActivity, gpxFile);
|
||||
importTrackCard.setListener(this);
|
||||
cardsContainer.addView(importTrackCard.build(mapActivity));
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import android.widget.ImageButton;
|
|||
import android.widget.LinearLayout;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXDatabase.GpxDataItem;
|
||||
import net.osmand.plus.GpxDbHelper.GpxDataItemCallback;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -13,17 +14,18 @@ import net.osmand.plus.UiUtilities;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.GpxUiHelper;
|
||||
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
|
||||
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class TrackEditCard extends BaseCard {
|
||||
|
||||
private GPXInfo gpxInfo;
|
||||
private GPXFile gpxFile;
|
||||
|
||||
public TrackEditCard(MapActivity mapActivity, GPXInfo gpxInfo) {
|
||||
public TrackEditCard(MapActivity mapActivity, GPXFile gpxFile) {
|
||||
super(mapActivity);
|
||||
this.gpxInfo = gpxInfo;
|
||||
this.gpxFile = gpxFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -50,9 +52,24 @@ public class TrackEditCard extends BaseCard {
|
|||
|
||||
@Override
|
||||
protected void updateContent() {
|
||||
String fileName = Algorithms.getFileWithoutDirs(gpxInfo.getFileName());
|
||||
String title = GpxUiHelper.getGpxTitle(fileName);
|
||||
String fileName = null;
|
||||
File file = null;
|
||||
if (!Algorithms.isEmpty(gpxFile.path)) {
|
||||
file = new File(gpxFile.path);
|
||||
fileName = gpxFile.path;
|
||||
} else if (!Algorithms.isEmpty(gpxFile.tracks)) {
|
||||
fileName = gpxFile.tracks.get(0).name;
|
||||
}
|
||||
if (Algorithms.isEmpty(fileName)) {
|
||||
fileName = app.getString(R.string.shared_string_gpx_track);
|
||||
}
|
||||
GPXInfo gpxInfo = new GPXInfo(gpxFile.path, file != null ? file.lastModified() : 0, file != null ? file.length() : 0);
|
||||
GpxDataItem dataItem = getDataItem(gpxInfo);
|
||||
String title = GpxUiHelper.getGpxTitle(Algorithms.getFileWithoutDirs(fileName));
|
||||
GPXRouteParamsBuilder routeParams = app.getRoutingHelper().getCurrentGPXRoute();
|
||||
if (gpxFile.getNonEmptySegmentsCount() > 1 && routeParams != null && routeParams.getSelectedSegment() != -1) {
|
||||
title = title + " segment " + (routeParams.getSelectedSegment() + 1);
|
||||
}
|
||||
GpxUiHelper.updateGpxInfoView(view, title, gpxInfo, dataItem, false, app);
|
||||
|
||||
ImageButton editButton = view.findViewById(R.id.show_on_map);
|
||||
|
|
|
@ -81,6 +81,7 @@ import net.osmand.plus.myplaces.TrackActivityFragmentAdapter;
|
|||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
|
||||
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
|
||||
import net.osmand.plus.routing.RouteProvider;
|
||||
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
|
||||
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
|
||||
import net.osmand.plus.widgets.IconPopupMenu;
|
||||
|
@ -114,7 +115,7 @@ import static net.osmand.plus.track.TrackPointsCard.OPEN_WAYPOINT_INDEX;
|
|||
|
||||
public class TrackMenuFragment extends ContextMenuScrollFragment implements CardListener,
|
||||
SegmentActionsListener, RenameCallback, OnTrackFileMoveListener, OnPointsDeleteListener,
|
||||
OsmAndLocationListener, OsmAndCompassListener {
|
||||
OsmAndLocationListener, OsmAndCompassListener, TrackSelectSegmentBottomSheet.OnSegmentSelectedListener {
|
||||
|
||||
public static final String OPEN_TRACK_MENU = "open_track_menu";
|
||||
public static final String RETURN_SCREEN_NAME = "return_screen_name";
|
||||
|
@ -160,6 +161,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
private int toolbarHeightPx;
|
||||
private boolean mapPositionAdjusted;
|
||||
|
||||
|
||||
public enum TrackMenuType {
|
||||
OVERVIEW(R.id.action_overview, R.string.shared_string_overview),
|
||||
TRACK(R.id.action_track, R.string.shared_string_gpx_tracks),
|
||||
|
@ -175,6 +177,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
public final int titleId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getMainLayoutId() {
|
||||
return R.layout.track_menu;
|
||||
|
@ -591,8 +594,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
MapActivity mapActivity = getMapActivity();
|
||||
View view = overviewCard.getView();
|
||||
if (mapActivity != null && view != null) {
|
||||
TextView distanceText = (TextView) view.findViewById(R.id.distance);
|
||||
ImageView direction = (ImageView) view.findViewById(R.id.direction);
|
||||
TextView distanceText = view.findViewById(R.id.distance);
|
||||
ImageView direction = view.findViewById(R.id.direction);
|
||||
app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, latLon);
|
||||
}
|
||||
}
|
||||
|
@ -723,24 +726,13 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
TrackAppearanceFragment.showInstance(mapActivity, selectedGpxFile, this);
|
||||
} else if (buttonIndex == DIRECTIONS_BUTTON_INDEX) {
|
||||
MapActivityActions mapActions = mapActivity.getMapActions();
|
||||
if (app.getRoutingHelper().isFollowingMode()) {
|
||||
mapActions.stopNavigationActionConfirm(null, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(gpxFile, null,
|
||||
null, null, true, true, MenuState.HEADER_ONLY);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (gpxFile.getNonEmptySegmentsCount() > 1) {
|
||||
TrackSelectSegmentBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), gpxFile, this);
|
||||
} else {
|
||||
mapActions.stopNavigationWithoutConfirm();
|
||||
mapActions.enterRoutePlanningModeGivenGpx(gpxFile, null, null,
|
||||
null, true, true, MenuState.HEADER_ONLY);
|
||||
}
|
||||
startNavigationForGPX(gpxFile, mapActions);
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
if (buttonIndex == JOIN_GAPS_BUTTON_INDEX) {
|
||||
displayHelper.setJoinSegments(!displayHelper.isJoinSegments());
|
||||
mapActivity.refreshMap();
|
||||
|
@ -830,6 +822,25 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
}
|
||||
}
|
||||
|
||||
private void startNavigationForGPX(final GPXFile gpxFile, MapActivityActions mapActions) {
|
||||
if (app.getRoutingHelper().isFollowingMode()) {
|
||||
mapActions.stopNavigationActionConfirm(null, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(gpxFile, null,
|
||||
null, null, true, true, MenuState.HEADER_ONLY);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mapActions.stopNavigationWithoutConfirm();
|
||||
mapActions.enterRoutePlanningModeGivenGpx(gpxFile, null, null,
|
||||
null, true, true, MenuState.HEADER_ONLY);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateToolbar(int y, boolean animated) {
|
||||
final MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
|
@ -1066,6 +1077,21 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSegmentSelect(GPXFile gpxFile, int selectedSegment) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
startNavigationForGPX(gpxFile, mapActivity.getMapActions());
|
||||
app.getSettings().GPX_ROUTE_SEGMENT.set(selectedSegment);
|
||||
RouteProvider.GPXRouteParamsBuilder paramsBuilder = app.getRoutingHelper().getCurrentGPXRoute();
|
||||
if (paramsBuilder != null) {
|
||||
paramsBuilder.setSelectedSegment(selectedSegment);
|
||||
app.getRoutingHelper().onSettingsChanged(true);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
private void editSegment(TrkSegment segment) {
|
||||
GPXFile gpxFile = getGpx();
|
||||
openPlanRoute(new GpxData(gpxFile));
|
||||
|
|
Loading…
Reference in a new issue