Fix restore my places request

This commit is contained in:
crimean 2019-06-26 16:55:48 +03:00
parent 388b3103cd
commit bd3f1a1a73
9 changed files with 138 additions and 128 deletions

View file

@ -51,7 +51,7 @@ import net.osmand.plus.base.OsmandExpandableListFragment;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.FontCache; import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.myplaces.FavoritesActivity; 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.Algorithms;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
@ -94,6 +94,9 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
private HashMap<String, OsmandSettings.OsmandPreference<Boolean>> preferenceCache = new HashMap<>(); private HashMap<String, OsmandSettings.OsmandPreference<Boolean>> preferenceCache = new HashMap<>();
private View footerView; private View footerView;
private int selectedGroupPos = -1;
private int selectedChildPos = -1;
private FavoritesListener favoritesListener; private FavoritesListener favoritesListener;
String groupNameToShow = null; String groupNameToShow = null;
@ -700,34 +703,37 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen
} }
public void showOnMap(final FavouritePoint point, int groupPos, int childPos) { public void showOnMap(final FavouritePoint point, int groupPos, int childPos) {
getMyApplication().getSettings().FAVORITES_TAB.set(FavoritesActivity.FAV_TAB); OsmandSettings settings = requireMyApplication().getSettings();
settings.FAVORITES_TAB.set(FAV_TAB);
final OsmandSettings settings = getMyApplication().getSettings(); selectedGroupPos = groupPos;
selectedChildPos = childPos;
LatLon location = new LatLon(point.getLatitude(), point.getLongitude()); LatLon location = new LatLon(point.getLatitude(), point.getLongitude());
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), FavoritesActivity.showOnMap(requireActivity(), this, location.getLatitude(), location.getLongitude(),
settings.getLastKnownMapZoom(), settings.getLastKnownMapZoom(), new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()), true, point);
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));
} }
@Override @Override
public Bundle storeState(Bundle bundle) { public Bundle storeState() {
bundle.putInt(FavoritesActivity.TAB_ID, FavoritesActivity.FAV_TAB); 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; return bundle;
} }
@Override @Override
public void restoreState(Bundle bundle) { public void restoreState(Bundle bundle) {
if (bundle != null && bundle.containsKey(TAB_ID) && bundle.containsKey(ITEM_POSITION)) { if (bundle != null && bundle.containsKey(TAB_ID) && bundle.containsKey(ITEM_POSITION)) {
if (bundle.getInt(TAB_ID, 0) == FAV_TAB) { if (bundle.getInt(TAB_ID) == FAV_TAB) {
int group = bundle.getInt(GROUP_POSITION, 0); selectedGroupPos = bundle.getInt(GROUP_POSITION, -1);
int child = bundle.getInt(ITEM_POSITION, 0); selectedChildPos = bundle.getInt(ITEM_POSITION, -1);
listView.setSelectedChild(group, child, true); if (selectedGroupPos != -1 && selectedChildPos != -1) {
listView.setSelectedChild(selectedGroupPos, selectedChildPos, true);
}
} }
} }
} }

View file

