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.views.layers.MapControlsLayer.MapControlsThemeInfoProvider;
|
||||||
import net.osmand.plus.widgets.popup.PopUpMenuHelper;
|
import net.osmand.plus.widgets.popup.PopUpMenuHelper;
|
||||||
import net.osmand.plus.widgets.popup.PopUpMenuItem;
|
import net.osmand.plus.widgets.popup.PopUpMenuItem;
|
||||||
import net.osmand.util.Algorithms;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
@ -212,24 +211,8 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
||||||
if (gpxFile == null || selectingTrack) {
|
if (gpxFile == null || selectingTrack) {
|
||||||
setupTracksCard();
|
setupTracksCard();
|
||||||
} else {
|
} 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);
|
sortButton.setVisibility(View.GONE);
|
||||||
GPXInfo gpxInfo = new GPXInfo(fileName, file != null ? file.lastModified() : 0, file != null ? file.length() : 0);
|
TrackEditCard importTrackCard = new TrackEditCard(mapActivity, gpxFile);
|
||||||
TrackEditCard importTrackCard = new TrackEditCard(mapActivity, gpxInfo);
|
|
||||||
importTrackCard.setListener(this);
|
importTrackCard.setListener(this);
|
||||||
cardsContainer.addView(importTrackCard.build(mapActivity));
|
cardsContainer.addView(importTrackCard.build(mapActivity));
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import android.widget.ImageButton;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
|
import net.osmand.GPXUtilities.GPXFile;
|
||||||
import net.osmand.plus.GPXDatabase.GpxDataItem;
|
import net.osmand.plus.GPXDatabase.GpxDataItem;
|
||||||
import net.osmand.plus.GpxDbHelper.GpxDataItemCallback;
|
import net.osmand.plus.GpxDbHelper.GpxDataItemCallback;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
@ -13,17 +14,18 @@ import net.osmand.plus.UiUtilities;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.helpers.GpxUiHelper;
|
import net.osmand.plus.helpers.GpxUiHelper;
|
||||||
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
|
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
|
||||||
|
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class TrackEditCard extends BaseCard {
|
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);
|
super(mapActivity);
|
||||||
this.gpxInfo = gpxInfo;
|
this.gpxFile = gpxFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,9 +52,24 @@ public class TrackEditCard extends BaseCard {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void updateContent() {
|
protected void updateContent() {
|
||||||
String fileName = Algorithms.getFileWithoutDirs(gpxInfo.getFileName());
|
String fileName = null;
|
||||||
String title = GpxUiHelper.getGpxTitle(fileName);
|
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);
|
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);
|
GpxUiHelper.updateGpxInfoView(view, title, gpxInfo, dataItem, false, app);
|
||||||
|
|
||||||
ImageButton editButton = view.findViewById(R.id.show_on_map);
|
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.osmedit.OsmEditingPlugin;
|
||||||
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
|
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
|
||||||
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
|
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.track.SaveGpxAsyncTask.SaveGpxListener;
|
||||||
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
|
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
|
||||||
import net.osmand.plus.widgets.IconPopupMenu;
|
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,
|
public class TrackMenuFragment extends ContextMenuScrollFragment implements CardListener,
|
||||||
SegmentActionsListener, RenameCallback, OnTrackFileMoveListener, OnPointsDeleteListener,
|
SegmentActionsListener, RenameCallback, OnTrackFileMoveListener, OnPointsDeleteListener,
|
||||||
OsmAndLocationListener, OsmAndCompassListener {
|
OsmAndLocationListener, OsmAndCompassListener, TrackSelectSegmentBottomSheet.OnSegmentSelectedListener {
|
||||||
|
|
||||||
public static final String OPEN_TRACK_MENU = "open_track_menu";
|
public static final String OPEN_TRACK_MENU = "open_track_menu";
|
||||||
public static final String RETURN_SCREEN_NAME = "return_screen_name";
|
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 int toolbarHeightPx;
|
||||||
private boolean mapPositionAdjusted;
|
private boolean mapPositionAdjusted;
|
||||||
|
|
||||||
|
|
||||||
public enum TrackMenuType {
|
public enum TrackMenuType {
|
||||||
OVERVIEW(R.id.action_overview, R.string.shared_string_overview),
|
OVERVIEW(R.id.action_overview, R.string.shared_string_overview),
|
||||||
TRACK(R.id.action_track, R.string.shared_string_gpx_tracks),
|
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;
|
public final int titleId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getMainLayoutId() {
|
public int getMainLayoutId() {
|
||||||
return R.layout.track_menu;
|
return R.layout.track_menu;
|
||||||
|
@ -591,8 +594,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
MapActivity mapActivity = getMapActivity();
|
MapActivity mapActivity = getMapActivity();
|
||||||
View view = overviewCard.getView();
|
View view = overviewCard.getView();
|
||||||
if (mapActivity != null && view != null) {
|
if (mapActivity != null && view != null) {
|
||||||
TextView distanceText = (TextView) view.findViewById(R.id.distance);
|
TextView distanceText = view.findViewById(R.id.distance);
|
||||||
ImageView direction = (ImageView) view.findViewById(R.id.direction);
|
ImageView direction = view.findViewById(R.id.direction);
|
||||||
app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, latLon);
|
app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, latLon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -723,23 +726,12 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
||||||
TrackAppearanceFragment.showInstance(mapActivity, selectedGpxFile, this);
|
TrackAppearanceFragment.showInstance(mapActivity, selectedGpxFile, this);
|
||||||
} else if (buttonIndex == DIRECTIONS_BUTTON_INDEX) {
|
} else if (buttonIndex == DIRECTIONS_BUTTON_INDEX) {
|
||||||
MapActivityActions mapActions = mapActivity.getMapActions();
|
MapActivityActions mapActions = mapActivity.getMapActions();
|
||||||
if (app.getRoutingHelper().isFollowingMode()) {
|
if (gpxFile.getNonEmptySegmentsCount() > 1) {
|
||||||
mapActions.stopNavigationActionConfirm(null, new Runnable() {
|
TrackSelectSegmentBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), gpxFile, this);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
MapActivity mapActivity = getMapActivity();
|
|
||||||
if (mapActivity != null) {
|
|
||||||
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(gpxFile, null,
|
|
||||||
null, null, true, true, MenuState.HEADER_ONLY);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
mapActions.stopNavigationWithoutConfirm();
|
startNavigationForGPX(gpxFile, mapActions);
|
||||||
mapActions.enterRoutePlanningModeGivenGpx(gpxFile, null, null,
|
dismiss();
|
||||||
null, true, true, MenuState.HEADER_ONLY);
|
|
||||||
}
|
}
|
||||||
dismiss();
|
|
||||||
}
|
}
|
||||||
if (buttonIndex == JOIN_GAPS_BUTTON_INDEX) {
|
if (buttonIndex == JOIN_GAPS_BUTTON_INDEX) {
|
||||||
displayHelper.setJoinSegments(!displayHelper.isJoinSegments());
|
displayHelper.setJoinSegments(!displayHelper.isJoinSegments());
|
||||||
|
@ -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) {
|
public void updateToolbar(int y, boolean animated) {
|
||||||
final MapActivity mapActivity = getMapActivity();
|
final MapActivity mapActivity = getMapActivity();
|
||||||
if (mapActivity != null) {
|
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) {
|
private void editSegment(TrkSegment segment) {
|
||||||
GPXFile gpxFile = getGpx();
|
GPXFile gpxFile = getGpx();
|
||||||
openPlanRoute(new GpxData(gpxFile));
|
openPlanRoute(new GpxData(gpxFile));
|
||||||
|
|
Loading…
Reference in a new issue