From ff6701de70562141541025ac4524bcb98e2f606a Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Thu, 17 Dec 2020 15:01:14 +0200 Subject: [PATCH 1/4] temp --- OsmAnd/res/values/strings.xml | 1 + .../plus/helpers/WaypointDialogHelper.java | 51 +++++++++++++++++-- 2 files changed, 48 insertions(+), 4 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 56d61d25ff..eecb00ee9a 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + Reverse all points • 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 diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java index 19cd646ecb..628bc7ed71 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java @@ -42,12 +42,13 @@ import java.util.ArrayList; import java.util.List; /** + * */ public class WaypointDialogHelper { private MapActivity mapActivity; private OsmandApplication app; private WaypointHelper waypointHelper; - private List helperCallbacks= new ArrayList<>(); + private List helperCallbacks = new ArrayList<>(); private boolean flat; private List deletedPoints; @@ -242,8 +243,8 @@ public class WaypointDialogHelper { // switch start & finish public static void switchStartAndFinish(TargetPointsHelper targetPointsHelper, TargetPoint finish, - Activity ctx, TargetPoint start, OsmandApplication app, - WaypointDialogHelper helper) { + Activity ctx, TargetPoint start, OsmandApplication app, + WaypointDialogHelper helper) { if (finish == null) { app.showShortToastMessage(R.string.mark_final_location_first); } else { @@ -263,6 +264,22 @@ public class WaypointDialogHelper { } } + public static void switchAllPoint(final OsmandApplication app, final Activity ctx, + final WaypointDialogHelper helper) { + List all; + TargetPointsHelper targets = app.getTargetPointsHelper(); + all = targets.getIntermediatePointsWithTarget(); + + List cur = targets.getIntermediatePointsWithTarget(); + for (int j = 0; j < cur.size() && j < all.size(); j++) { + if (cur.get(j) != all.get(j)) { + break; + } + } + targets.reorderAllTargetPoints(all, true); + updateControls(ctx, helper); + } + public static void updateControls(Activity ctx, WaypointDialogHelper helper) { if (helper != null && helper.helperCallbacks != null) { for (WaypointDialogHelperCallback callback : helper.helperCallbacks) { @@ -278,7 +295,7 @@ public class WaypointDialogHelper { } public static void replaceStartWithFirstIntermediate(TargetPointsHelper targetPointsHelper, Activity ctx, - WaypointDialogHelper helper) { + WaypointDialogHelper helper) { List intermediatePoints = targetPointsHelper.getIntermediatePointsWithTarget(); TargetPoint firstIntermediate = intermediatePoints.remove(0); targetPointsHelper.setStartPoint(new LatLon(firstIntermediate.getLatitude(), @@ -493,6 +510,32 @@ public class WaypointDialogHelper { items.add(new DividerHalfItem(getContext())); + BaseBottomSheetItem reorderAllItems = new SimpleBottomSheetItem.Builder() + .setIcon(getContentIcon(R.drawable.ic_action_sort_reverse_order)) + .setTitle(getString(R.string.switch_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.switchAllPoint( + mapActivity.getMyApplication(), + mapActivity, + mapActivity.getDashboard().getWaypointDialogHelper() + ); + } + dismiss(); + } + }) + .create(); + if (getMyApplication() != null) { + int intermediateSize = getMyApplication().getTargetPointsHelper().getAllPoints().size(); + if (intermediateSize > 2) { + items.add(reorderAllItems); + } + } + final BaseBottomSheetItem[] addWaypointItem = new BaseBottomSheetItem[1]; addWaypointItem[0] = new SimpleBottomSheetItem.Builder() .setIcon(getContentIcon(R.drawable.ic_action_plus)) From 50162f229ab53c555a52b57f41842fecf4ec7e71 Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Thu, 17 Dec 2020 17:25:15 +0200 Subject: [PATCH 2/4] Sort: Allow to reverse all points --- .../plus/helpers/WaypointDialogHelper.java | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java index 628bc7ed71..24d684a408 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java @@ -39,6 +39,7 @@ import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -266,17 +267,13 @@ public class WaypointDialogHelper { public static void switchAllPoint(final OsmandApplication app, final Activity ctx, final WaypointDialogHelper helper) { - List all; TargetPointsHelper targets = app.getTargetPointsHelper(); - all = targets.getIntermediatePointsWithTarget(); - - List cur = targets.getIntermediatePointsWithTarget(); - for (int j = 0; j < cur.size() && j < all.size(); j++) { - if (cur.get(j) != all.get(j)) { - break; - } - } - targets.reorderAllTargetPoints(all, true); + List 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); } @@ -508,8 +505,6 @@ public class WaypointDialogHelper { .create(); items.add(reorderStartAndFinishItem); - items.add(new DividerHalfItem(getContext())); - BaseBottomSheetItem reorderAllItems = new SimpleBottomSheetItem.Builder() .setIcon(getContentIcon(R.drawable.ic_action_sort_reverse_order)) .setTitle(getString(R.string.switch_all_points)) @@ -530,12 +525,14 @@ public class WaypointDialogHelper { }) .create(); if (getMyApplication() != null) { - int intermediateSize = getMyApplication().getTargetPointsHelper().getAllPoints().size(); + int intermediateSize = getMyApplication().getTargetPointsHelper().getIntermediatePoints().size(); if (intermediateSize > 2) { items.add(reorderAllItems); } } + items.add(new DividerHalfItem(getContext())); + final BaseBottomSheetItem[] addWaypointItem = new BaseBottomSheetItem[1]; addWaypointItem[0] = new SimpleBottomSheetItem.Builder() .setIcon(getContentIcon(R.drawable.ic_action_plus)) From 9ac96bfb86cb7390ec442696bf15ec1fd8ea7b0d Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Thu, 17 Dec 2020 18:57:48 +0200 Subject: [PATCH 3/4] Refactor --- OsmAnd/res/values/strings.xml | 2 +- .../plus/helpers/WaypointDialogHelper.java | 21 +++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index eecb00ee9a..4647ed8506 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,7 +11,7 @@ Thx - Hardy --> - Reverse all points + Reverse all points • 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 diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java index 24d684a408..8fbfcb45fc 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java @@ -265,8 +265,8 @@ public class WaypointDialogHelper { } } - public static void switchAllPoint(final OsmandApplication app, final Activity ctx, - final WaypointDialogHelper helper) { + public static void reverseAllPoints(OsmandApplication app, Activity ctx, + WaypointDialogHelper helper) { TargetPointsHelper targets = app.getTargetPointsHelper(); List points = targets.getAllPoints(); Collections.reverse(points); @@ -457,7 +457,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)) @@ -507,15 +508,15 @@ public class WaypointDialogHelper { BaseBottomSheetItem reorderAllItems = new SimpleBottomSheetItem.Builder() .setIcon(getContentIcon(R.drawable.ic_action_sort_reverse_order)) - .setTitle(getString(R.string.switch_all_points)) + .setTitle(getString(R.string.reverce_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.switchAllPoint( - mapActivity.getMyApplication(), + WaypointDialogHelper.reverseAllPoints( + app, mapActivity, mapActivity.getDashboard().getWaypointDialogHelper() ); @@ -524,11 +525,9 @@ public class WaypointDialogHelper { } }) .create(); - if (getMyApplication() != null) { - int intermediateSize = getMyApplication().getTargetPointsHelper().getIntermediatePoints().size(); - if (intermediateSize > 2) { - items.add(reorderAllItems); - } + int intermediateSize = targetsHelper.getIntermediatePoints().size(); + if (intermediateSize > 2 && !targetsHelper.getAllPoints().isEmpty()) { + items.add(reorderAllItems); } items.add(new DividerHalfItem(getContext())); From 0f69a1c0481d6922165d64bb68a01ee147f87365 Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Thu, 17 Dec 2020 19:15:27 +0200 Subject: [PATCH 4/4] Typo fix, additional fix --- OsmAnd/res/values/strings.xml | 2 +- .../plus/helpers/WaypointDialogHelper.java | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 4647ed8506..b1df50c808 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,7 +11,7 @@ Thx - Hardy --> - Reverse all points + Reverse all points • 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 diff --git a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java index 8fbfcb45fc..8d0d8210c1 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/WaypointDialogHelper.java @@ -268,13 +268,15 @@ public class WaypointDialogHelper { public static void reverseAllPoints(OsmandApplication app, Activity ctx, WaypointDialogHelper helper) { TargetPointsHelper targets = app.getTargetPointsHelper(); - List 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); + if (!targets.getAllPoints().isEmpty()) { + List 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) { @@ -508,7 +510,7 @@ public class WaypointDialogHelper { BaseBottomSheetItem reorderAllItems = new SimpleBottomSheetItem.Builder() .setIcon(getContentIcon(R.drawable.ic_action_sort_reverse_order)) - .setTitle(getString(R.string.reverce_all_points)) + .setTitle(getString(R.string.reverse_all_points)) .setLayoutId(R.layout.bottom_sheet_item_simple) .setOnClickListener(new View.OnClickListener() { @Override @@ -526,7 +528,7 @@ public class WaypointDialogHelper { }) .create(); int intermediateSize = targetsHelper.getIntermediatePoints().size(); - if (intermediateSize > 2 && !targetsHelper.getAllPoints().isEmpty()) { + if (intermediateSize > 2) { items.add(reorderAllItems); }