Merge branch 'r3.8'
This commit is contained in:
commit
87609c43c1
10 changed files with 86 additions and 42 deletions
|
@ -124,9 +124,11 @@ public class Algorithms {
|
|||
}
|
||||
|
||||
public static String getFileNameWithoutExtension(String name) {
|
||||
int i = name.lastIndexOf('.');
|
||||
if (i >= 0) {
|
||||
name = name.substring(0, i);
|
||||
if (name != null) {
|
||||
int index = name.lastIndexOf('.');
|
||||
if (index != -1) {
|
||||
return name.substring(0, index);
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
|
|
@ -216,10 +216,12 @@
|
|||
|
||||
<include
|
||||
android:id="@+id/add_point_button"
|
||||
layout="@layout/bottom_sheet_dialog_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="@dimen/measurement_tool_button_width"
|
||||
android:layout_gravity="end"
|
||||
layout="@layout/bottom_sheet_dialog_button" />
|
||||
android:minWidth="@dimen/measurement_tool_button_width" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
|
|
@ -153,16 +153,6 @@ public class AndroidUtils {
|
|||
R.color.icon_color_default_light, R.color.wikivoyage_active_dark);
|
||||
}
|
||||
|
||||
public static String trimExtension(String src) {
|
||||
if (src != null) {
|
||||
int index = src.lastIndexOf('.');
|
||||
if (index != -1) {
|
||||
return src.substring(0, index);
|
||||
}
|
||||
}
|
||||
return src;
|
||||
}
|
||||
|
||||
public static String addColon(OsmandApplication app, @StringRes int stringRes) {
|
||||
return app.getString(R.string.ltr_or_rtl_combine_via_colon, app.getString(stringRes), "").trim();
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.FileUtils;
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
|
@ -526,7 +525,7 @@ public class MapMarkersHelper {
|
|||
|
||||
private MapMarkersGroup createGPXMarkerGroup(File fl) {
|
||||
return new MapMarkersGroup(getMarkerGroupId(fl),
|
||||
AndroidUtils.trimExtension(fl.getName()),
|
||||
Algorithms.getFileNameWithoutExtension(fl.getName()),
|
||||
MapMarkersGroup.GPX_TYPE);
|
||||
}
|
||||
|
||||
|
|
|
@ -298,13 +298,15 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment
|
|||
return (menuState & (MenuState.HEADER_ONLY | MenuState.HALF_SCREEN)) != 0;
|
||||
}
|
||||
|
||||
public static void showInstance(@NonNull FragmentManager fm, @Nullable Fragment targetFragment, @NonNull LocationsHolder locationsHolder) {
|
||||
public static void showInstance(@NonNull FragmentManager fm, @Nullable Fragment targetFragment,
|
||||
@NonNull LocationsHolder locationsHolder, @Nullable ApplicationMode appMode) {
|
||||
try {
|
||||
if (!fm.isStateSaved()) {
|
||||
GpxApproximationFragment fragment = new GpxApproximationFragment();
|
||||
fragment.setRetainInstance(true);
|
||||
fragment.setTargetFragment(targetFragment, REQUEST_CODE);
|
||||
fragment.setLocationsHolder(locationsHolder);
|
||||
fragment.setSnapToRoadAppMode(appMode);
|
||||
fm.beginTransaction()
|
||||
.replace(R.id.fragmentContainer, fragment, TAG)
|
||||
.addToBackStack(TAG)
|
||||
|
@ -348,12 +350,19 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment
|
|||
|
||||
@Override
|
||||
public void onProfileSelect(ApplicationMode applicationMode) {
|
||||
if (snapToRoadAppMode != applicationMode) {
|
||||
snapToRoadAppMode = applicationMode;
|
||||
if (setSnapToRoadAppMode(applicationMode)) {
|
||||
calculateGpxApproximation();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setSnapToRoadAppMode(ApplicationMode appMode) {
|
||||
if (appMode != null && snapToRoadAppMode != appMode) {
|
||||
snapToRoadAppMode = appMode;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public LocationsHolder getLocationsHolder() {
|
||||
return locationsHolder;
|
||||
}
|
||||
|
|
|
@ -706,8 +706,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
case SnapTrackWarningFragment.CONTINUE_RESULT_CODE:
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
ApplicationMode mode = editingCtx.getAppMode();
|
||||
if (mode == ApplicationMode.DEFAULT || "public_transport".equals(mode.getRoutingProfile())) {
|
||||
mode = null;
|
||||
}
|
||||
GpxApproximationFragment.showInstance(mapActivity.getSupportFragmentManager(),
|
||||
this, new LocationsHolder(editingCtx.getPoints()));
|
||||
this, new LocationsHolder(editingCtx.getPoints()), mode);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1517,12 +1521,20 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
|
|||
|
||||
private String getSuggestedFileName() {
|
||||
GpxData gpxData = editingCtx.getGpxData();
|
||||
String displayedName;
|
||||
if (gpxData == null) {
|
||||
String displayedName = null;
|
||||
if (gpxData != null) {
|
||||
GPXFile gpxFile = gpxData.getGpxFile();
|
||||
if (!Algorithms.isEmpty(gpxFile.path)) {
|
||||
displayedName = Algorithms.getFileNameWithoutExtension(new File(gpxFile.path).getName());
|
||||
} else if (!Algorithms.isEmpty(gpxFile.tracks)) {
|
||||
displayedName = gpxFile.tracks.get(0).name;
|
||||
}
|
||||
}
|
||||
if (gpxData == null || displayedName == null) {
|
||||
String suggestedName = new SimpleDateFormat("EEE dd MMM yyyy", Locale.US).format(new Date());
|
||||
displayedName = FileUtils.createUniqueFileName(requireMyApplication(), suggestedName, GPX_INDEX_DIR, GPX_FILE_EXT);
|
||||
} else {
|
||||
displayedName = AndroidUtils.trimExtension(new File(gpxData.getGpxFile().path).getName());
|
||||
displayedName = Algorithms.getFileNameWithoutExtension(new File(gpxData.getGpxFile().path).getName());
|
||||
}
|
||||
return displayedName;
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import androidx.viewpager.widget.ViewPager;
|
|||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.FileUtils;
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
|
@ -482,12 +483,18 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
|
|||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
GPXRouteParamsBuilder paramsBuilder = app.getRoutingHelper().getCurrentGPXRoute();
|
||||
|
||||
String fileName;
|
||||
if (paramsBuilder == null || paramsBuilder.getFile() == null || paramsBuilder.getFile().path == null) {
|
||||
String fileName = null;
|
||||
if (paramsBuilder != null && paramsBuilder.getFile() != null) {
|
||||
GPXFile gpxFile = paramsBuilder.getFile();
|
||||
if (!Algorithms.isEmpty(gpxFile.path)) {
|
||||
fileName = Algorithms.getFileNameWithoutExtension(new File(gpxFile.path).getName());
|
||||
} else if (!Algorithms.isEmpty(gpxFile.tracks)) {
|
||||
fileName = gpxFile.tracks.get(0).name;
|
||||
}
|
||||
}
|
||||
if (Algorithms.isEmpty(fileName)) {
|
||||
String suggestedName = new SimpleDateFormat("EEE dd MMM yyyy", Locale.US).format(new Date());
|
||||
fileName = FileUtils.createUniqueFileName(app, suggestedName, IndexConstants.GPX_INDEX_DIR, GPX_FILE_EXT);
|
||||
} else {
|
||||
fileName = AndroidUtils.trimExtension(new File(paramsBuilder.getFile().path).getName());
|
||||
}
|
||||
SaveAsNewTrackBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(),
|
||||
ChooseRouteFragment.this, null, fileName,
|
||||
|
|
|
@ -25,6 +25,7 @@ import net.osmand.AndroidUtils;
|
|||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.GPXUtilities.TrkSegment;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.ValueHolder;
|
||||
|
@ -205,7 +206,6 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
|||
SelectTrackCard selectTrackCard = new SelectTrackCard(mapActivity);
|
||||
selectTrackCard.setListener(this);
|
||||
cardsContainer.addView(selectTrackCard.build(mapActivity));
|
||||
cardsContainer.addView(buildDividerView(cardsContainer, false));
|
||||
|
||||
ApplicationMode mode = app.getRoutingHelper().getAppMode();
|
||||
|
||||
|
@ -213,13 +213,16 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
|||
GPXRouteParamsBuilder rparams = routingHelper.getCurrentGPXRoute();
|
||||
boolean osmandRouter = mode.getRouteService() == RouteProvider.RouteService.OSMAND;
|
||||
if (rparams != null && osmandRouter) {
|
||||
if (!gpxFile.hasRoute() || gpxFile.hasRtePt()) {
|
||||
boolean showReverseCard = !routingHelper.isCurrentGPXRouteV2();
|
||||
if (showReverseCard) {
|
||||
cardsContainer.addView(buildDividerView(cardsContainer, false));
|
||||
|
||||
ReverseTrackCard reverseTrackCard = new ReverseTrackCard(mapActivity, rparams.isReverse());
|
||||
reverseTrackCard.setListener(this);
|
||||
cardsContainer.addView(reverseTrackCard.build(mapActivity));
|
||||
}
|
||||
if (!gpxFile.hasRtePt() && !gpxFile.hasRoute()) {
|
||||
cardsContainer.addView(buildDividerView(cardsContainer, true));
|
||||
cardsContainer.addView(buildDividerView(cardsContainer, showReverseCard));
|
||||
|
||||
AttachTrackToRoadsCard attachTrackCard = new AttachTrackToRoadsCard(mapActivity);
|
||||
attachTrackCard.setListener(this);
|
||||
|
@ -431,14 +434,11 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
|||
if (mapActivity != null) {
|
||||
if (card instanceof ImportTrackCard) {
|
||||
importTrack();
|
||||
} else if (card instanceof TrackEditCard) {
|
||||
openPlanRoute(true);
|
||||
} else if (card instanceof TrackEditCard || card instanceof AttachTrackToRoadsCard) {
|
||||
openPlanRoute();
|
||||
close();
|
||||
} else if (card instanceof SelectTrackCard) {
|
||||
updateSelectionMode(true);
|
||||
} else if (card instanceof AttachTrackToRoadsCard) {
|
||||
openPlanRoute(false);
|
||||
close();
|
||||
} else if (card instanceof ReverseTrackCard
|
||||
|| card instanceof NavigateTrackOptionsCard) {
|
||||
updateMenu();
|
||||
|
@ -486,6 +486,14 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
|||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
this.gpxFile = gpxFile;
|
||||
List<WptPt> points = gpxFile.getRoutePoints();
|
||||
if (!points.isEmpty()) {
|
||||
ApplicationMode mode = ApplicationMode.valueOfStringKey(points.get(0).getProfileType(), null);
|
||||
if (mode != null) {
|
||||
app.getRoutingHelper().setAppMode(mode);
|
||||
app.initVoiceCommandPlayer(mapActivity, mode, true, null, false, false, true);
|
||||
}
|
||||
}
|
||||
mapActivity.getMapActions().setGPXRouteParams(gpxFile);
|
||||
app.getTargetPointsHelper().updateRouteAndRefresh(true);
|
||||
app.getRoutingHelper().recalculateRouteDueToSettingsChange();
|
||||
|
@ -542,7 +550,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
|||
}
|
||||
}
|
||||
|
||||
public void openPlanRoute(boolean useAppMode) {
|
||||
public void openPlanRoute() {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null && gpxFile != null) {
|
||||
editingTrack = true;
|
||||
|
@ -552,9 +560,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
|
|||
GpxData gpxData = new GpxData(gpxFile, rect, actionType, segment);
|
||||
MeasurementEditingContext editingContext = new MeasurementEditingContext();
|
||||
editingContext.setGpxData(gpxData);
|
||||
if (useAppMode) {
|
||||
editingContext.setAppMode(app.getRoutingHelper().getAppMode());
|
||||
}
|
||||
editingContext.setAppMode(app.getRoutingHelper().getAppMode());
|
||||
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), editingContext, true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import androidx.core.content.ContextCompat;
|
|||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.StateChangedListener;
|
||||
import net.osmand.plus.OsmAndLocationSimulation;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -47,6 +48,7 @@ import net.osmand.plus.settings.backend.ApplicationMode;
|
|||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
|
||||
import net.osmand.router.GeneralRouter;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Arrays;
|
||||
|
@ -342,14 +344,19 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
|
||||
private BaseBottomSheetItem createGpxRoutingItem(final LocalRoutingParameter optionsItem) {
|
||||
RouteProvider.GPXRouteParamsBuilder routeParamsBuilder = mapActivity.getRoutingHelper().getCurrentGPXRoute();
|
||||
String description;
|
||||
String description = null;
|
||||
int descriptionColorId;
|
||||
if (routeParamsBuilder == null) {
|
||||
descriptionColorId = nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light;
|
||||
description = mapActivity.getString(R.string.follow_track_descr);
|
||||
} else {
|
||||
descriptionColorId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
|
||||
description = new File(routeParamsBuilder.getFile().path).getName();
|
||||
GPXFile gpxFile = routeParamsBuilder.getFile();
|
||||
if (!Algorithms.isEmpty(gpxFile.path)) {
|
||||
description = new File(gpxFile.path).getName();
|
||||
} else if (!Algorithms.isEmpty(gpxFile.tracks)) {
|
||||
description = gpxFile.tracks.get(0).name;
|
||||
}
|
||||
}
|
||||
|
||||
return new BottomSheetItemWithDescription.Builder()
|
||||
|
|
|
@ -12,6 +12,7 @@ import androidx.appcompat.view.ContextThemeWrapper;
|
|||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.plus.GPXDatabase.GpxDataItem;
|
||||
|
@ -19,6 +20,7 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.GpxUiHelper;
|
||||
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
|
@ -115,6 +117,14 @@ public class TracksCard extends BaseCard {
|
|||
v.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
List<GPXUtilities.WptPt> points = item.file.getRoutePoints();
|
||||
if (!points.isEmpty()) {
|
||||
ApplicationMode mode = ApplicationMode.valueOfStringKey(points.get(0).getProfileType(), null);
|
||||
if (mode != null) {
|
||||
app.getRoutingHelper().setAppMode(mode);
|
||||
app.initVoiceCommandPlayer(mapActivity, mode, true, null, false, false, true);
|
||||
}
|
||||
}
|
||||
mapActivity.getMapActions().setGPXRouteParams(item.file);
|
||||
app.getTargetPointsHelper().updateRouteAndRefresh(true);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue