Merge pull request #7089 from osmandapp/issue_6967

Issue 6967
This commit is contained in:
vshcherb 2019-06-26 11:16:09 +02:00 committed by GitHub
commit 3b8a5284d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 207 additions and 61 deletions

View file

@ -1,5 +1,8 @@
package net.osmand.plus.activities;
import static net.osmand.plus.myplaces.FavoritesActivity.FAV_TAB;
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@ -48,6 +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.util.Algorithms;
import net.osmand.util.MapUtils;
@ -64,7 +68,8 @@ import java.util.Map;
import java.util.Set;
public class FavoritesTreeFragment extends OsmandExpandableListFragment {
public class FavoritesTreeFragment extends OsmandExpandableListFragment implements
FavoritesFragmentStateHolder {
public static final int SEARCH_ID = -1;
// public static final int EXPORT_ID = 0;
// public static final int IMPORT_ID = 1;
@ -91,6 +96,8 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
private FavoritesListener favoritesListener;
String groupNameToShow = null;
@Override
public void onAttach(Context context) {
super.onAttach(context);
@ -204,7 +211,11 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
getGroupExpandedPreference(groupName).set(true);
}
});
String groupNameToShow = ((FavoritesActivity) getActivity()).getGroupNameToShow();
if (getArguments() != null) {
groupNameToShow = getArguments().getString(GROUP_NAME_TO_SHOW);
}
if (groupNameToShow != null) {
int groupPos = favouritesAdapter.getGroupPosition(groupNameToShow);
if (groupPos != -1) {
@ -235,6 +246,9 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
super.onResume();
favouritesAdapter.synchronizeGroups();
initListExpandedState();
if (groupNameToShow == null) {
restoreState(getArguments());
}
}
@Override
@ -308,7 +322,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
updateSelectionMode(actionMode);
} else {
final FavouritePoint point = favouritesAdapter.getChild(groupPosition, childPosition);
showOnMap(point);
showOnMap(point, groupPosition, childPosition);
}
return true;
}
@ -685,7 +699,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
return preference;
}
public void showOnMap(final FavouritePoint point) {
public void showOnMap(final FavouritePoint point, int groupPos, int childPos) {
getMyApplication().getSettings().FAVORITES_TAB.set(FavoritesActivity.FAV_TAB);
final OsmandSettings settings = getMyApplication().getSettings();
@ -695,7 +709,27 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
new PointDescription(PointDescription.POINT_TYPE_FAVORITE, point.getName()),
true,
point); //$NON-NLS-1$
MapActivity.launchMapActivityMoveToTop(getActivity());
Bundle b = new Bundle();
b.putInt(GROUP_POSITION, groupPos);
b.putInt(ITEM_POSITION, childPos);
MapActivity.launchMapActivityMoveToTop(getActivity(), storeState(b));
}
@Override
public Bundle storeState(Bundle bundle) {
bundle.putInt(FavoritesActivity.TAB_ID, FavoritesActivity.FAV_TAB);
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);
}
}
}
class FavouritesAdapter extends OsmandBaseExpandableListAdapter implements Filterable {
@ -865,7 +899,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView,
public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView,
ViewGroup parent) {
View row = convertView;
if (row == null) {
@ -897,7 +931,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
options.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showOnMap(model);
showOnMap(model, groupPosition, childPosition);
}
});
}

View file

@ -159,6 +159,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
OnRequestPermissionsResultCallback, IRouteInformationListener, AMapPointUpdateListener,
MapMarkerChangedListener, OnDismissDialogFragmentListener, OnDrawMapListener, OsmAndAppCustomizationListener {
public static final String INTENT_KEY_PARENT_MAP_ACTIVITY = "intent_parent_map_activity_key";
public static final String INTENT_PARAMS = "intent_prarams";
private static final int SHOW_POSITION_MSG_ID = OsmAndConstants.UI_HANDLER_MAP_VIEW + 1;
private static final int LONG_KEYPRESS_MSG_ID = OsmAndConstants.UI_HANDLER_MAP_VIEW + 2;
@ -1585,7 +1586,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return mapLayers;
}
public static void launchMapActivityMoveToTop(Context activity, String intentExtraActionName, Bundle intentExtraActionValue) {
public static void launchMapActivityMoveToTop(Context activity, Bundle intentParams) {
if (activity instanceof MapActivity) {
if (((MapActivity) activity).getDashboard().isVisible()) {
((MapActivity) activity).getDashboard().hideDashboard();
@ -1597,6 +1598,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
Intent intent = ((Activity) activity).getIntent();
if (intent != null) {
prevActivityIntent = new Intent(intent);
if (intentParams != null) {
prevActivityIntent.putExtra(INTENT_PARAMS, intentParams);
prevActivityIntent.putExtras(intentParams);
}
prevActivityIntent.putExtra(INTENT_KEY_PARENT_MAP_ACTIVITY, true);
} else {
prevActivityIntent = null;
@ -1609,15 +1614,12 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
Intent newIntent = new Intent(activity, ((OsmandApplication) activity.getApplicationContext())
.getAppCustomization().getMapActivity());
newIntent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT | Intent.FLAG_ACTIVITY_CLEAR_TOP | additionalFlags);
if (intentExtraActionName != null) {
newIntent.putExtra(intentExtraActionName, intentExtraActionValue);
}
activity.startActivity(newIntent);
}
}
public static void launchMapActivityMoveToTop(Context activity) {
launchMapActivityMoveToTop(activity, null, null);
launchMapActivityMoveToTop(activity, null);
}
public static void clearPrevActivityIntent() {

View file

@ -1,5 +1,8 @@
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;
@ -48,6 +51,7 @@ import net.osmand.plus.base.OsmAndListFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.myplaces.FavoritesActivity.FavoritesFragmentStateHolder;
import org.apache.commons.logging.Log;
import java.io.File;
@ -60,7 +64,7 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Set;
public class NotesFragment extends OsmAndListFragment {
public class NotesFragment extends OsmAndListFragment implements FavoritesFragmentStateHolder {
public static final Recording SHARE_LOCATION_FILE = new Recording(new File("."));
@ -141,6 +145,7 @@ public class NotesFragment extends OsmAndListFragment {
listAdapter.setListener(createAdapterListener());
listAdapter.setPortrait(portrait);
listView.setAdapter(listAdapter);
restoreState(getArguments());
}
@Override
@ -266,8 +271,8 @@ public class NotesFragment extends OsmAndListFragment {
}
@Override
public void onItemClick(Recording rec) {
showOnMap(rec);
public void onItemClick(Recording rec, int position) {
showOnMap(rec, position);
}
@Override
@ -562,10 +567,16 @@ public class NotesFragment extends OsmAndListFragment {
}
private void showOnMap(Recording recording) {
showOnMap(recording, -1);
}
private void showOnMap(Recording recording, int itemPosition) {
getMyApplication().getSettings().setMapLocationToShow(recording.getLatitude(), recording.getLongitude(), 15,
new PointDescription(recording.getSearchHistoryType(), recording.getName(getActivity(), true)),
true, recording);
MapActivity.launchMapActivityMoveToTop(getActivity());
Bundle b = new Bundle();
b.putInt(ITEM_POSITION, itemPosition);
MapActivity.launchMapActivityMoveToTop(getActivity(), storeState(b));
}
private void editNote(final Recording recording) {
@ -604,4 +615,27 @@ public class NotesFragment extends OsmAndListFragment {
.setNegativeButton(R.string.shared_string_cancel, null)
.show();
}
@Override
public Bundle storeState(Bundle bundle) {
bundle.putInt(TAB_ID, NOTES_TAB);
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);
}
}
}
}
}
}

View file

@ -201,7 +201,7 @@ public class NotesAdapter extends ArrayAdapter<Object> {
return R.string.shared_string_video;
}
private void setupItem(int position, final Recording recording, final ItemViewHolder holder) {
private void setupItem(final int position, final Recording recording, final ItemViewHolder holder) {
setupBackground(holder.view);
if (recording == NotesFragment.SHARE_LOCATION_FILE) {
holder.title.setText(R.string.av_locations);
@ -248,7 +248,7 @@ public class NotesAdapter extends ArrayAdapter<Object> {
holder.checkBox.performClick();
} else {
if (listener != null) {
listener.onItemClick(recording);
listener.onItemClick(recording, position);
}
}
}
@ -368,7 +368,7 @@ public class NotesAdapter extends ArrayAdapter<Object> {
void onCheckBoxClick(Recording rec, boolean checked);
void onItemClick(Recording rec);
void onItemClick(Recording rec, int position);
void onOptionsClick(Recording rec);
}

View file

@ -295,7 +295,7 @@ public class ImportHelper {
final Intent newIntent = new Intent(activity,
app.getAppCustomization().getFavoritesActivity());
newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
newIntent.putExtra(FavoritesActivity.OPEN_FAVOURITES_TAB, true);
newIntent.putExtra(FavoritesActivity.TAB_ID, FavoritesActivity.FAV_TAB);
activity.startActivity(newIntent);
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
@ -596,7 +596,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.OPEN_MY_PLACES_TAB, true);
newIntent.putExtra(FavoritesActivity.TAB_ID, FavoritesActivity.GPX_TAB);
activity.startActivity(newIntent);
}
}

View file

@ -3,6 +3,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;
@ -27,6 +28,7 @@ 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,9 +260,10 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
public void onClick(View view) {
OsmAndAppCustomization appCustomization = app.getAppCustomization();
final Intent intent = new Intent(context, appCustomization.getFavoritesActivity());
intent.putExtra(FavoritesActivity.OPEN_FAVOURITES_TAB, true);
intent.putExtra(FavoritesActivity.GROUP_NAME_TO_SHOW, group.name);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
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 file

@ -79,6 +79,7 @@ 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;
@ -101,10 +102,10 @@ import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
public class AvailableGPXFragment extends OsmandExpandableListFragment {
public class AvailableGPXFragment extends OsmandExpandableListFragment implements
FavoritesFragmentStateHolder {
public static final Pattern ILLEGAL_PATH_NAME_CHARACTERS = Pattern.compile("[?:\"*|<>]");
public static final int SEARCH_ID = -1;
// public static final int ACTION_ID = 0;
// protected static final int DELETE_ACTION_ID = 1;
@ -196,6 +197,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
updateEnable = true;
startHandler();
restoreState(getArguments());
}
@Override
@ -713,7 +715,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
settings.setMapLocationToShow(loc.lat, loc.lon, settings.getLastKnownMapZoom());
e = false;
getMyApplication().getSelectedGpxHelper().setGpxFileToDisplay(info.gpx);
MapActivity.launchMapActivityMoveToTop(getActivity());
MapActivity.launchMapActivityMoveToTop(getActivity(), storeState(new Bundle()));
}
}
if (e) {
@ -862,6 +864,16 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
builder.create().show();
}
@Override
public Bundle storeState(Bundle bundle) {
bundle.putInt(FavoritesActivity.TAB_ID, FavoritesActivity.GPX_TAB);
return bundle;
}
@Override
public void restoreState(Bundle bundle) {
}
public class LoadGpxTask extends AsyncTask<Activity, GpxInfo, List<GpxInfo>> {
private List<GpxInfo> result;

View file

@ -24,6 +24,7 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.FavoritesTreeFragment;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TabActivity;
import net.osmand.plus.helpers.ImportHelper;
import net.osmand.plus.views.controls.PagerSlidingTabStrip;
@ -40,17 +41,22 @@ 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 GROUP_NAME_TO_SHOW = "group_name_to_show";
public static final String OPEN_FAVOURITES_TAB = "open_favourites_tab";
public static final String OPEN_MY_PLACES_TAB = "open_my_places_tab";
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;
protected List<WeakReference<Fragment>> fragList = new ArrayList<>();
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<>();
private int tabSize;
private ImportHelper importHelper;
private String groupNameToShow;
private List<TabItem> mTabs;
private Bundle intentParams = null;
@Override
public void onCreate(Bundle icicle) {
@ -60,6 +66,7 @@ public class FavoritesActivity extends TabActivity {
app.logEvent("myplaces_open");
importHelper = new ImportHelper(this, getMyApplication(), null);
//noinspection ConstantConditions
@ -68,28 +75,25 @@ public class FavoritesActivity extends TabActivity {
setContentView(R.layout.tab_content);
List<TabItem> mTabs = getTabItems();
mTabs = getTabItems();
setTabs(mTabs);
// setupHomeButton();
ViewPager mViewPager = (ViewPager) findViewById(R.id.pager);
if (icicle == null) {
Intent intent = getIntent();
if (intent != null) {
if (intent.hasExtra(OPEN_FAVOURITES_TAB) && intent.getBooleanExtra(OPEN_FAVOURITES_TAB, false)) {
if (intent.hasExtra(GROUP_NAME_TO_SHOW)) {
groupNameToShow = intent.getStringExtra(GROUP_NAME_TO_SHOW);
}
mViewPager.setCurrentItem(0, false);
} else if (intent.hasExtra(OPEN_MY_PLACES_TAB) && intent.getBooleanExtra(OPEN_MY_PLACES_TAB, false)) {
mViewPager.setCurrentItem(1, false);
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))) {
pagerItem = n;
break;
}
}
mViewPager.setCurrentItem(pagerItem, false);
}
}
public String getGroupNameToShow() {
return groupNameToShow;
}
public void addTrack() {
@ -151,8 +155,8 @@ public class FavoritesActivity extends TabActivity {
private AvailableGPXFragment getGpxFragment() {
AvailableGPXFragment gpxFragment = null;
for (WeakReference<Fragment> f : fragList) {
Fragment frag = f.get();
for (WeakReference<FavoritesFragmentStateHolder> f : fragList) {
FavoritesFragmentStateHolder frag = f.get();
if (frag instanceof AvailableGPXFragment) {
gpxFragment = (AvailableGPXFragment) frag;
}
@ -187,13 +191,29 @@ public class FavoritesActivity extends TabActivity {
@Override
public void onAttachFragment(Fragment fragment) {
fragList.add(new WeakReference<>(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);
}
fragList.add(new WeakReference<>((FavoritesFragmentStateHolder) fragment));
}
}
@Override
protected void onResume() {
super.onResume();
List<TabItem> mTabs = getTabItems();
mTabs = getTabItems();
if(mTabs.size() != tabSize ) {
setTabs(mTabs);
}
@ -244,5 +264,18 @@ public class FavoritesActivity extends TabActivity {
e.printStackTrace();
}
}
public interface FavoritesFragmentStateHolder {
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);
}
}

View file

@ -176,7 +176,7 @@ public class OsmEditsAdapter extends ArrayAdapter<Object> {
}
}
private void bindOsmEditViewHolder(final OsmEditViewHolder holder, final OsmPoint osmEdit, int position) {
private void bindOsmEditViewHolder(final OsmEditViewHolder holder, final OsmPoint osmEdit, final int position) {
setupBackground(holder.mainView);
holder.titleTextView.setText(getTitle(osmEdit));
holder.descriptionTextView.setText(getDescription(osmEdit));
@ -219,7 +219,7 @@ public class OsmEditsAdapter extends ArrayAdapter<Object> {
holder.selectCheckBox.performClick();
} else {
if (listener != null) {
listener.onItemShowMap(osmEdit);
listener.onItemShowMap(osmEdit, position);
}
}
@ -350,7 +350,7 @@ public class OsmEditsAdapter extends ArrayAdapter<Object> {
void onItemSelect(OsmPoint point, boolean checked);
void onItemShowMap(OsmPoint point);
void onItemShowMap(OsmPoint point, int position);
void onOptionsClick(OsmPoint note);
}

View file

@ -1,5 +1,8 @@
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,7 +36,6 @@ import net.osmand.AndroidUtils;
import net.osmand.data.PointDescription;
import net.osmand.osm.edit.Entity;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Way;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt;
@ -49,6 +51,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.osmedit.ExportOptionsBottomSheetDialogFragment.ExportOptionsFragmentListener;
import net.osmand.plus.osmedit.FileTypeBottomSheetDialogFragment.FileTypeFragmentListener;
import net.osmand.plus.osmedit.OsmEditOptionsBottomSheetDialogFragment.OsmEditOptionsFragmentListener;
@ -69,7 +72,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialogFragment.ProgressDialogPoiUploader, OpenstreetmapLocalUtil.OnNodeCommittedListener {
public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialogFragment.ProgressDialogPoiUploader, OpenstreetmapLocalUtil.OnNodeCommittedListener,
FavoritesFragmentStateHolder {
public static final int EXPORT_TYPE_ALL = 0;
public static final int EXPORT_TYPE_POI = 1;
@ -404,6 +408,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
public void onResume() {
super.onResume();
fetchData();
restoreState(getArguments());
}
@Override
@ -454,8 +459,8 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
}
@Override
public void onItemShowMap(OsmPoint point) {
showOnMap(point);
public void onItemShowMap(OsmPoint point, int position) {
showOnMap(point, position);
}
@Override
@ -642,13 +647,15 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
uploadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, points);
}
private void showOnMap(OsmPoint osmPoint) {
private void showOnMap(OsmPoint osmPoint, int 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$
MapActivity.launchMapActivityMoveToTop(getActivity());
Bundle b = new Bundle();
b.putInt(ITEM_POSITION, itemPosition);
MapActivity.launchMapActivityMoveToTop(getActivity(), storeState(b));
}
private void deletePoint(OsmPoint osmPoint) {
@ -894,4 +901,25 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
}
}
@Override
public Bundle storeState(Bundle bundle) {
bundle.putInt(TAB_ID, OSM_TAB);
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);
}
}
}
}
}
}