From a0386129df212c00b33f7c584e42d0c3cd184ebc Mon Sep 17 00:00:00 2001 From: nazar-kutz Date: Fri, 12 Mar 2021 13:17:42 +0200 Subject: [PATCH] Don't show fragment name on back button, but return after back button was pressed --- .../net/osmand/plus/helpers/IntentHelper.java | 2 +- .../SelectedGpxMenuController.java | 2 +- .../controllers/WptPtMenuController.java | 2 +- .../plus/search/QuickSearchListFragment.java | 2 +- .../osmand/plus/track/TrackMenuFragment.java | 27 ++++++++++++++----- 5 files changed, 24 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java b/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java index 1d6f5dc862..f02b5b0961 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java @@ -259,7 +259,7 @@ public class IntentHelper { String path = intent.getStringExtra(TRACK_FILE_NAME); String name = intent.getStringExtra(RETURN_SCREEN_NAME); boolean currentRecording = intent.getBooleanExtra(CURRENT_RECORDING, false); - TrackMenuFragment.showInstance(mapActivity, path, currentRecording, null, name); + TrackMenuFragment.showInstance(mapActivity, path, currentRecording, null, name, null); mapActivity.setIntent(null); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java index 487689d22d..5fc74c9db9 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java @@ -47,7 +47,7 @@ public class SelectedGpxMenuController extends MenuController { LatLon latLon = new LatLon(wptPt.lat, wptPt.lon); SelectedGpxFile selectedGpxFile = selectedGpxPoint.getSelectedGpxFile(); String path = selectedGpxFile.getGpxFile().path; - TrackMenuFragment.showInstance(mapActivity, path, selectedGpxFile.isShowCurrentTrack(), latLon, null); + TrackMenuFragment.showInstance(mapActivity, path, selectedGpxFile.isShowCurrentTrack(), latLon, null, null); } }; leftTitleButtonController.caption = mapActivity.getString(R.string.shared_string_open_track); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java index 8442f93334..d9ad62cad9 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java @@ -50,7 +50,7 @@ public class WptPtMenuController extends MenuController { SelectedGpxFile selectedGpxFile = selectionHelper.getSelectedGPXFile(wpt); if (selectedGpxFile != null) { String path = selectedGpxFile.getGpxFile().path; - TrackMenuFragment.showInstance(mapActivity, path, selectedGpxFile.isShowCurrentTrack(), new LatLon(wpt.lon, wpt.lat), null); + TrackMenuFragment.showInstance(mapActivity, path, selectedGpxFile.isShowCurrentTrack(), new LatLon(wpt.lon, wpt.lat), null, null); } } } diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java index 410f011154..89e918284c 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java @@ -306,7 +306,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { SearchHistoryHelper.getInstance(app).addNewItemToHistory(gpxInfo); File file = new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), gpxInfo.getFileName()); String path = file.getAbsolutePath(); - TrackMenuFragment.showInstance(mapActivity, path, false, null, QuickSearchDialogFragment.TAG); + TrackMenuFragment.showInstance(mapActivity, path, false, null, null, QuickSearchDialogFragment.TAG); dialogFragment.dismiss(); } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 357ea3ba8a..bb738a8e00 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -154,6 +154,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card private String gpxTitle; private String returnScreenName; + private String callingFragmentTag; private TrackChartPoints trackChartPoints; private Float heading; @@ -272,7 +273,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card if (contextMenu.isActive() && contextMenu.getPointDescription() != null && contextMenu.getPointDescription().isGpxPoint()) { contextMenu.show(); - } else if (Algorithms.objectEquals(returnScreenName, QuickSearchDialogFragment.TAG)) { + } else if (Algorithms.objectEquals(callingFragmentTag, QuickSearchDialogFragment.TAG)) { mapActivity.showQuickSearch(ShowQuickSearchMode.CURRENT, false); } else { mapActivity.launchPrevActivityIntent(); @@ -311,6 +312,10 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card this.returnScreenName = returnScreenName; } + public void setCallingFragmentTag(String callingFragmentTag) { + this.callingFragmentTag = callingFragmentTag; + } + @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); @@ -1259,7 +1264,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card boolean currentRecording = file == null; String path = file != null ? file.getAbsolutePath() : null; if (context instanceof MapActivity) { - TrackMenuFragment.showInstance((MapActivity) context, path, currentRecording, null, null); + TrackMenuFragment.showInstance((MapActivity) context, path, currentRecording, null, null, null); } else { Bundle bundle = new Bundle(); bundle.putString(TRACK_FILE_NAME, path); @@ -1307,23 +1312,30 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } } - public static void showInstance(@NonNull MapActivity mapActivity, @Nullable String path, - boolean showCurrentTrack, @Nullable final LatLon latLon, @Nullable final String returnScreenName) { + public static void showInstance(@NonNull MapActivity mapActivity, + @Nullable String path, + boolean showCurrentTrack, + @Nullable final LatLon latLon, + @Nullable final String returnScreenName, + @Nullable final String callingFragmentTag) { final WeakReference mapActivityRef = new WeakReference<>(mapActivity); loadSelectedGpxFile(mapActivity, path, showCurrentTrack, new CallbackWithObject() { @Override public boolean processResult(SelectedGpxFile selectedGpxFile) { MapActivity mapActivity = mapActivityRef.get(); if (mapActivity != null && selectedGpxFile != null) { - showInstance(mapActivity, selectedGpxFile, latLon, returnScreenName); + showInstance(mapActivity, selectedGpxFile, latLon, returnScreenName, callingFragmentTag); } return true; } }); } - public static boolean showInstance(@NonNull MapActivity mapActivity, @NonNull SelectedGpxFile selectedGpxFile, - @Nullable LatLon latLon, @Nullable String returnScreenName) { + public static boolean showInstance(@NonNull MapActivity mapActivity, + @NonNull SelectedGpxFile selectedGpxFile, + @Nullable LatLon latLon, + @Nullable String returnScreenName, + @Nullable String callingFragmentTag) { try { Bundle args = new Bundle(); args.putInt(ContextMenuFragment.MENU_STATE_KEY, MenuState.HEADER_ONLY); @@ -1333,6 +1345,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card fragment.setRetainInstance(true); fragment.setSelectedGpxFile(selectedGpxFile); fragment.setReturnScreenName(returnScreenName); + fragment.setCallingFragmentTag(callingFragmentTag); if (latLon != null) { fragment.setLatLon(latLon);