diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index 3f012d4bce..1bce00c0ab 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -51,7 +51,7 @@ import net.osmand.plus.base.OsmandExpandableListFragment; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.FontCache; import net.osmand.plus.myplaces.FavoritesActivity; -import net.osmand.plus.myplaces.FavoritesActivity.FavoritesFragmentStateHolder; +import net.osmand.plus.myplaces.FavoritesFragmentStateHolder; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -94,6 +94,9 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen private HashMap> preferenceCache = new HashMap<>(); private View footerView; + private int selectedGroupPos = -1; + private int selectedChildPos = -1; + private FavoritesListener favoritesListener; String groupNameToShow = null; @@ -700,34 +703,37 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen } public void showOnMap(final FavouritePoint point, int groupPos, int childPos) { - getMyApplication().getSettings().FAVORITES_TAB.set(FavoritesActivity.FAV_TAB); - - final OsmandSettings settings = getMyApplication().getSettings(); + OsmandSettings settings = requireMyApplication().getSettings(); + settings.FAVORITES_TAB.set(FAV_TAB); + selectedGroupPos = groupPos; + selectedChildPos = childPos; LatLon location = new LatLon(point.getLatitude(), point.getLongitude()); - settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), - settings.getLastKnownMapZoom(), - new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()), - true, - point); //$NON-NLS-1$ - Bundle b = new Bundle(); - b.putInt(GROUP_POSITION, groupPos); - b.putInt(ITEM_POSITION, childPos); - MapActivity.launchMapActivityMoveToTop(getActivity(), storeState(b)); + FavoritesActivity.showOnMap(requireActivity(), this, location.getLatitude(), location.getLongitude(), + settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()), true, point); } @Override - public Bundle storeState(Bundle bundle) { - bundle.putInt(FavoritesActivity.TAB_ID, FavoritesActivity.FAV_TAB); + public Bundle storeState() { + Bundle bundle = new Bundle(); + bundle.putInt(TAB_ID, FAV_TAB); + if (selectedGroupPos != -1) { + bundle.putInt(GROUP_POSITION, selectedGroupPos); + } + if (selectedChildPos != -1) { + bundle.putInt(ITEM_POSITION, selectedChildPos); + } return bundle; } @Override public void restoreState(Bundle bundle) { if (bundle != null && bundle.containsKey(TAB_ID) && bundle.containsKey(ITEM_POSITION)) { - if (bundle.getInt(TAB_ID, 0) == FAV_TAB) { - int group = bundle.getInt(GROUP_POSITION, 0); - int child = bundle.getInt(ITEM_POSITION, 0); - listView.setSelectedChild(group, child, true); + if (bundle.getInt(TAB_ID) == FAV_TAB) { + selectedGroupPos = bundle.getInt(GROUP_POSITION, -1); + selectedChildPos = bundle.getInt(ITEM_POSITION, -1); + if (selectedGroupPos != -1 && selectedChildPos != -1) { + listView.setSelectedChild(selectedGroupPos, selectedChildPos, true); + } } } } diff --git a/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java b/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java index 5ffba1f49b..1593ce3338 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/NotesFragment.java @@ -1,8 +1,5 @@ package net.osmand.plus.audionotes; -import static net.osmand.plus.myplaces.FavoritesActivity.NOTES_TAB; -import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID; - import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -30,17 +27,16 @@ import android.widget.ListView; import android.widget.Toast; import net.osmand.AndroidUtils; -import net.osmand.PlatformUtil; -import net.osmand.data.PointDescription; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.WptPt; +import net.osmand.PlatformUtil; +import net.osmand.data.PointDescription; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings.NotesSortByMode; import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.activities.ActionBarProgressActivity; -import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.OsmandActionBarActivity; import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording; import net.osmand.plus.audionotes.ItemMenuBottomSheetDialogFragment.ItemMenuFragmentListener; @@ -50,8 +46,8 @@ import net.osmand.plus.audionotes.adapters.NotesAdapter.NotesAdapterListener; import net.osmand.plus.base.OsmAndListFragment; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.myplaces.FavoritesActivity; +import net.osmand.plus.myplaces.FavoritesFragmentStateHolder; -import net.osmand.plus.myplaces.FavoritesActivity.FavoritesFragmentStateHolder; import org.apache.commons.logging.Log; import java.io.File; @@ -64,6 +60,9 @@ import java.util.LinkedList; import java.util.List; import java.util.Set; +import static net.osmand.plus.audionotes.AudioVideoNotesPlugin.NOTES_TAB; +import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID; + public class NotesFragment extends OsmAndListFragment implements FavoritesFragmentStateHolder { public static final Recording SHARE_LOCATION_FILE = new Recording(new File(".")); @@ -80,6 +79,7 @@ public class NotesFragment extends OsmAndListFragment implements FavoritesFragme private View emptyView; private boolean selectionMode; + private int selectedItemPosition = -1; private ActionMode actionMode; @@ -571,12 +571,10 @@ public class NotesFragment extends OsmAndListFragment implements FavoritesFragme } private void showOnMap(Recording recording, int itemPosition) { - getMyApplication().getSettings().setMapLocationToShow(recording.getLatitude(), recording.getLongitude(), 15, + selectedItemPosition = itemPosition; + FavoritesActivity.showOnMap(requireActivity(), this, recording.getLatitude(), recording.getLongitude(), 15, new PointDescription(recording.getSearchHistoryType(), recording.getName(getActivity(), true)), true, recording); - Bundle b = new Bundle(); - b.putInt(ITEM_POSITION, itemPosition); - MapActivity.launchMapActivityMoveToTop(getActivity(), storeState(b)); } private void editNote(final Recording recording) { @@ -617,24 +615,28 @@ public class NotesFragment extends OsmAndListFragment implements FavoritesFragme } @Override - public Bundle storeState(Bundle bundle) { + public Bundle storeState() { + Bundle bundle = new Bundle(); bundle.putInt(TAB_ID, NOTES_TAB); + bundle.putInt(ITEM_POSITION, selectedItemPosition); return bundle; } @Override public void restoreState(Bundle bundle) { if (bundle != null && bundle.containsKey(TAB_ID) && bundle.containsKey(ITEM_POSITION)) { - if (bundle.getInt(TAB_ID, 0) == NOTES_TAB) { - int position= bundle.getInt(ITEM_POSITION, 0); - int itemsCount = getListView().getAdapter().getCount(); - if (itemsCount > 0 && itemsCount > position) { - if (position == 1) { - getListView().setSelection(0); - } else { - getListView().setSelection(position); + if (bundle.getInt(TAB_ID) == NOTES_TAB) { + selectedItemPosition = bundle.getInt(ITEM_POSITION, -1); + if (selectedItemPosition != -1) { + int itemsCount = getListView().getAdapter().getCount(); + if (itemsCount > 0 && itemsCount > selectedItemPosition) { + if (selectedItemPosition == 1) { + getListView().setSelection(0); + } else { + getListView().setSelection(selectedItemPosition); + } } - } + } } } } diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index f0c717288f..b0e71828d6 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -69,6 +69,10 @@ import java.util.List; import java.util.Locale; import java.util.zip.ZipInputStream; +import static net.osmand.plus.myplaces.FavoritesActivity.FAV_TAB; +import static net.osmand.plus.myplaces.FavoritesActivity.GPX_TAB; +import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID; + /** * @author Koen Rabaey */ @@ -295,7 +299,7 @@ public class ImportHelper { final Intent newIntent = new Intent(activity, app.getAppCustomization().getFavoritesActivity()); newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - newIntent.putExtra(FavoritesActivity.TAB_ID, FavoritesActivity.FAV_TAB); + newIntent.putExtra(TAB_ID, FAV_TAB); activity.startActivity(newIntent); } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); @@ -596,7 +600,7 @@ public class ImportHelper { if (forceImportFavourites) { final Intent newIntent = new Intent(activity, app.getAppCustomization().getFavoritesActivity()); newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); - newIntent.putExtra(FavoritesActivity.TAB_ID, FavoritesActivity.GPX_TAB); + newIntent.putExtra(TAB_ID, GPX_TAB); activity.startActivity(newIntent); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java index 20cd85703b..36c759e726 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java @@ -1,9 +1,7 @@ package net.osmand.plus.mapcontextmenu.builders; import android.content.Context; -import android.content.Intent; import android.graphics.Color; -import android.os.Bundle; import android.support.annotation.NonNull; import android.text.TextUtils; import android.view.Gravity; @@ -23,12 +21,10 @@ import net.osmand.data.QuadRect; import net.osmand.data.TransportStop; import net.osmand.osm.PoiCategory; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; -import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.myplaces.FavoritesActivity; -import net.osmand.plus.myplaces.FavoritesActivity.FavoritesFragmentStateHolder; import net.osmand.plus.widgets.TextViewEx; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -258,13 +254,7 @@ public class FavouritePointMenuBuilder extends MenuBuilder { button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - OsmAndAppCustomization appCustomization = app.getAppCustomization(); - final Intent intent = new Intent(context, appCustomization.getFavoritesActivity()); - Bundle b = new Bundle(); - b.putInt(FavoritesActivity.TAB_ID, FavoritesActivity.FAV_TAB); - b.putString(FavoritesFragmentStateHolder.GROUP_NAME_TO_SHOW, group.name); - intent.putExtra(MapActivity.INTENT_PARAMS, b); - context.startActivity(intent); + FavoritesActivity.openFavoritesGroup(context, group.name); } }); view.addView(button); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index a2dacad371..31bf7e806d 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -79,7 +79,6 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; -import net.osmand.plus.myplaces.FavoritesActivity.FavoritesFragmentStateHolder; import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.util.Algorithms; @@ -102,6 +101,9 @@ import java.util.Map; import java.util.Set; import java.util.regex.Pattern; +import static net.osmand.plus.myplaces.FavoritesActivity.GPX_TAB; +import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID; + public class AvailableGPXFragment extends OsmandExpandableListFragment implements FavoritesFragmentStateHolder { @@ -710,12 +712,13 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement boolean e = true; if (info.gpx != null) { WptPt loc = info.gpx.findPointToShow(); - OsmandSettings settings = getMyApplication().getSettings(); + OsmandApplication app = requireMyApplication(); + OsmandSettings settings = app.getSettings(); if (loc != null) { settings.setMapLocationToShow(loc.lat, loc.lon, settings.getLastKnownMapZoom()); e = false; - getMyApplication().getSelectedGpxHelper().setGpxFileToDisplay(info.gpx); - MapActivity.launchMapActivityMoveToTop(getActivity(), storeState(new Bundle())); + app.getSelectedGpxHelper().setGpxFileToDisplay(info.gpx); + MapActivity.launchMapActivityMoveToTop(getActivity(), storeState()); } } if (e) { @@ -865,8 +868,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement } @Override - public Bundle storeState(Bundle bundle) { - bundle.putInt(FavoritesActivity.TAB_ID, FavoritesActivity.GPX_TAB); + public Bundle storeState() { + Bundle bundle = new Bundle(); + bundle.putInt(TAB_ID, GPX_TAB); return bundle; } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java b/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java index 227c550c8d..c7fe62a201 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/FavoritesActivity.java @@ -1,14 +1,14 @@ -/** - * - */ package net.osmand.plus.myplaces; import android.app.Activity; +import android.content.Context; import android.content.Intent; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v4.view.ViewPager; import android.support.v7.widget.SearchView; @@ -18,6 +18,8 @@ import android.text.style.ImageSpan; import android.view.MenuItem; import android.widget.ImageView; +import net.osmand.data.PointDescription; +import net.osmand.plus.OsmAndAppCustomization; import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; @@ -41,52 +43,44 @@ public class FavoritesActivity extends TabActivity { private static final int OPEN_GPX_DOCUMENT_REQUEST = 1006; private static final int IMPORT_FAVOURITES_REQUEST = 1007; - - public static final String TAB_ID = "selected_tab_id"; - public static final int GPX_TAB = R.string.shared_string_tracks; public static final int FAV_TAB = R.string.shared_string_my_favorites; - public static final int NOTES_TAB = R.string.notes; - public static final int OSM_TAB = R.string.osm_edits; protected List> fragList = new ArrayList<>(); private int tabSize; private ImportHelper importHelper; - private List mTabs; private Bundle intentParams = null; @Override - public void onCreate(Bundle icicle) { + public void onCreate(Bundle savedInstanceState) { OsmandApplication app = (OsmandApplication) getApplication(); app.applyTheme(this); - super.onCreate(icicle); + super.onCreate(savedInstanceState); app.logEvent("myplaces_open"); - importHelper = new ImportHelper(this, getMyApplication(), null); //noinspection ConstantConditions getSupportActionBar().setTitle(R.string.shared_string_my_places); getSupportActionBar().setElevation(0); - setContentView(R.layout.tab_content); - mTabs = getTabItems(); + List mTabs = getTabItems(); setTabs(mTabs); ViewPager mViewPager = (ViewPager) findViewById(R.id.pager); - if (icicle == null) { + if (savedInstanceState == null) { Intent intent = getIntent(); if (intent != null && intent.hasExtra(MapActivity.INTENT_PARAMS)) { intentParams = intent.getBundleExtra(MapActivity.INTENT_PARAMS); int tabId = intentParams.getInt(TAB_ID, FAV_TAB); int pagerItem = 0; for (int n = 0; n < mTabs.size(); n++) { - if (mTabs.get(n).mTitle.equals(getString(tabId))) { + if (mTabs.get(n).resId == tabId) { pagerItem = n; break; } @@ -192,20 +186,7 @@ public class FavoritesActivity extends TabActivity { @Override public void onAttachFragment(Fragment fragment) { if (fragment instanceof FavoritesFragmentStateHolder) { - if (intentParams != null && intentParams.getInt(TAB_ID, -1) != -1) { - Bundle b = new Bundle(); - int tabId = intentParams.getInt(TAB_ID, FAV_TAB); - b.putInt(TAB_ID, intentParams.getInt(TAB_ID, FAV_TAB)); - if (tabId == FAV_TAB) { - b.putString(FavoritesFragmentStateHolder.GROUP_NAME_TO_SHOW, - intentParams.getString(FavoritesFragmentStateHolder.GROUP_NAME_TO_SHOW)); - b.putInt(FavoritesFragmentStateHolder.GROUP_POSITION, intentParams.getInt( - FavoritesFragmentStateHolder.GROUP_POSITION, 0)); - } - b.putInt(FavoritesFragmentStateHolder.ITEM_POSITION, - intentParams.getInt(FavoritesFragmentStateHolder.ITEM_POSITION, 0)); - fragment.setArguments(b); - } + fragment.setArguments(intentParams); fragList.add(new WeakReference<>((FavoritesFragmentStateHolder) fragment)); } } @@ -213,8 +194,8 @@ public class FavoritesActivity extends TabActivity { @Override protected void onResume() { super.onResume(); - mTabs = getTabItems(); - if(mTabs.size() != tabSize ) { + List mTabs = getTabItems(); + if (mTabs.size() != tabSize) { setTabs(mTabs); } } @@ -230,11 +211,9 @@ public class FavoritesActivity extends TabActivity { @Override public boolean onOptionsItemSelected(MenuItem item) { int itemId = item.getItemId(); - switch (itemId) { - case android.R.id.home: + if (itemId == android.R.id.home) { finish(); return true; - } return false; } @@ -261,21 +240,29 @@ public class FavoritesActivity extends TabActivity { stopHint.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); searchEdit.setHint(stopHint); } catch (Exception e) { - e.printStackTrace(); + // ignore } } - public interface FavoritesFragmentStateHolder { + public static void showOnMap(@NonNull Activity activity, @Nullable FavoritesFragmentStateHolder fragment, double latitude, double longitude, int zoom, PointDescription pointDescription, + boolean addToHistory, Object toShow) { + OsmandApplication app = (OsmandApplication) activity.getApplication(); + app.getSettings().setMapLocationToShow(latitude, longitude, zoom, pointDescription, addToHistory, toShow); + if (fragment != null) { + MapActivity.launchMapActivityMoveToTop(activity, fragment.storeState()); + } else { + MapActivity.launchMapActivityMoveToTop(activity); + } + } - String ITEM_POSITION = "item_position"; - - String GROUP_POSITION = "group_position"; - - String GROUP_NAME_TO_SHOW = "group_name_to_show"; - - Bundle storeState(Bundle bundle); - - void restoreState(Bundle bundle); + public static void openFavoritesGroup(Context context, String groupName) { + OsmAndAppCustomization appCustomization = ((OsmandApplication) context.getApplicationContext()).getAppCustomization(); + Intent intent = new Intent(context, appCustomization.getFavoritesActivity()); + Bundle b = new Bundle(); + b.putInt(TAB_ID, FAV_TAB); + b.putString(FavoritesFragmentStateHolder.GROUP_NAME_TO_SHOW, groupName); + intent.putExtra(MapActivity.INTENT_PARAMS, b); + context.startActivity(intent); } } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/FavoritesFragmentStateHolder.java b/OsmAnd/src/net/osmand/plus/myplaces/FavoritesFragmentStateHolder.java new file mode 100644 index 0000000000..5db58c1663 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/myplaces/FavoritesFragmentStateHolder.java @@ -0,0 +1,13 @@ +package net.osmand.plus.myplaces; + +import android.os.Bundle; + +public interface FavoritesFragmentStateHolder { + String ITEM_POSITION = "item_position"; + String GROUP_POSITION = "group_position"; + String GROUP_NAME_TO_SHOW = "group_name_to_show"; + + Bundle storeState(); + + void restoreState(Bundle bundle); +} diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index 8a39857514..a2d18d0c7d 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -57,6 +57,7 @@ import static net.osmand.plus.OsmAndCustomizationConstants.OSM_NOTES; public class OsmEditingPlugin extends OsmandPlugin { private static final Log LOG = PlatformUtil.getLog(OsmEditingPlugin.class); + public static final int OSM_EDIT_TAB = R.string.osm_edits; private static final String ID = "osm.editing"; // Constants for determining the order of items in the additional actions context menu diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index 8cf9ee8ceb..5db9fee0fc 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -1,8 +1,5 @@ package net.osmand.plus.osmedit; -import static net.osmand.plus.myplaces.FavoritesActivity.OSM_TAB; -import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID; - import android.app.Dialog; import android.app.ProgressDialog; import android.content.DialogInterface; @@ -33,12 +30,12 @@ import android.widget.TextView; import android.widget.Toast; import net.osmand.AndroidUtils; -import net.osmand.data.PointDescription; -import net.osmand.osm.edit.Entity; -import net.osmand.osm.edit.Node; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.WptPt; +import net.osmand.data.PointDescription; +import net.osmand.osm.edit.Entity; +import net.osmand.osm.edit.Node; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; @@ -51,7 +48,7 @@ import net.osmand.plus.base.OsmAndListFragment; import net.osmand.plus.dialogs.ProgressDialogFragment; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.myplaces.FavoritesActivity; -import net.osmand.plus.myplaces.FavoritesActivity.FavoritesFragmentStateHolder; +import net.osmand.plus.myplaces.FavoritesFragmentStateHolder; import net.osmand.plus.osmedit.ExportOptionsBottomSheetDialogFragment.ExportOptionsFragmentListener; import net.osmand.plus.osmedit.FileTypeBottomSheetDialogFragment.FileTypeFragmentListener; import net.osmand.plus.osmedit.OsmEditOptionsBottomSheetDialogFragment.OsmEditOptionsFragmentListener; @@ -72,6 +69,9 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID; +import static net.osmand.plus.osmedit.OsmEditingPlugin.OSM_EDIT_TAB; + public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialogFragment.ProgressDialogPoiUploader, OpenstreetmapLocalUtil.OnNodeCommittedListener, FavoritesFragmentStateHolder { @@ -108,6 +108,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo private ActionMode actionMode; private long refreshId; + private int selectedItemPosition = -1; private int exportType; @@ -648,14 +649,12 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo } private void showOnMap(OsmPoint osmPoint, int itemPosition) { + selectedItemPosition = itemPosition; boolean isOsmPoint = osmPoint instanceof OpenstreetmapPoint; String type = osmPoint.getGroup() == Group.POI ? PointDescription.POINT_TYPE_POI : PointDescription.POINT_TYPE_OSM_BUG; String name = (isOsmPoint ? ((OpenstreetmapPoint) osmPoint).getName() : ((OsmNotesPoint) osmPoint).getText()); - getMyApplication().getSettings().setMapLocationToShow(osmPoint.getLatitude(), osmPoint.getLongitude(), 15, - new PointDescription(type, name), true, osmPoint); //$NON-NLS-1$ - Bundle b = new Bundle(); - b.putInt(ITEM_POSITION, itemPosition); - MapActivity.launchMapActivityMoveToTop(getActivity(), storeState(b)); + FavoritesActivity.showOnMap(requireActivity(), this, osmPoint.getLatitude(), osmPoint.getLongitude(), 15, + new PointDescription(type, name), true, osmPoint); } private void deletePoint(OsmPoint osmPoint) { @@ -902,23 +901,27 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo } @Override - public Bundle storeState(Bundle bundle) { - bundle.putInt(TAB_ID, OSM_TAB); + public Bundle storeState() { + Bundle bundle = new Bundle(); + bundle.putInt(TAB_ID, OSM_EDIT_TAB); + bundle.putInt(ITEM_POSITION, selectedItemPosition); return bundle; } public void restoreState(Bundle bundle) { if (bundle != null && bundle.containsKey(TAB_ID) && bundle.containsKey(ITEM_POSITION)) { - if (bundle.getInt(TAB_ID, 0) == OSM_TAB) { - int position= bundle.getInt(ITEM_POSITION, 0); - int itemsCount = getListView().getAdapter().getCount(); - if (itemsCount > 0 && itemsCount > position) { - if (position == 1) { - getListView().setSelection(0); - } else { - getListView().setSelection(position); + if (bundle.getInt(TAB_ID) == OSM_EDIT_TAB) { + selectedItemPosition = bundle.getInt(ITEM_POSITION, -1); + if (selectedItemPosition != -1) { + int itemsCount = getListView().getAdapter().getCount(); + if (itemsCount > 0 && itemsCount > selectedItemPosition) { + if (selectedItemPosition == 1) { + getListView().setSelection(0); + } else { + getListView().setSelection(selectedItemPosition); + } } - } + } } } }