diff --git a/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java b/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java index 7f3a9ca30c..a7d6dd7f79 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/IntentHelper.java @@ -21,7 +21,6 @@ import net.osmand.plus.activities.PluginsFragment; import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; import net.osmand.plus.mapmarkers.MapMarkersDialogFragment; import net.osmand.plus.mapsource.EditMapSourceDialogFragment; -import net.osmand.plus.osmedit.OsmEditingFragment; import net.osmand.plus.search.QuickSearchDialogFragment; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; @@ -235,13 +234,6 @@ public class IntentHelper { } mapActivity.setIntent(null); } - if (intent.hasExtra(OsmEditingFragment.OPEN_PLUGIN)) { - boolean openPlugins = intent.getBooleanExtra(OsmEditingFragment.OPEN_PLUGIN, false); - if (openPlugins) { - OsmEditingFragment.showInstance(mapActivity.getSupportFragmentManager()); - } - mapActivity.setIntent(null); - } if (intent.hasExtra(BaseSettingsFragment.OPEN_CONFIG_ON_MAP)) { switch (intent.getStringExtra(BaseSettingsFragment.OPEN_CONFIG_ON_MAP)) { case BaseSettingsFragment.MAP_CONFIG: diff --git a/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java b/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java index c77cfbfc0d..43e1e73cc8 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java @@ -60,6 +60,8 @@ public class FavoritesActivity extends TabActivity { private int tabSize; private ImportHelper importHelper; + private ViewPager viewPager; + private Bundle intentParams = null; @Override @@ -80,7 +82,7 @@ public class FavoritesActivity extends TabActivity { List mTabs = getTabItems(); setTabs(mTabs); - ViewPager mViewPager = (ViewPager) findViewById(R.id.pager); + viewPager = findViewById(R.id.pager); if (savedInstanceState == null) { Intent intent = getIntent(); if (intent != null && intent.hasExtra(MapActivity.INTENT_PARAMS)) { @@ -93,7 +95,7 @@ public class FavoritesActivity extends TabActivity { break; } } - mViewPager.setCurrentItem(pagerItem, false); + viewPager.setCurrentItem(pagerItem, false); } } } @@ -191,6 +193,17 @@ public class FavoritesActivity extends TabActivity { return mTabs; } + public Bundle storeCurrentState() { + int currentItem = viewPager.getCurrentItem(); + if (currentItem >= 0 && currentItem < fragList.size()) { + FavoritesFragmentStateHolder stateHolder = fragList.get(currentItem).get(); + if (stateHolder != null) { + return stateHolder.storeState(); + } + } + return null; + } + @Override public void onAttachFragment(Fragment fragment) { if (fragment instanceof FavoritesFragmentStateHolder) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java index ad066bcb39..c590f80b95 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingFragment.java @@ -9,6 +9,8 @@ import android.view.LayoutInflater; import android.view.View; import android.widget.TextView; +import androidx.activity.OnBackPressedCallback; +import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import androidx.preference.Preference; import androidx.preference.PreferenceViewHolder; @@ -37,11 +39,8 @@ import static net.osmand.plus.osmedit.OsmEditingPlugin.OSM_EDIT_TAB; public class OsmEditingFragment extends BaseSettingsFragment implements OnPreferenceChanged, ValidateOsmLoginListener, OsmAuthorizationListener { - public static final String TAG = OsmEditingFragment.class.getName(); - private static final Log log = PlatformUtil.getLog(OsmEditingFragment.class); - public static final String OPEN_PLUGIN = "open_plugins"; private static final String OSM_LOGOUT = "osm_logout"; private static final String OPEN_OSM_EDITS = "open_osm_edits"; public static final String OSM_LOGIN_DATA = "osm_login_data"; @@ -53,6 +52,17 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); authorizationAdapter = app.getOsmOAuthHelper().getAuthorizationAdapter(); + + FragmentActivity activity = requireMyActivity(); + activity.getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) { + public void handleOnBackPressed() { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.launchPrevActivityIntent(); + } + dismiss(); + } + }); } @Override @@ -200,17 +210,4 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer public void authorizationCompleted() { updateAllSettings(); } - - public static boolean showInstance(FragmentManager fragmentManager) { - try { - OsmEditingFragment fragment = new OsmEditingFragment(); - fragmentManager.beginTransaction() - .add(R.id.fragmentContainer, fragment, TAG) - .addToBackStack(TAG) - .commitAllowingStateLoss(); - return true; - } catch (Exception e) { - return false; - } - } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java index 9a3209fdc3..ed982747b0 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendGpxBottomSheetFragment.java @@ -1,7 +1,5 @@ package net.osmand.plus.osmedit.dialogs; -import android.content.Context; -import android.content.Intent; import android.os.AsyncTask; import android.os.Bundle; import android.text.Editable; @@ -31,16 +29,19 @@ import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionAdapterListener; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionItem; import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo; -import net.osmand.plus.osmedit.OsmEditingFragment; +import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin.UploadVisibility; import net.osmand.plus.osmedit.UploadGPXFilesTask; import net.osmand.plus.settings.backend.OsmandSettings; +import net.osmand.plus.settings.fragments.BaseSettingsFragment; import net.osmand.util.Algorithms; import java.util.ArrayList; import java.util.List; +import static net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenType.OPEN_STREET_MAP_EDITING; + public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { public static final String TAG = SendGpxBottomSheetFragment.class.getSimpleName(); @@ -105,8 +106,11 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { account.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + FragmentActivity activity = getActivity(); + if (activity != null) { + showOpenStreetMapScreen(activity); + } dismiss(); - showOpenStreetMapScreen(); } }); RecyclerView iconCategoriesRecyclerView = sendOsmPoiView.findViewById(R.id.description_view); @@ -120,12 +124,21 @@ public class SendGpxBottomSheetFragment extends MenuBottomSheetDialogFragment { items.add(titleItem); } - private void showOpenStreetMapScreen() { - Bundle params = new Bundle(); - params.putBoolean(OsmEditingFragment.OPEN_PLUGIN, true); - Context context = getView().getContext(); - Intent intent = getActivity().getIntent(); - MapActivity.launchMapActivityMoveToTop(context, intent != null ? intent.getExtras() : null, null, params); + protected static void showOpenStreetMapScreen(@NonNull FragmentActivity activity) { + if (activity instanceof MapActivity) { + BaseSettingsFragment.showInstance(activity, OPEN_STREET_MAP_EDITING); + } else { + Bundle prevIntentParams = null; + if (activity instanceof FavoritesActivity) { + prevIntentParams = ((FavoritesActivity) activity).storeCurrentState(); + } else if (activity.getIntent() != null) { + prevIntentParams = activity.getIntent().getExtras(); + } + Bundle params = new Bundle(); + params.putString(BaseSettingsFragment.OPEN_SETTINGS, OPEN_STREET_MAP_EDITING.name()); + + MapActivity.launchMapActivityMoveToTop(activity, prevIntentParams, null, params); + } } @Override diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java index 8e8e37934c..d26c1ac212 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendOsmNoteBottomSheetFragment.java @@ -1,8 +1,6 @@ package net.osmand.plus.osmedit.dialogs; import android.app.Activity; -import android.content.Context; -import android.content.Intent; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.ContextThemeWrapper; @@ -16,6 +14,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.widget.SwitchCompat; import androidx.fragment.app.Fragment; +import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import com.google.android.material.textfield.TextInputLayout; @@ -29,7 +28,6 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; -import net.osmand.plus.osmedit.OsmEditingFragment; import net.osmand.plus.osmedit.OsmNotesPoint; import net.osmand.plus.osmedit.OsmPoint; import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter; @@ -43,6 +41,7 @@ import org.apache.commons.logging.Log; import static net.osmand.plus.UiUtilities.setupDialogButton; import static net.osmand.plus.osmedit.OsmEditingFragment.OSM_LOGIN_DATA; import static net.osmand.plus.osmedit.ValidateOsmLoginDetailsTask.ValidateOsmLoginListener; +import static net.osmand.plus.osmedit.dialogs.SendGpxBottomSheetFragment.showOpenStreetMapScreen; import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.OPENSTREETMAP_POINT; import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.ProgressDialogPoiUploader; import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.SimpleProgressDialogPoiUploader; @@ -136,8 +135,11 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen account.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + FragmentActivity activity = getActivity(); + if (activity != null) { + showOpenStreetMapScreen(activity); + } dismiss(); - showOpenStreetMapScreen(); } }); final SimpleBottomSheetItem bottomSheetItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() @@ -184,14 +186,6 @@ public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragmen } } - private void showOpenStreetMapScreen() { - Bundle params = new Bundle(); - params.putBoolean(OsmEditingFragment.OPEN_PLUGIN, true); - Context context = getView().getContext(); - Intent intent = getActivity().getIntent(); - MapActivity.launchMapActivityMoveToTop(context, intent != null ? intent.getExtras() : null, null, params); - } - @Override protected DialogButtonType getRightBottomButtonType() { return (DialogButtonType.PRIMARY); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java index af4c92d4b9..42ba887996 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiBottomSheetFragment.java @@ -1,8 +1,6 @@ package net.osmand.plus.osmedit.dialogs; import android.app.Activity; -import android.content.Context; -import android.content.Intent; import android.os.Bundle; import android.view.ContextThemeWrapper; import android.view.View; @@ -13,6 +11,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.widget.SwitchCompat; +import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import net.osmand.PlatformUtil; @@ -25,7 +24,6 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.osmedit.OpenstreetmapPoint; -import net.osmand.plus.osmedit.OsmEditingFragment; import net.osmand.plus.osmedit.OsmPoint; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.util.Algorithms; @@ -35,7 +33,10 @@ import org.apache.commons.logging.Log; import java.util.HashMap; import java.util.Map; -import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.*; +import static net.osmand.plus.osmedit.dialogs.SendGpxBottomSheetFragment.showOpenStreetMapScreen; +import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.OPENSTREETMAP_POINT; +import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.ProgressDialogPoiUploader; +import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.SimpleProgressDialogPoiUploader; public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { @@ -92,8 +93,11 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { account.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + FragmentActivity activity = getActivity(); + if (activity != null) { + showOpenStreetMapScreen(activity); + } dismiss(); - showOpenStreetMapScreen(); } }); final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder() @@ -102,14 +106,6 @@ public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment { items.add(titleItem); } - private void showOpenStreetMapScreen() { - Bundle params = new Bundle(); - params.putBoolean(OsmEditingFragment.OPEN_PLUGIN, true); - Context context = getView().getContext(); - Intent intent = getActivity().getIntent(); - MapActivity.launchMapActivityMoveToTop(context, intent != null ? intent.getExtras() : null, null, params); - } - public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points) { try { if (!fm.isStateSaved()) {