From 9ac96bfb86cb7390ec442696bf15ec1fd8ea7b0d Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Thu, 17 Dec 2020 18:57:48 +0200 Subject: [PATCH] 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()));