Minor fixes

This commit is contained in:
Vitaliy 2020-08-20 13:15:06 +03:00
parent fde90d40d4
commit f3f7916fbc
8 changed files with 27 additions and 31 deletions

View file

@ -1290,7 +1290,7 @@ public class GPXUtilities {
return pt; return pt;
} }
public TrkSegment getTrkSegment() { public TrkSegment getNonEmptyTrkSegment() {
for (GPXUtilities.Track t : tracks) { for (GPXUtilities.Track t : tracks) {
for (TrkSegment s : t.segments) { for (TrkSegment s : t.segments) {
if (s.points.size() > 0) { if (s.points.size() > 0) {

View file

@ -47,7 +47,7 @@ final class MapLayerMenuListener extends OnRowItemClick {
GpxSelectionHelper selectedGpxHelper = mapActivity.getMyApplication().getSelectedGpxHelper(); GpxSelectionHelper selectedGpxHelper = mapActivity.getMyApplication().getSelectedGpxHelper();
List<SelectedGpxFile> selectedGpxFiles = selectedGpxHelper.getSelectedGPXFiles(); List<SelectedGpxFile> selectedGpxFiles = selectedGpxHelper.getSelectedGPXFiles();
List<String> files = GpxUiHelper.getSelectedTrackNames(mapActivity.getMyApplication()); List<String> files = GpxUiHelper.getSelectedTrackPaths(mapActivity.getMyApplication());
if (selectedGpxFiles.isEmpty()) { if (selectedGpxFiles.isEmpty()) {
Map<GPXFile, Long> fls = selectedGpxHelper.getSelectedGpxFilesBackUp(); Map<GPXFile, Long> fls = selectedGpxHelper.getSelectedGpxFilesBackUp();
for (Map.Entry<GPXFile, Long> f : fls.entrySet()) { for (Map.Entry<GPXFile, Long> f : fls.entrySet()) {

View file

@ -810,7 +810,7 @@ public class GpxUiHelper {
} }
} }
public static List<String> getSelectedTrackNames(OsmandApplication app) { public static List<String> getSelectedTrackPaths(OsmandApplication app) {
List<String> trackNames = new ArrayList<>(); List<String> trackNames = new ArrayList<>();
for (SelectedGpxFile file : app.getSelectedGpxHelper().getSelectedGPXFiles()) { for (SelectedGpxFile file : app.getSelectedGpxHelper().getSelectedGPXFiles()) {
trackNames.add(file.getGpxFile().path); trackNames.add(file.getGpxFile().path);

View file

@ -117,7 +117,7 @@ public class ImportHelper {
public interface OnGpxImportCompleteListener { public interface OnGpxImportCompleteListener {
void onImportComplete(boolean success); void onImportComplete(boolean success);
void onSavingComplete(boolean success, GPXFile result); void onSaveComplete(boolean success, GPXFile result);
} }
public ImportHelper(final AppCompatActivity activity, final OsmandApplication app, final OsmandMapTileView mapView) { public ImportHelper(final AppCompatActivity activity, final OsmandApplication app, final OsmandMapTileView mapView) {
@ -1094,7 +1094,7 @@ public class ImportHelper {
boolean success = Algorithms.isEmpty(warning); boolean success = Algorithms.isEmpty(warning);
if (gpxImportCompleteListener != null) { if (gpxImportCompleteListener != null) {
gpxImportCompleteListener.onSavingComplete(success, result); gpxImportCompleteListener.onSaveComplete(success, result);
} }
if (success) { if (success) {
if (showInDetailsActivity) { if (showInDetailsActivity) {

View file

@ -131,7 +131,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
private boolean progressBarVisible; private boolean progressBarVisible;
private boolean pointsListOpened; private boolean pointsListOpened;
private boolean planRouteMode = false; private boolean planRouteMode = false;
private boolean attachToRoads;
private Boolean saved; private Boolean saved;
private boolean portrait; private boolean portrait;
private boolean nightMode; private boolean nightMode;
@ -159,10 +158,6 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
this.planRouteMode = planRouteMode; this.planRouteMode = planRouteMode;
} }
public void setAttachToRoads(boolean attachToRoads) {
this.attachToRoads = attachToRoads;
}
@Nullable @Nullable
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@ -469,7 +464,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
if (editingCtx.isNewData() && planRouteMode) { if (editingCtx.isNewData() && planRouteMode) {
StartPlanRouteBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), StartPlanRouteBottomSheet.showInstance(mapActivity.getSupportFragmentManager(),
createStartPlanRouteListener()); createStartPlanRouteListener());
} else if (attachToRoads && !(editingCtx.isNewData() || editingCtx.hasRoutePoints() || editingCtx.isInSnapToRoadMode())) { } else if (!(editingCtx.isNewData() || editingCtx.hasRoutePoints() || editingCtx.isInSnapToRoadMode())) {
SnapTrackWarningBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), this); SnapTrackWarningBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), this);
} }
} }
@ -892,7 +887,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
public void addNewGpxData(GPXFile gpxFile) { public void addNewGpxData(GPXFile gpxFile) {
QuadRect rect = gpxFile.getRect(); QuadRect rect = gpxFile.getRect();
TrkSegment segment = gpxFile.getTrkSegment(); TrkSegment segment = gpxFile.getNonEmptyTrkSegment();
ActionType actionType = segment == null ? ActionType.ADD_ROUTE_POINTS : ActionType.EDIT_SEGMENT; ActionType actionType = segment == null ? ActionType.ADD_ROUTE_POINTS : ActionType.EDIT_SEGMENT;
NewGpxData newGpxData = new NewGpxData(gpxFile, rect, actionType, segment); NewGpxData newGpxData = new NewGpxData(gpxFile, rect, actionType, segment);
@ -1803,12 +1798,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
return showFragment(fragment, fragmentManager); return showFragment(fragment, fragmentManager);
} }
public static boolean showInstance(FragmentManager fragmentManager, MeasurementEditingContext editingCtx, public static boolean showInstance(FragmentManager fragmentManager, MeasurementEditingContext editingCtx, boolean planRoute) {
boolean planRoute, boolean attachToRoads) {
MeasurementToolFragment fragment = new MeasurementToolFragment(); MeasurementToolFragment fragment = new MeasurementToolFragment();
fragment.setEditingCtx(editingCtx); fragment.setEditingCtx(editingCtx);
fragment.setPlanRouteMode(planRoute); fragment.setPlanRouteMode(planRoute);
fragment.setAttachToRoads(attachToRoads);
return showFragment(fragment, fragmentManager); return showFragment(fragment, fragmentManager);
} }

View file

@ -172,7 +172,7 @@ public class StartPlanRouteBottomSheet extends MenuBottomSheetDialogFragment {
} }
@Override @Override
public void onSavingComplete(boolean success, GPXUtilities.GPXFile result) { public void onSaveComplete(boolean success, GPXUtilities.GPXFile result) {
} }
}); });

View file

@ -136,7 +136,7 @@ public class FavoritesActivity extends TabActivity {
} }
@Override @Override
public void onSavingComplete(boolean success, GPXUtilities.GPXFile result) { public void onSaveComplete(boolean success, GPXUtilities.GPXFile result) {
} }
}); });

View file

@ -21,8 +21,8 @@ import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject; import net.osmand.CallbackWithObject;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
@ -201,13 +201,13 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
boolean osmandRouter = mode.getRouteService() == RouteProvider.RouteService.OSMAND; boolean osmandRouter = mode.getRouteService() == RouteProvider.RouteService.OSMAND;
if (rparams != null && osmandRouter) { if (rparams != null && osmandRouter) {
// if (!routingHelper.isCurrentGPXRouteV2()) { // if (!routingHelper.isCurrentGPXRouteV2()) {
int textId = R.string.gpx_option_reverse_route; int textId = R.string.gpx_option_reverse_route;
String title = app.getString(textId); String title = app.getString(textId);
LocalRoutingParameter parameter = new OtherLocalRoutingParameter(textId, title, rparams.isReverse()); LocalRoutingParameter parameter = new OtherLocalRoutingParameter(textId, title, rparams.isReverse());
ReverseTrackCard reverseTrackCard = new ReverseTrackCard(mapActivity, parameter); ReverseTrackCard reverseTrackCard = new ReverseTrackCard(mapActivity, parameter);
reverseTrackCard.setListener(this); reverseTrackCard.setListener(this);
cardsContainer.addView(reverseTrackCard.build(mapActivity)); cardsContainer.addView(reverseTrackCard.build(mapActivity));
// } // }
if (!gpxFile.hasRtePt()) { if (!gpxFile.hasRtePt()) {
AttachTrackToRoadsCard attachTrackCard = new AttachTrackToRoadsCard(mapActivity); AttachTrackToRoadsCard attachTrackCard = new AttachTrackToRoadsCard(mapActivity);
@ -226,7 +226,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null) { if (mapActivity != null) {
File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR); File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
List<String> selectedTrackNames = GpxUiHelper.getSelectedTrackNames(app); List<String> selectedTrackNames = GpxUiHelper.getSelectedTrackPaths(app);
List<GPXInfo> list = GpxUiHelper.getSortedGPXFilesInfo(dir, selectedTrackNames, false); List<GPXInfo> list = GpxUiHelper.getSortedGPXFilesInfo(dir, selectedTrackNames, false);
if (list.size() > 0) { if (list.size() > 0) {
String defaultCategory = app.getString(R.string.shared_string_all); String defaultCategory = app.getString(R.string.shared_string_all);
@ -346,12 +346,12 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
if (card instanceof ImportTrackCard) { if (card instanceof ImportTrackCard) {
importTrack(); importTrack();
} else if (card instanceof TrackEditCard) { } else if (card instanceof TrackEditCard) {
openPlanRoute(false); openPlanRoute(true);
close(); close();
} else if (card instanceof SelectTrackCard) { } else if (card instanceof SelectTrackCard) {
updateSelectionMode(true); updateSelectionMode(true);
} else if (card instanceof AttachTrackToRoadsCard) { } else if (card instanceof AttachTrackToRoadsCard) {
openPlanRoute(true); openPlanRoute(false);
close(); close();
} else if (card instanceof ReverseTrackCard } else if (card instanceof ReverseTrackCard
|| card instanceof NavigateTrackOptionsCard) { || card instanceof NavigateTrackOptionsCard) {
@ -439,7 +439,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
} }
@Override @Override
public void onSavingComplete(boolean success, GPXFile result) { public void onSaveComplete(boolean success, GPXFile result) {
if (success) { if (success) {
selectTrackToFollow(result); selectTrackToFollow(result);
updateSelectionMode(false); updateSelectionMode(false);
@ -456,17 +456,20 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
} }
} }
public void openPlanRoute(boolean attachToRoads) { public void openPlanRoute(boolean useAppMode) {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
if (mapActivity != null && gpxFile != null) { if (mapActivity != null && gpxFile != null) {
QuadRect rect = gpxFile.getRect(); QuadRect rect = gpxFile.getRect();
GPXUtilities.TrkSegment segment = gpxFile.getTrkSegment(); TrkSegment segment = gpxFile.getNonEmptyTrkSegment();
ActionType actionType = segment == null ? ActionType.ADD_ROUTE_POINTS : ActionType.EDIT_SEGMENT; ActionType actionType = segment == null ? ActionType.ADD_ROUTE_POINTS : ActionType.EDIT_SEGMENT;
NewGpxData newGpxData = new NewGpxData(gpxFile, rect, actionType, segment); NewGpxData newGpxData = new NewGpxData(gpxFile, rect, actionType, segment);
MeasurementEditingContext editingContext = new MeasurementEditingContext(); MeasurementEditingContext editingContext = new MeasurementEditingContext();
editingContext.setNewGpxData(newGpxData); editingContext.setNewGpxData(newGpxData);
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), editingContext, true, attachToRoads); if (useAppMode) {
editingContext.setAppMode(app.getRoutingHelper().getAppMode());
}
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), editingContext, true);
} }
} }