@ -1,8 +1,5 @@
package net.osmand.plus.audionotes; 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.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
@ -30,17 +27,16 @@ import android.widget.ListView;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.data.PointDescription;
import net.osmand.GPXUtilities; import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt; import net.osmand.GPXUtilities.WptPt;
import net.osmand.PlatformUtil;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings.NotesSortByMode; import net.osmand.plus.OsmandSettings.NotesSortByMode;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.activities.ActionBarProgressActivity; import net.osmand.plus.activities.ActionBarProgressActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandActionBarActivity; import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording; import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording;
import net.osmand.plus.audionotes.ItemMenuBottomSheetDialogFragment.ItemMenuFragmentListener; 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.base.OsmAndListFragment;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.myplaces.FavoritesActivity; 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 org.apache.commons.logging.Log;
import java.io.File; import java.io.File;
@ -64,6 +60,9 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Set; 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 class NotesFragment extends OsmAndListFragment implements FavoritesFragmentStateHolder {
public static final Recording SHARE_LOCATION_FILE = new Recording(new File(".")); 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 View emptyView;
private boolean selectionMode; private boolean selectionMode;
private int selectedItemPosition = -1;
private ActionMode actionMode; private ActionMode actionMode;
@ -571,12 +571,10 @@ public class NotesFragment extends OsmAndListFragment implements FavoritesFragme
} }
private void showOnMap(Recording recording, int itemPosition) { 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)), new PointDescription(recording.getSearchHistoryType(), recording.getName(getActivity(), true)),
true, recording); true, recording);
Bundle b = new Bundle();
b.putInt(ITEM_POSITION, itemPosition);
MapActivity.launchMapActivityMoveToTop(getActivity(), storeState(b));
} }
private void editNote(final Recording recording) { private void editNote(final Recording recording) {
@ -617,22 +615,26 @@ public class NotesFragment extends OsmAndListFragment implements FavoritesFragme
} }
@Override @Override
public Bundle storeState(Bundle bundle) { public Bundle storeState() {
Bundle bundle = new Bundle();
bundle.putInt(TAB_ID, NOTES_TAB); bundle.putInt(TAB_ID, NOTES_TAB);
bundle.putInt(ITEM_POSITION, selectedItemPosition);
return bundle; return bundle;
} }
@Override @Override
public void restoreState(Bundle bundle) { public void restoreState(Bundle bundle) {
if (bundle != null && bundle.containsKey(TAB_ID) && bundle.containsKey(ITEM_POSITION)) { if (bundle != null && bundle.containsKey(TAB_ID) && bundle.containsKey(ITEM_POSITION)) {
if (bundle.getInt(TAB_ID, 0) == NOTES_TAB) { if (bundle.getInt(TAB_ID) == NOTES_TAB) {
int position= bundle.getInt(ITEM_POSITION, 0); selectedItemPosition = bundle.getInt(ITEM_POSITION, -1);
if (selectedItemPosition != -1) {
int itemsCount = getListView().getAdapter().getCount(); int itemsCount = getListView().getAdapter().getCount();
if (itemsCount > 0 && itemsCount > position) { if (itemsCount > 0 && itemsCount > selectedItemPosition) {
if (position == 1) { if (selectedItemPosition == 1) {
getListView().setSelection(0); getListView().setSelection(0);
} else { } else {
getListView().setSelection(position); getListView().setSelection(selectedItemPosition);
}
} }
} }
} }

View file

@ -69,6 +69,10 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.zip.ZipInputStream; 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 * @author Koen Rabaey
*/ */
@ -295,7 +299,7 @@ public class ImportHelper {
final Intent newIntent = new Intent(activity, final Intent newIntent = new Intent(activity,
app.getAppCustomization().getFavoritesActivity()); app.getAppCustomization().getFavoritesActivity());
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
newIntent.putExtra(FavoritesActivity.TAB_ID, FavoritesActivity.FAV_TAB); newIntent.putExtra(TAB_ID, FAV_TAB);
activity.startActivity(newIntent); activity.startActivity(newIntent);
} }
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@ -596,7 +600,7 @@ public class ImportHelper {
if (forceImportFavourites) { if (forceImportFavourites) {
final Intent newIntent = new Intent(activity, app.getAppCustomization().getFavoritesActivity()); final Intent newIntent = new Intent(activity, app.getAppCustomization().getFavoritesActivity());
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
newIntent.putExtra(FavoritesActivity.TAB_ID, FavoritesActivity.GPX_TAB); newIntent.putExtra(TAB_ID, GPX_TAB);
activity.startActivity(newIntent); activity.startActivity(newIntent);
} }
} }

View file

@ -1,9 +1,7 @@
package net.osmand.plus.mapcontextmenu.builders; package net.osmand.plus.mapcontextmenu.builders;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.Gravity; import android.view.Gravity;
@ -23,12 +21,10 @@ import net.osmand.data.QuadRect;
import net.osmand.data.TransportStop; import net.osmand.data.TransportStop;
import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiCategory;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.myplaces.FavoritesActivity.FavoritesFragmentStateHolder;
import net.osmand.plus.widgets.TextViewEx; import net.osmand.plus.widgets.TextViewEx;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
@ -258,13 +254,7 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
button.setOnClickListener(new View.OnClickListener() { button.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
OsmAndAppCustomization appCustomization = app.getAppCustomization(); FavoritesActivity.openFavoritesGroup(context, group.name);
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);
} }
}); });
view.addView(button); view.addView(button);

