Merge pull request #10430 from osmandapp/reverse-all-points

Reverse all points
This commit is contained in:
Vitaliy 2020-12-17 19:19:43 +02:00 committed by GitHub
commit 7caf6f370e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 5 deletions

View file

@ -11,6 +11,7 @@
Thx - Hardy
-->
<string name="reverse_all_points">Reverse all points</string>
<string name="release_3_9">
• 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

View file

@ -39,15 +39,17 @@ import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
*
*/
public class WaypointDialogHelper {
private MapActivity mapActivity;
private OsmandApplication app;
private WaypointHelper waypointHelper;
private List<WaypointDialogHelperCallback> helperCallbacks= new ArrayList<>();
private List<WaypointDialogHelperCallback> helperCallbacks = new ArrayList<>();
private boolean flat;
private List<LocationPointWrapper> deletedPoints;
@ -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) {
if (helper != null && helper.helperCallbacks != null) {
for (WaypointDialogHelperCallback callback : helper.helperCallbacks) {
@ -443,7 +459,8 @@ public class WaypointDialogHelper {
@Override
public void createMenuItems(Bundle savedInstanceState) {
items.add(new TitleItem(getString(R.string.shared_string_options)));
final OsmandApplication app = requiredMyApplication();
final TargetPointsHelper targetsHelper = app.getTargetPointsHelper();
BaseBottomSheetItem sortDoorToDoorItem = new SimpleBottomSheetItem.Builder()
.setIcon(getContentIcon(R.drawable.ic_action_sort_door_to_door))
.setTitle(getString(R.string.intermediate_items_sort_by_distance))
@ -491,6 +508,30 @@ public class WaypointDialogHelper {
.create();
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()));
final BaseBottomSheetItem[] addWaypointItem = new BaseBottomSheetItem[1];