Merge pull request #10430 from osmandapp/reverse-all-points
Reverse all points
This commit is contained in:
commit
7caf6f370e
2 changed files with 47 additions and 5 deletions
|
@ -11,6 +11,7 @@
|
||||||
Thx - Hardy
|
Thx - Hardy
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
<string name="reverse_all_points">Reverse all points</string>
|
||||||
<string name="release_3_9">
|
<string name="release_3_9">
|
||||||
• Added option to export and import all data including settings, resources, my places\n\n
|
• Added option to export and import all data including settings, resources, my places\n\n
|
||||||
• Plan Route: graphs for track segments with route, and added the ability to create and edit multiple track segments\n\n
|
• Plan Route: graphs for track segments with route, and added the ability to create and edit multiple track segments\n\n
|
||||||
|
|
|
@ -39,15 +39,17 @@ import net.osmand.util.Algorithms;
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public class WaypointDialogHelper {
|
public class WaypointDialogHelper {
|
||||||
private MapActivity mapActivity;
|
private MapActivity mapActivity;
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private WaypointHelper waypointHelper;
|
private WaypointHelper waypointHelper;
|
||||||
private List<WaypointDialogHelperCallback> helperCallbacks= new ArrayList<>();
|
private List<WaypointDialogHelperCallback> helperCallbacks = new ArrayList<>();
|
||||||
|
|
||||||
private boolean flat;
|
private boolean flat;
|
||||||
private List<LocationPointWrapper> deletedPoints;
|
private List<LocationPointWrapper> deletedPoints;
|
||||||
|
@ -242,8 +244,8 @@ public class WaypointDialogHelper {
|
||||||
|
|
||||||
// switch start & finish
|
// switch start & finish
|
||||||
public static void switchStartAndFinish(TargetPointsHelper targetPointsHelper, TargetPoint finish,
|
public static void switchStartAndFinish(TargetPointsHelper targetPointsHelper, TargetPoint finish,
|
||||||
Activity ctx, TargetPoint start, OsmandApplication app,
|
Activity ctx, TargetPoint start, OsmandApplication app,
|
||||||
WaypointDialogHelper helper) {
|
WaypointDialogHelper helper) {
|
||||||
if (finish == null) {
|
if (finish == null) {
|
||||||
app.showShortToastMessage(R.string.mark_final_location_first);
|
app.showShortToastMessage(R.string.mark_final_location_first);
|
||||||
} else {
|
} else {
|
||||||
|
@ -263,6 +265,20 @@ public class WaypointDialogHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void reverseAllPoints(OsmandApplication app, Activity ctx,
|
||||||
|
WaypointDialogHelper helper) {
|
||||||
|
TargetPointsHelper targets = app.getTargetPointsHelper();
|
||||||
|
if (!targets.getAllPoints().isEmpty()) {
|
||||||
|
List<TargetPoint> points = targets.getAllPoints();
|
||||||
|
Collections.reverse(points);
|
||||||
|
TargetPoint start = points.get(0);
|
||||||
|
targets.setStartPoint(start.point, false, start.getOriginalPointDescription());
|
||||||
|
points.remove(start);
|
||||||
|
targets.reorderAllTargetPoints(points, true);
|
||||||
|
updateControls(ctx, helper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void updateControls(Activity ctx, WaypointDialogHelper helper) {
|
public static void updateControls(Activity ctx, WaypointDialogHelper helper) {
|
||||||
if (helper != null && helper.helperCallbacks != null) {
|
if (helper != null && helper.helperCallbacks != null) {
|
||||||
for (WaypointDialogHelperCallback callback : helper.helperCallbacks) {
|
for (WaypointDialogHelperCallback callback : helper.helperCallbacks) {
|
||||||
|
@ -278,7 +294,7 @@ public class WaypointDialogHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void replaceStartWithFirstIntermediate(TargetPointsHelper targetPointsHelper, Activity ctx,
|
public static void replaceStartWithFirstIntermediate(TargetPointsHelper targetPointsHelper, Activity ctx,
|
||||||
WaypointDialogHelper helper) {
|
WaypointDialogHelper helper) {
|
||||||
List<TargetPoint> intermediatePoints = targetPointsHelper.getIntermediatePointsWithTarget();
|
List<TargetPoint> intermediatePoints = targetPointsHelper.getIntermediatePointsWithTarget();
|
||||||
TargetPoint firstIntermediate = intermediatePoints.remove(0);
|
TargetPoint firstIntermediate = intermediatePoints.remove(0);
|
||||||
targetPointsHelper.setStartPoint(new LatLon(firstIntermediate.getLatitude(),
|
targetPointsHelper.setStartPoint(new LatLon(firstIntermediate.getLatitude(),
|
||||||
|
@ -443,7 +459,8 @@ public class WaypointDialogHelper {
|
||||||
@Override
|
@Override
|
||||||
public void createMenuItems(Bundle savedInstanceState) {
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
items.add(new TitleItem(getString(R.string.shared_string_options)));
|
items.add(new TitleItem(getString(R.string.shared_string_options)));
|
||||||
|
final OsmandApplication app = requiredMyApplication();
|
||||||
|
final TargetPointsHelper targetsHelper = app.getTargetPointsHelper();
|
||||||
BaseBottomSheetItem sortDoorToDoorItem = new SimpleBottomSheetItem.Builder()
|
BaseBottomSheetItem sortDoorToDoorItem = new SimpleBottomSheetItem.Builder()
|
||||||
.setIcon(getContentIcon(R.drawable.ic_action_sort_door_to_door))
|
.setIcon(getContentIcon(R.drawable.ic_action_sort_door_to_door))
|
||||||
.setTitle(getString(R.string.intermediate_items_sort_by_distance))
|
.setTitle(getString(R.string.intermediate_items_sort_by_distance))
|
||||||
|
@ -491,6 +508,30 @@ public class WaypointDialogHelper {
|
||||||
.create();
|
.create();
|
||||||
items.add(reorderStartAndFinishItem);
|
items.add(reorderStartAndFinishItem);
|
||||||
|
|
||||||
|
BaseBottomSheetItem reorderAllItems = new SimpleBottomSheetItem.Builder()
|
||||||
|
.setIcon(getContentIcon(R.drawable.ic_action_sort_reverse_order))
|
||||||
|
.setTitle(getString(R.string.reverse_all_points))
|
||||||
|
.setLayoutId(R.layout.bottom_sheet_item_simple)
|
||||||
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
MapActivity mapActivity = getMapActivity();
|
||||||
|
if (mapActivity != null) {
|
||||||
|
WaypointDialogHelper.reverseAllPoints(
|
||||||
|
app,
|
||||||
|
mapActivity,
|
||||||
|
mapActivity.getDashboard().getWaypointDialogHelper()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.create();
|
||||||
|
int intermediateSize = targetsHelper.getIntermediatePoints().size();
|
||||||
|
if (intermediateSize > 2) {
|
||||||
|
items.add(reorderAllItems);
|
||||||
|
}
|
||||||
|
|
||||||
items.add(new DividerHalfItem(getContext()));
|
items.add(new DividerHalfItem(getContext()));
|
||||||
|
|
||||||
final BaseBottomSheetItem[] addWaypointItem = new BaseBottomSheetItem[1];
|
final BaseBottomSheetItem[] addWaypointItem = new BaseBottomSheetItem[1];
|
||||||
|
|
Loading…
Reference in a new issue