diff --git a/OsmAnd/src/net/osmand/plus/profiles/ConfigureAppModesBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/profiles/ConfigureAppModesBottomSheetDialogFragment.java index ab59432b01..687cd342bf 100644 --- a/OsmAnd/src/net/osmand/plus/profiles/ConfigureAppModesBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/profiles/ConfigureAppModesBottomSheetDialogFragment.java @@ -1,7 +1,11 @@ package net.osmand.plus.profiles; -import net.osmand.plus.settings.backend.ApplicationMode; +import androidx.annotation.NonNull; +import androidx.fragment.app.FragmentManager; + import net.osmand.plus.R; +import net.osmand.plus.profiles.ConfigureProfileMenuAdapter.ProfileSelectedListener; +import net.osmand.plus.settings.backend.ApplicationMode; import java.util.ArrayList; import java.util.HashSet; @@ -9,8 +13,8 @@ import java.util.LinkedHashSet; import java.util.List; import java.util.Set; -public class ConfigureAppModesBottomSheetDialogFragment extends AppModesBottomSheetDialogFragment - implements ConfigureProfileMenuAdapter.ProfileSelectedListener { +public class ConfigureAppModesBottomSheetDialogFragment extends AppModesBottomSheetDialogFragment + implements ProfileSelectedListener { public static final String TAG = "ConfigureAppModesBottomSheetDialogFragment"; @@ -56,4 +60,15 @@ public class ConfigureAppModesBottomSheetDialogFragment extends AppModesBottomSh } ApplicationMode.changeProfileAvailability(item, isChecked, getMyApplication()); } + + public static void showInstance(@NonNull FragmentManager fragmentManager, boolean usedOnMap, UpdateMapRouteMenuListener listener) { + if (fragmentManager.findFragmentByTag(TAG) == null) { + ConfigureAppModesBottomSheetDialogFragment fragment = new ConfigureAppModesBottomSheetDialogFragment(); + fragment.setUsedOnMap(usedOnMap); + fragment.setUpdateMapRouteMenuListener(listener); + fragmentManager.beginTransaction() + .add(fragment, TAG) + .commitAllowingStateLoss(); + } + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java index a6b69ba124..83a866c49e 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java @@ -29,6 +29,8 @@ import androidx.appcompat.content.res.AppCompatResources; import androidx.appcompat.widget.AppCompatImageView; import androidx.core.content.ContextCompat; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; import androidx.transition.AutoTransition; import androidx.transition.Scene; import androidx.transition.Transition; @@ -71,7 +73,7 @@ import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenuFragment; import net.osmand.plus.mapmarkers.MapMarker; import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment; import net.osmand.plus.poi.PoiUIFilter; -import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment; +import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment.UpdateMapRouteMenuListener; import net.osmand.plus.profiles.ConfigureAppModesBottomSheetDialogFragment; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidPTTypesRoutingParameter; import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter; @@ -870,16 +872,16 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener } private void showProfileBottomSheetDialog() { - final AppModesBottomSheetDialogFragment fragment = new ConfigureAppModesBottomSheetDialogFragment(); - fragment.setUsedOnMap(true); - fragment.setUpdateMapRouteMenuListener(new AppModesBottomSheetDialogFragment.UpdateMapRouteMenuListener() { - @Override - public void updateAppModeMenu() { - updateApplicationModes(); - } - }); - getMapActivity().getSupportFragmentManager().beginTransaction() - .add(fragment, ConfigureAppModesBottomSheetDialogFragment.TAG).commitAllowingStateLoss(); + FragmentActivity activity = getMapActivity(); + if (activity != null) { + FragmentManager manager = activity.getSupportFragmentManager(); + ConfigureAppModesBottomSheetDialogFragment.showInstance(manager, true, new UpdateMapRouteMenuListener() { + @Override + public void updateAppModeMenu() { + updateApplicationModes(); + } + }); + } } private void updateApplicationMode(ApplicationMode mode, ApplicationMode next) {