From ad281d44456d68f361fa2040f61b0e8bfee08731 Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Fri, 27 Nov 2020 20:27:29 +0200 Subject: [PATCH 1/3] Make yes/no buttons larger and farther apart --- OsmAnd/res/values/strings.xml | 2 +- .../plus/activities/MapActivityActions.java | 24 +--- .../base/MenuBottomSheetDialogFragment.java | 2 +- .../DismissRouteBottomSheetFragment.java | 127 ++++++++++++++++++ 4 files changed, 133 insertions(+), 22 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/osmedit/dialogs/DismissRouteBottomSheetFragment.java diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 9da2ac6d86..9c4708f0dc 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -2652,7 +2652,7 @@ %1$d files left %1$d files left to download Full version - Dismiss route + Dismiss route? Stop navigation Clear destination Not connected to Wi-Fi. Use current connection to the Internet to download? diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 00bd656b63..acc122f560 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -61,6 +61,7 @@ import net.osmand.plus.mapmarkers.MarkersPlanRouteContext; import net.osmand.plus.measurementtool.MeasurementToolFragment; import net.osmand.plus.measurementtool.StartPlanRouteBottomSheet; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; +import net.osmand.plus.osmedit.dialogs.DismissRouteBottomSheetFragment; import net.osmand.plus.profiles.RoutingProfileDataObject; import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu; import net.osmand.plus.routepreparationmenu.WaypointsFragment; @@ -157,6 +158,7 @@ public class MapActivityActions implements DialogProvider { private final MapActivity mapActivity; private OsmandSettings settings; + private DialogInterface.OnDismissListener dismissListener; @NonNull private ImageView drawerLogoHeader; @@ -1122,26 +1124,8 @@ public class MapActivityActions implements DialogProvider { } } - public AlertDialog stopNavigationActionConfirm() { - return stopNavigationActionConfirm(null); - } - - public AlertDialog stopNavigationActionConfirm(final Runnable onStopAction) { - AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity); - // Stop the navigation - builder.setTitle(getString(R.string.cancel_route)); - builder.setMessage(getString(R.string.stop_routing_confirm)); - builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - stopNavigationWithoutConfirm(); - if (onStopAction != null) { - onStopAction.run(); - } - } - }); - builder.setNegativeButton(R.string.shared_string_no, null); - return builder.show(); + public void stopNavigationActionConfirm() { + DismissRouteBottomSheetFragment.showInstance(mapActivity.getSupportFragmentManager(), null, dismissListener); } public void whereAmIDialog() { diff --git a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java index 84bd292aa5..1b07ab16ae 100644 --- a/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/base/MenuBottomSheetDialogFragment.java @@ -306,7 +306,7 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra } } - boolean useVerticalButtons() { + protected boolean useVerticalButtons() { Activity activity = requireActivity(); int rightBottomButtonTextId = getRightBottomButtonTextId(); if (getDismissButtonTextId() != DEFAULT_VALUE && rightBottomButtonTextId != DEFAULT_VALUE) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DismissRouteBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DismissRouteBottomSheetFragment.java new file mode 100644 index 0000000000..1780151c4b --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DismissRouteBottomSheetFragment.java @@ -0,0 +1,127 @@ +package net.osmand.plus.osmedit.dialogs; + +import android.app.Activity; +import android.content.DialogInterface; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentManager; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem; +import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem; +import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.router.GeneralRouter; + +import java.util.List; + +public class DismissRouteBottomSheetFragment extends MenuBottomSheetDialogFragment { + + private OsmandApplication app; + private OsmandSettings settings; + + public static final int REQUEST_CODE = 1001; + + public static final String TAG = DismissRouteBottomSheetFragment.class.getSimpleName(); + private DialogInterface.OnDismissListener dismissListener; + + public DismissRouteBottomSheetFragment() { + } + + @Override + public void createMenuItems(Bundle savedInstanceState) { + app = getMyApplication(); + if (app != null) { + settings = app.getSettings(); + } + + items.add(new ShortDescriptionItem.Builder() + .setDescription(getString(R.string.stop_routing_confirm)) + .setTitle(getString(R.string.cancel_route)) + .setLayoutId(R.layout.bottom_sheet_item_list_title_with_descr) + .create()); + + items.add(new DividerSpaceItem(getContext(), + getResources().getDimensionPixelSize(R.dimen.content_padding_small))); + + } + + @Override + protected boolean useVerticalButtons() { + return false; + } + + @Override + protected int getDismissButtonTextId() { + return R.string.shared_string_cancel; + } + + @Override + protected int getRightBottomButtonTextId() { + return R.string.shared_string_dismiss; + } + + @Override + protected UiUtilities.DialogButtonType getRightBottomButtonType() { + return (UiUtilities.DialogButtonType.PRIMARY); + } + + @Override + public int getSecondDividerHeight() { + return getResources().getDimensionPixelSize(R.dimen.bottom_sheet_icon_margin); + } + + @Override + protected void onRightBottomButtonClick() { + stopNavigationWithoutConfirm(); + dismiss(); + } + + public void stopNavigationWithoutConfirm() { + app.stopNavigation(); + getMapActivity().updateApplicationModeSettings(); + getMapActivity().getDashboard().clearDeletedPoints(); + List modes = ApplicationMode.values(app); + for (ApplicationMode mode : modes) { + if (settings.FORCE_PRIVATE_ACCESS_ROUTING_ASKED.getModeValue(mode)) { + settings.FORCE_PRIVATE_ACCESS_ROUTING_ASKED.setModeValue(mode, false); + settings.getCustomRoutingBooleanProperty(GeneralRouter.ALLOW_PRIVATE, false).setModeValue(mode, false); + } + } + } + + @Override + public void onDismiss(@NonNull DialogInterface dialog) { + super.onDismiss(dialog); + if (dismissListener != null) { + dismissListener.onDismiss(dialog); + } + } + + @Nullable + public MapActivity getMapActivity() { + Activity activity = getActivity(); + if (activity instanceof MapActivity) { + return (MapActivity) activity; + } + return null; + + } + + public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment targetFragment, DialogInterface.OnDismissListener dismissListener) { + if (!fragmentManager.isStateSaved()) { + DismissRouteBottomSheetFragment fragment = new DismissRouteBottomSheetFragment(); + fragment.dismissListener = dismissListener; + fragment.setTargetFragment(targetFragment, REQUEST_CODE); + fragment.show(fragmentManager, TAG); + } + } +} + From bb1f7cdd71cb955ee5c39d1396ca21b1b79432a9 Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Sun, 29 Nov 2020 11:44:40 +0200 Subject: [PATCH 2/3] Dismiss listener --- .../plus/osmedit/dialogs/DismissRouteBottomSheetFragment.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DismissRouteBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DismissRouteBottomSheetFragment.java index 1780151c4b..a14e811b2d 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DismissRouteBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DismissRouteBottomSheetFragment.java @@ -115,6 +115,10 @@ public class DismissRouteBottomSheetFragment extends MenuBottomSheetDialogFragme } + public void setOnDismissListener(DialogInterface.OnDismissListener dismissListener) { + this.dismissListener = dismissListener; + } + public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment targetFragment, DialogInterface.OnDismissListener dismissListener) { if (!fragmentManager.isStateSaved()) { DismissRouteBottomSheetFragment fragment = new DismissRouteBottomSheetFragment(); From 64e95f7cd579769a6e1c7e61ddf6aa8dd00a8a5a Mon Sep 17 00:00:00 2001 From: androiddevkkotlin Date: Fri, 4 Dec 2020 11:39:18 +0200 Subject: [PATCH 3/3] Make yes/no buttons larger --- OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 13 ++- .../plus/activities/MapActivityActions.java | 15 ++-- .../dashboard/DashNavigationFragment.java | 8 +- .../plus/helpers/ExternalApiHelper.java | 10 +-- .../MeasurementToolFragment.java | 2 +- .../DismissRouteBottomSheetFragment.java | 81 +++++++------------ .../plus/views/layers/MapControlsLayer.java | 2 +- 7 files changed, 50 insertions(+), 81 deletions(-) diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index f319a878be..467ad76a0f 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -19,7 +19,6 @@ import android.view.KeyEvent; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -55,8 +54,6 @@ import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; -import net.osmand.plus.mapmarkers.MapMarkersHelper; -import net.osmand.plus.mapmarkers.MapMarker; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.SQLiteTileSource; @@ -68,6 +65,8 @@ import net.osmand.plus.helpers.ExternalApiHelper; import net.osmand.plus.helpers.LockHelper; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.other.IContextMenuButtonListener; +import net.osmand.plus.mapmarkers.MapMarker; +import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.myplaces.TrackBitmapDrawer; import net.osmand.plus.quickaction.QuickAction; @@ -79,11 +78,11 @@ import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.VoiceRouter; import net.osmand.plus.settings.backend.ApplicationMode; +import net.osmand.plus.settings.backend.ExportSettingsType; import net.osmand.plus.settings.backend.OsmAndAppCustomization; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.backend.backup.ProfileSettingsItem; import net.osmand.plus.settings.backend.backup.SettingsHelper; -import net.osmand.plus.settings.backend.ExportSettingsType; import net.osmand.plus.settings.backend.backup.SettingsItem; import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.OsmandMapTileView; @@ -598,8 +597,7 @@ public class OsmandAidlApi { final RoutingHelper routingHelper = app.getRoutingHelper(); boolean force = intent.getBooleanExtra(AIDL_FORCE, true); if (routingHelper.isFollowingMode() && !force) { - AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm(); - dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { + mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { @@ -665,8 +663,7 @@ public class OsmandAidlApi { final RoutingHelper routingHelper = app.getRoutingHelper(); boolean force = intent.getBooleanExtra(AIDL_FORCE, true); if (routingHelper.isFollowingMode() && !force) { - AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm(); - dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { + mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index acc122f560..0213268a05 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -3,6 +3,7 @@ package net.osmand.plus.activities; import android.app.Activity; import android.app.Dialog; import android.content.DialogInterface; +import android.content.DialogInterface.OnDismissListener; import android.content.Intent; import android.graphics.Bitmap; import android.net.Uri; @@ -39,8 +40,6 @@ import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuAdapter.ItemClickListener; import net.osmand.plus.ContextMenuItem; import net.osmand.plus.ContextMenuItem.ItemBuilder; -import net.osmand.plus.mapmarkers.MapMarkersHelper; -import net.osmand.plus.mapmarkers.MapMarker; import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; @@ -56,7 +55,9 @@ import net.osmand.plus.download.IndexItem; import net.osmand.plus.liveupdates.OsmLiveActivity; import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment; import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener; +import net.osmand.plus.mapmarkers.MapMarker; import net.osmand.plus.mapmarkers.MapMarkersDialogFragment; +import net.osmand.plus.mapmarkers.MapMarkersHelper; import net.osmand.plus.mapmarkers.MarkersPlanRouteContext; import net.osmand.plus.measurementtool.MeasurementToolFragment; import net.osmand.plus.measurementtool.StartPlanRouteBottomSheet; @@ -76,7 +77,6 @@ import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.layers.MapControlsLayer; import net.osmand.plus.wikipedia.WikipediaDialogFragment; import net.osmand.plus.wikivoyage.WikivoyageWelcomeDialogFragment; -import net.osmand.plus.wikivoyage.data.TravelDbHelper; import net.osmand.plus.wikivoyage.data.TravelHelper; import net.osmand.plus.wikivoyage.explore.WikivoyageExploreActivity; import net.osmand.router.GeneralRouter; @@ -158,7 +158,6 @@ public class MapActivityActions implements DialogProvider { private final MapActivity mapActivity; private OsmandSettings settings; - private DialogInterface.OnDismissListener dismissListener; @NonNull private ImageView drawerLogoHeader; @@ -1124,8 +1123,12 @@ public class MapActivityActions implements DialogProvider { } } - public void stopNavigationActionConfirm() { - DismissRouteBottomSheetFragment.showInstance(mapActivity.getSupportFragmentManager(), null, dismissListener); + public void stopNavigationActionConfirm(@Nullable OnDismissListener listener) { + stopNavigationActionConfirm(listener, null); + } + + public void stopNavigationActionConfirm(@Nullable OnDismissListener listener, @Nullable Runnable onStopAction) { + DismissRouteBottomSheetFragment.showInstance(mapActivity.getSupportFragmentManager(), listener, onStopAction); } public void whereAmIDialog() { diff --git a/OsmAnd/src/net/osmand/plus/dashboard/DashNavigationFragment.java b/OsmAnd/src/net/osmand/plus/dashboard/DashNavigationFragment.java index db4ab19884..b7f359a3e4 100644 --- a/OsmAnd/src/net/osmand/plus/dashboard/DashNavigationFragment.java +++ b/OsmAnd/src/net/osmand/plus/dashboard/DashNavigationFragment.java @@ -11,7 +11,6 @@ import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.FragmentActivity; import net.osmand.plus.R; @@ -85,14 +84,13 @@ public class DashNavigationFragment extends DashBaseFragment { @Override public void onClick(View v) { - AlertDialog dlg = map.getMapActions().stopNavigationActionConfirm(); - dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { - + map.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() { + @Override public void onDismiss(DialogInterface dialog) { setupNavigation(); DashWaypointsFragment f = dashboard.getFragmentByClass(DashWaypointsFragment.class); - if(f != null) { + if (f != null) { f.onOpenDash(); } } diff --git a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java index c2b1c25591..c92438e850 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ExternalApiHelper.java @@ -11,7 +11,6 @@ import android.os.ParcelFileDescriptor; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.appcompat.app.AlertDialog; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; @@ -293,8 +292,7 @@ public class ExternalApiHelper { final RoutingHelper routingHelper = app.getRoutingHelper(); if (routingHelper.isFollowingMode() && !force) { - AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm(); - dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { + mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { @@ -353,8 +351,7 @@ public class ExternalApiHelper { final RoutingHelper routingHelper = app.getRoutingHelper(); if (routingHelper.isFollowingMode() && !force) { - AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm(); - dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { + mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { @@ -667,8 +664,7 @@ public class ExternalApiHelper { } final RoutingHelper routingHelper = app.getRoutingHelper(); if (routingHelper.isFollowingMode() && !force) { - AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm(); - dlg.setOnDismissListener(new DialogInterface.OnDismissListener() { + mapActivity.getMapActions().stopNavigationActionConfirm(new DialogInterface.OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index a441c7607a..db5a66cdce 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -886,7 +886,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route app.getTargetPointsHelper().updateRouteAndRefresh(true); app.getRoutingHelper().recalculateRouteDueToSettingsChange(); } else { - mapActivity.getMapActions().stopNavigationActionConfirm(new Runnable() { + mapActivity.getMapActions().stopNavigationActionConfirm(null , new Runnable() { @Override public void run() { MapActivity mapActivity = getMapActivity(); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DismissRouteBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DismissRouteBottomSheetFragment.java index a14e811b2d..641cee51cc 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DismissRouteBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/DismissRouteBottomSheetFragment.java @@ -2,55 +2,41 @@ package net.osmand.plus.osmedit.dialogs; import android.app.Activity; import android.content.DialogInterface; +import android.content.DialogInterface.OnDismissListener; import android.os.Bundle; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; -import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; -import net.osmand.plus.UiUtilities; +import net.osmand.plus.UiUtilities.DialogButtonType; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MenuBottomSheetDialogFragment; +import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; +import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem; -import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem; -import net.osmand.plus.settings.backend.ApplicationMode; -import net.osmand.plus.settings.backend.OsmandSettings; -import net.osmand.router.GeneralRouter; - -import java.util.List; public class DismissRouteBottomSheetFragment extends MenuBottomSheetDialogFragment { - private OsmandApplication app; - private OsmandSettings settings; - - public static final int REQUEST_CODE = 1001; - public static final String TAG = DismissRouteBottomSheetFragment.class.getSimpleName(); - private DialogInterface.OnDismissListener dismissListener; - public DismissRouteBottomSheetFragment() { - } + private Runnable onStopAction; + private OnDismissListener dismissListener; @Override public void createMenuItems(Bundle savedInstanceState) { - app = getMyApplication(); - if (app != null) { - settings = app.getSettings(); - } - - items.add(new ShortDescriptionItem.Builder() + BaseBottomSheetItem descriptionItem = new BottomSheetItemWithDescription.Builder() .setDescription(getString(R.string.stop_routing_confirm)) .setTitle(getString(R.string.cancel_route)) .setLayoutId(R.layout.bottom_sheet_item_list_title_with_descr) - .create()); + .create(); - items.add(new DividerSpaceItem(getContext(), - getResources().getDimensionPixelSize(R.dimen.content_padding_small))); + items.add(descriptionItem); + int padding = getResources().getDimensionPixelSize(R.dimen.content_padding_small); + items.add(new DividerSpaceItem(requireContext(), padding)); } @Override @@ -69,8 +55,8 @@ public class DismissRouteBottomSheetFragment extends MenuBottomSheetDialogFragme } @Override - protected UiUtilities.DialogButtonType getRightBottomButtonType() { - return (UiUtilities.DialogButtonType.PRIMARY); + protected DialogButtonType getRightBottomButtonType() { + return DialogButtonType.PRIMARY; } @Override @@ -80,27 +66,21 @@ public class DismissRouteBottomSheetFragment extends MenuBottomSheetDialogFragme @Override protected void onRightBottomButtonClick() { - stopNavigationWithoutConfirm(); - dismiss(); - } - - public void stopNavigationWithoutConfirm() { - app.stopNavigation(); - getMapActivity().updateApplicationModeSettings(); - getMapActivity().getDashboard().clearDeletedPoints(); - List modes = ApplicationMode.values(app); - for (ApplicationMode mode : modes) { - if (settings.FORCE_PRIVATE_ACCESS_ROUTING_ASKED.getModeValue(mode)) { - settings.FORCE_PRIVATE_ACCESS_ROUTING_ASKED.setModeValue(mode, false); - settings.getCustomRoutingBooleanProperty(GeneralRouter.ALLOW_PRIVATE, false).setModeValue(mode, false); - } + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getMapActions().stopNavigationWithoutConfirm(); } + if (onStopAction != null) { + onStopAction.run(); + } + dismiss(); } @Override public void onDismiss(@NonNull DialogInterface dialog) { super.onDismiss(dialog); - if (dismissListener != null) { + FragmentActivity activity = getActivity(); + if (activity != null && !activity.isChangingConfigurations() && dismissListener != null) { dismissListener.onDismiss(dialog); } } @@ -112,20 +92,15 @@ public class DismissRouteBottomSheetFragment extends MenuBottomSheetDialogFragme return (MapActivity) activity; } return null; - } - public void setOnDismissListener(DialogInterface.OnDismissListener dismissListener) { - this.dismissListener = dismissListener; - } - - public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment targetFragment, DialogInterface.OnDismissListener dismissListener) { + public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable OnDismissListener listener, @Nullable Runnable onStopAction) { if (!fragmentManager.isStateSaved()) { DismissRouteBottomSheetFragment fragment = new DismissRouteBottomSheetFragment(); - fragment.dismissListener = dismissListener; - fragment.setTargetFragment(targetFragment, REQUEST_CODE); + fragment.dismissListener = listener; + fragment.onStopAction = onStopAction; + fragment.setRetainInstance(true); fragment.show(fragmentManager, TAG); } } -} - +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java index 9a24d0aba6..e7cc9b4466 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/MapControlsLayer.java @@ -339,7 +339,7 @@ public class MapControlsLayer extends OsmandMapLayer { public void stopNavigation() { mapRouteInfoMenu.hide(); if (mapActivity.getRoutingHelper().isFollowingMode()) { - mapActivity.getMapActions().stopNavigationActionConfirm(); + mapActivity.getMapActions().stopNavigationActionConfirm(null); } else { mapActivity.getMapActions().stopNavigationWithoutConfirm(); }