View file

@ -79,7 +79,6 @@ import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment; import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.myplaces.FavoritesActivity.FavoritesFragmentStateHolder;
import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -102,6 +101,9 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.regex.Pattern; 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 public class AvailableGPXFragment extends OsmandExpandableListFragment implements
FavoritesFragmentStateHolder { FavoritesFragmentStateHolder {
@ -710,12 +712,13 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
boolean e = true; boolean e = true;
if (info.gpx != null) { if (info.gpx != null) {
WptPt loc = info.gpx.findPointToShow(); WptPt loc = info.gpx.findPointToShow();
OsmandSettings settings = getMyApplication().getSettings(); OsmandApplication app = requireMyApplication();
OsmandSettings settings = app.getSettings();
if (loc != null) { if (loc != null) {
settings.setMapLocationToShow(loc.lat, loc.lon, settings.getLastKnownMapZoom()); settings.setMapLocationToShow(loc.lat, loc.lon, settings.getLastKnownMapZoom());
e = false; e = false;
getMyApplication().getSelectedGpxHelper().setGpxFileToDisplay(info.gpx); app.getSelectedGpxHelper().setGpxFileToDisplay(info.gpx);
MapActivity.launchMapActivityMoveToTop(getActivity(), storeState(new Bundle())); MapActivity.launchMapActivityMoveToTop(getActivity(), storeState());
} }
} }
if (e) { if (e) {
@ -865,8 +868,9 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
} }
@Override @Override
public Bundle storeState(Bundle bundle) { public Bundle storeState() {
bundle.putInt(FavoritesActivity.TAB_ID, FavoritesActivity.GPX_TAB); Bundle bundle = new Bundle();
bundle.putInt(TAB_ID, GPX_TAB);
return bundle; return bundle;
} }

View file

@ -1,14 +1,14 @@
/**
*
*/
package net.osmand.plus.myplaces; package net.osmand.plus.myplaces;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.widget.SearchView; import android.support.v7.widget.SearchView;
@ -18,6 +18,8 @@ import android.text.style.ImageSpan;
import android.view.MenuItem; import android.view.MenuItem;
import android.widget.ImageView; import android.widget.ImageView;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmAndAppCustomization;
import net.osmand.plus.OsmAndLocationProvider; import net.osmand.plus.OsmAndLocationProvider;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; 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 OPEN_GPX_DOCUMENT_REQUEST = 1006;
private static final int IMPORT_FAVOURITES_REQUEST = 1007; private static final int IMPORT_FAVOURITES_REQUEST = 1007;
public static final String TAB_ID = "selected_tab_id"; public static final String TAB_ID = "selected_tab_id";
public static final int GPX_TAB = R.string.shared_string_tracks; 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 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<WeakReference<FavoritesFragmentStateHolder>> fragList = new ArrayList<>(); protected List<WeakReference<FavoritesFragmentStateHolder>> fragList = new ArrayList<>();
private int tabSize; private int tabSize;
private ImportHelper importHelper; private ImportHelper importHelper;
private List<TabItem> mTabs;
private Bundle intentParams = null; private Bundle intentParams = null;
@Override @Override
public void onCreate(Bundle icicle) { public void onCreate(Bundle savedInstanceState) {
OsmandApplication app = (OsmandApplication) getApplication(); OsmandApplication app = (OsmandApplication) getApplication();
app.applyTheme(this); app.applyTheme(this);
super.onCreate(icicle); super.onCreate(savedInstanceState);
app.logEvent("myplaces_open"); app.logEvent("myplaces_open");
importHelper = new ImportHelper(this, getMyApplication(), null); importHelper = new ImportHelper(this, getMyApplication(), null);
//noinspection ConstantConditions //noinspection ConstantConditions
getSupportActionBar().setTitle(R.string.shared_string_my_places); getSupportActionBar().setTitle(R.string.shared_string_my_places);
getSupportActionBar().setElevation(0); getSupportActionBar().setElevation(0);
setContentView(R.layout.tab_content); setContentView(R.layout.tab_content);
mTabs = getTabItems(); List<TabItem> mTabs = getTabItems();
setTabs(mTabs); setTabs(mTabs);
ViewPager mViewPager = (ViewPager) findViewById(R.id.pager); ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
if (icicle == null) { if (savedInstanceState == null) {
Intent intent = getIntent(); Intent intent = getIntent();
if (intent != null && intent.hasExtra(MapActivity.INTENT_PARAMS)) { if (intent != null && intent.hasExtra(MapActivity.INTENT_PARAMS)) {
intentParams = intent.getBundleExtra(MapActivity.INTENT_PARAMS); intentParams = intent.getBundleExtra(MapActivity.INTENT_PARAMS);
int tabId = intentParams.getInt(TAB_ID, FAV_TAB); int tabId = intentParams.getInt(TAB_ID, FAV_TAB);
int pagerItem = 0; int pagerItem = 0;
for (int n = 0; n < mTabs.size(); n++) { for (int n = 0; n < mTabs.size(); n++) {
if (mTabs.get(n).mTitle.equals(getString(tabId))) { if (mTabs.get(n).resId == tabId) {
pagerItem = n; pagerItem = n;
break; break;
} }
@ -192,20 +186,7 @@ public class FavoritesActivity extends TabActivity {
@Override @Override
public void onAttachFragment(Fragment fragment) { public void onAttachFragment(Fragment fragment) {
if (fragment instanceof FavoritesFragmentStateHolder) { if (fragment instanceof FavoritesFragmentStateHolder) {
if (intentParams != null && intentParams.getInt(TAB_ID, -1) != -1) { fragment.setArguments(intentParams);
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);
}
fragList.add(new WeakReference<>((FavoritesFragmentStateHolder) fragment)); fragList.add(new WeakReference<>((FavoritesFragmentStateHolder) fragment));
} }
} }
@ -213,7 +194,7 @@ public class FavoritesActivity extends TabActivity {
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
mTabs = getTabItems(); List<TabItem> mTabs = getTabItems();
if (mTabs.size() != tabSize) { if (mTabs.size() != tabSize) {
setTabs(mTabs); setTabs(mTabs);
} }
@ -230,11 +211,9 @@ public class FavoritesActivity extends TabActivity {
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId(); int itemId = item.getItemId();
switch (itemId) { if (itemId == android.R.id.home) {
case android.R.id.home:
finish(); finish();
return true; return true;
} }
return false; return false;
} }
@ -261,21 +240,29 @@ public class FavoritesActivity extends TabActivity {
stopHint.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); stopHint.setSpan(new ImageSpan(searchIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
searchEdit.setHint(stopHint); searchEdit.setHint(stopHint);
} catch (Exception e) { } 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) {
String ITEM_POSITION = "item_position"; OsmandApplication app = (OsmandApplication) activity.getApplication();
app.getSettings().setMapLocationToShow(latitude, longitude, zoom, pointDescription, addToHistory, toShow);
String GROUP_POSITION = "group_position"; if (fragment != null) {
MapActivity.launchMapActivityMoveToTop(activity, fragment.storeState());
String GROUP_NAME_TO_SHOW = "group_name_to_show"; } else {
MapActivity.launchMapActivityMoveToTop(activity);
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);
} }
} }

View file

@ -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);
}

View file

@ -57,6 +57,7 @@ import static net.osmand.plus.OsmAndCustomizationConstants.OSM_NOTES;
public class OsmEditingPlugin extends OsmandPlugin { public class OsmEditingPlugin extends OsmandPlugin {
private static final Log LOG = PlatformUtil.getLog(OsmEditingPlugin.class); 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"; private static final String ID = "osm.editing";
// Constants for determining the order of items in the additional actions context menu // Constants for determining the order of items in the additional actions context menu

View file

@ -1,8 +1,5 @@
package net.osmand.plus.osmedit; 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.Dialog;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -33,12 +30,12 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.AndroidUtils; 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;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt; 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.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; 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.dialogs.ProgressDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.myplaces.FavoritesActivity; 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.ExportOptionsBottomSheetDialogFragment.ExportOptionsFragmentListener;
import net.osmand.plus.osmedit.FileTypeBottomSheetDialogFragment.FileTypeFragmentListener; import net.osmand.plus.osmedit.FileTypeBottomSheetDialogFragment.FileTypeFragmentListener;
import net.osmand.plus.osmedit.OsmEditOptionsBottomSheetDialogFragment.OsmEditOptionsFragmentListener; import net.osmand.plus.osmedit.OsmEditOptionsBottomSheetDialogFragment.OsmEditOptionsFragmentListener;
@ -72,6 +69,9 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; 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, public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialogFragment.ProgressDialogPoiUploader, OpenstreetmapLocalUtil.OnNodeCommittedListener,
FavoritesFragmentStateHolder { FavoritesFragmentStateHolder {
@ -108,6 +108,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
private ActionMode actionMode; private ActionMode actionMode;
private long refreshId; private long refreshId;
private int selectedItemPosition = -1;
private int exportType; private int exportType;
@ -648,14 +649,12 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
} }
private void showOnMap(OsmPoint osmPoint, int itemPosition) { private void showOnMap(OsmPoint osmPoint, int itemPosition) {
selectedItemPosition = itemPosition;
boolean isOsmPoint = osmPoint instanceof OpenstreetmapPoint; boolean isOsmPoint = osmPoint instanceof OpenstreetmapPoint;
String type = osmPoint.getGroup() == Group.POI ? PointDescription.POINT_TYPE_POI : PointDescription.POINT_TYPE_OSM_BUG; String type = osmPoint.getGroup() == Group.POI ? PointDescription.POINT_TYPE_POI : PointDescription.POINT_TYPE_OSM_BUG;
String name = (isOsmPoint ? ((OpenstreetmapPoint) osmPoint).getName() : ((OsmNotesPoint) osmPoint).getText()); String name = (isOsmPoint ? ((OpenstreetmapPoint) osmPoint).getName() : ((OsmNotesPoint) osmPoint).getText());
getMyApplication().getSettings().setMapLocationToShow(osmPoint.getLatitude(), osmPoint.getLongitude(), 15, FavoritesActivity.showOnMap(requireActivity(), this, osmPoint.getLatitude(), osmPoint.getLongitude(), 15,
new PointDescription(type, name), true, osmPoint); //$NON-NLS-1$ new PointDescription(type, name), true, osmPoint);
Bundle b = new Bundle();
b.putInt(ITEM_POSITION, itemPosition);
MapActivity.launchMapActivityMoveToTop(getActivity(), storeState(b));
} }
private void deletePoint(OsmPoint osmPoint) { private void deletePoint(OsmPoint osmPoint) {
@ -902,21 +901,25 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
} }
@Override @Override
public Bundle storeState(Bundle bundle) { public Bundle storeState() {
bundle.putInt(TAB_ID, OSM_TAB); Bundle bundle = new Bundle();
bundle.putInt(TAB_ID, OSM_EDIT_TAB);
bundle.putInt(ITEM_POSITION, selectedItemPosition);
return bundle; return bundle;
} }
public void restoreState(Bundle bundle) { public void restoreState(Bundle bundle) {
if (bundle != null && bundle.containsKey(TAB_ID) && bundle.containsKey(ITEM_POSITION)) { if (bundle != null && bundle.containsKey(TAB_ID) && bundle.containsKey(ITEM_POSITION)) {
if (bundle.getInt(TAB_ID, 0) == OSM_TAB) { if (bundle.getInt(TAB_ID) == OSM_EDIT_TAB) {
int position= bundle.getInt(ITEM_POSITION, 0); selectedItemPosition = bundle.getInt(ITEM_POSITION, -1);
if (selectedItemPosition != -1) {
int itemsCount = getListView().getAdapter().getCount(); int itemsCount = getListView().getAdapter().getCount();
if (itemsCount > 0 && itemsCount > position) { if (itemsCount > 0 && itemsCount > selectedItemPosition) {
if (position == 1) { if (selectedItemPosition == 1) {
getListView().setSelection(0); getListView().setSelection(0);
} else { } else {
getListView().setSelection(position); getListView().setSelection(selectedItemPosition);
}
} }
} }
} }