fixed logic and add to favorites and gpx fragments.

This commit is contained in:
madwasp79 2019-06-25 13:54:40 +03:00
parent d83f80d65e
commit f128c9402d
8 changed files with 112 additions and 73 deletions

View file

@ -48,6 +48,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.FragmentStateHolder;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
@ -64,7 +65,8 @@ import java.util.Map;
import java.util.Set;
public class FavoritesTreeFragment extends OsmandExpandableListFragment {
public class FavoritesTreeFragment extends OsmandExpandableListFragment implements
FragmentStateHolder {
public static final int SEARCH_ID = -1;
// public static final int EXPORT_ID = 0;
// public static final int IMPORT_ID = 1;
@ -204,7 +206,12 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
getGroupExpandedPreference(groupName).set(true);
}
});
String groupNameToShow = ((FavoritesActivity) getActivity()).getGroupNameToShow();
String groupNameToShow = null;
if (getArguments() != null) {
groupNameToShow = getArguments().getString(FavoritesActivity.GROUP_NAME_TO_SHOW);
}
if (groupNameToShow != null) {
int groupPos = favouritesAdapter.getGroupPosition(groupNameToShow);
if (groupPos != -1) {
@ -235,6 +242,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment {
super.onResume();
favouritesAdapter.synchronizeGroups();
initListExpandedState();
restoreState(getArguments());
}
@Override
@ -308,7 +316,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 +693,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 +703,25 @@ 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(FavoritesActivity.GROUP_POSITION, groupPos);
b.putInt(FavoritesActivity.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) {
int group = bundle.getInt(FavoritesActivity.GROUP_POSITION, 0);
int child = bundle.getInt(FavoritesActivity.ITEM_POSITION, 0);
listView.setSelectedChild(group, child, true);
}
}
class FavouritesAdapter extends OsmandBaseExpandableListAdapter implements Filterable {
@ -865,7 +891,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 +923,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;
@ -1598,6 +1599,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
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);

View file

@ -1,8 +1,8 @@
package net.osmand.plus.audionotes;
import static net.osmand.plus.myplaces.FavoritesActivity.NOTE_TAB;
import static net.osmand.plus.myplaces.FavoritesActivity.SCROLL_POSITION;
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_TO_OPEN;
import static net.osmand.plus.myplaces.FavoritesActivity.NOTES_TAB;
import static net.osmand.plus.myplaces.FavoritesActivity.ITEM_POSITION;
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
import android.content.Context;
import android.content.DialogInterface;
@ -576,8 +576,8 @@ public class NotesFragment extends OsmAndListFragment implements FragmentStateHo
new PointDescription(recording.getSearchHistoryType(), recording.getName(getActivity(), true)),
true, recording);
Bundle b = new Bundle();
b.putInt(SCROLL_POSITION, itemPosition);
b.putInt(TAB_TO_OPEN, NOTE_TAB);
b.putInt(ITEM_POSITION, itemPosition);
b.putInt(TAB_ID, NOTES_TAB);
MapActivity.launchMapActivityMoveToTop(getActivity(), storeState(b));
}
@ -625,8 +625,8 @@ public class NotesFragment extends OsmAndListFragment implements FragmentStateHo
@Override
public void restoreState(Bundle bundle) {
if (bundle != null && bundle.containsKey(SCROLL_POSITION)) {
int position= bundle.getInt(SCROLL_POSITION, 0);
if (bundle != null && bundle.containsKey(ITEM_POSITION)) {
int position= bundle.getInt(ITEM_POSITION, 0);
int itemsCount = getListView().getAdapter().getCount();
if (itemsCount > 0 && itemsCount > position) {
if (position == 1) {

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

@ -258,7 +258,7 @@ 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.TAB_ID, FavoritesActivity.FAV_TAB);
intent.putExtra(FavoritesActivity.GROUP_NAME_TO_SHOW, group.name);
intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
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.FragmentStateHolder;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.util.Algorithms;
@ -101,7 +102,8 @@ import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
public class AvailableGPXFragment extends OsmandExpandableListFragment {
public class AvailableGPXFragment extends OsmandExpandableListFragment implements
FragmentStateHolder {
public static final Pattern ILLEGAL_PATH_NAME_CHARACTERS = Pattern.compile("[?:\"*|<>]");
@ -196,6 +198,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment {
updateEnable = true;
startHandler();
restoreState(getArguments());
}
@Override
@ -713,7 +716,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 +865,17 @@ 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,8 +24,11 @@ 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.audionotes.NotesFragment;
import net.osmand.plus.helpers.ImportHelper;
import net.osmand.plus.osmedit.OsmEditsFragment;
import net.osmand.plus.views.controls.PagerSlidingTabStrip;
import java.lang.ref.WeakReference;
@ -41,25 +44,23 @@ public class FavoritesActivity extends TabActivity {
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_TO_OPEN = "tab_to_open";
public static final String SCROLL_POSITION = "scroll_position";
public static final String TAB_ID = "selected_tab_id";
public static final String ITEM_POSITION = "item_position";
public static final String GROUP_POSITION = "group_position";
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 NOTE_TAB = R.string.notes;
public static final int NOTES_TAB = R.string.notes;
public static final int OSM_TAB = R.string.osm_edits;
protected List<WeakReference<Fragment>> fragList = new ArrayList<>();
protected List<WeakReference<FragmentStateHolder>> fragList = new ArrayList<>();
private int tabSize;
private ImportHelper importHelper;
private String groupNameToShow;
private int itemPosition = 0;
private List<TabItem> mTabs;
private Bundle intentParams = null;
@Override
public void onCreate(Bundle icicle) {
OsmandApplication app = (OsmandApplication) getApplication();
@ -77,44 +78,27 @@ 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(SCROLL_POSITION)) {
itemPosition = intent.getIntExtra(SCROLL_POSITION, 0);
}
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.hasExtra(TAB_TO_OPEN)) {
for (int n = 0; n < mTabs.size(); n++) {
int tab = intent.getIntExtra(TAB_TO_OPEN, FAV_TAB);
if (mTabs.get(n).mTitle.equals(getString(tab))) {
mViewPager.setCurrentItem(n, false);
break;
}
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() {
Intent intent = getImportGpxIntent();
startActivityForResult(intent, OPEN_GPX_DOCUMENT_REQUEST);
@ -174,8 +158,8 @@ public class FavoritesActivity extends TabActivity {
private AvailableGPXFragment getGpxFragment() {
AvailableGPXFragment gpxFragment = null;
for (WeakReference<Fragment> f : fragList) {
Fragment frag = f.get();
for (WeakReference<FragmentStateHolder> f : fragList) {
FragmentStateHolder frag = f.get();
if (frag instanceof AvailableGPXFragment) {
gpxFragment = (AvailableGPXFragment) frag;
}
@ -210,18 +194,32 @@ public class FavoritesActivity extends TabActivity {
@Override
public void onAttachFragment(Fragment fragment) {
if (fragment instanceof FragmentStateHolder && getIntent() != null) {
Bundle b = new Bundle();
b.putInt(SCROLL_POSITION, getIntent().getIntExtra(SCROLL_POSITION, 0));
fragment.setArguments(b);
if (fragment instanceof FragmentStateHolder) {
if (intentParams != null && intentParams.getInt(TAB_ID, -1) != -1) {
Bundle b = new Bundle();
int tabId = intentParams.getInt(TAB_ID, FAV_TAB);
if (tabId == FAV_TAB && fragment instanceof FavoritesTreeFragment) {
b.putString(GROUP_NAME_TO_SHOW, intentParams.getString(GROUP_NAME_TO_SHOW));
b.putInt(GROUP_POSITION, intentParams.getInt(GROUP_POSITION, 0));
b.putInt(ITEM_POSITION, intentParams.getInt(ITEM_POSITION, 0));
} else if (tabId == GPX_TAB && fragment instanceof AvailableGPXFragment) {
b.putInt(GROUP_POSITION, intentParams.getInt(GROUP_POSITION, 0));
b.putInt(ITEM_POSITION, intentParams.getInt(ITEM_POSITION, 0));
} else if (tabId == NOTES_TAB && fragment instanceof NotesFragment) {
b.putInt(ITEM_POSITION, intentParams.getInt(ITEM_POSITION, 0));
} else if (tabId == OSM_TAB && fragment instanceof OsmEditsFragment) {
b.putInt(ITEM_POSITION, intentParams.getInt(ITEM_POSITION, 0));
}
fragment.setArguments(b);
}
fragList.add(new WeakReference<>((FragmentStateHolder) fragment));
}
fragList.add(new WeakReference<>(fragment));
}
@Override
protected void onResume() {
super.onResume();
List<TabItem> mTabs = getTabItems();
mTabs = getTabItems();
if(mTabs.size() != tabSize ) {
setTabs(mTabs);
}

View file

@ -1,9 +1,8 @@
package net.osmand.plus.osmedit;
import static net.osmand.plus.myplaces.FavoritesActivity.NOTE_TAB;
import static net.osmand.plus.myplaces.FavoritesActivity.OSM_TAB;
import static net.osmand.plus.myplaces.FavoritesActivity.SCROLL_POSITION;
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_TO_OPEN;
import static net.osmand.plus.myplaces.FavoritesActivity.ITEM_POSITION;
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
import android.app.Dialog;
import android.app.ProgressDialog;
@ -656,8 +655,8 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
getMyApplication().getSettings().setMapLocationToShow(osmPoint.getLatitude(), osmPoint.getLongitude(), 15,
new PointDescription(type, name), true, osmPoint); //$NON-NLS-1$
Bundle b = new Bundle();
b.putInt(SCROLL_POSITION, itemPosition);
b.putInt(TAB_TO_OPEN, OSM_TAB);
b.putInt(ITEM_POSITION, itemPosition);
b.putInt(TAB_ID, OSM_TAB);
MapActivity.launchMapActivityMoveToTop(getActivity(), storeState(b));
}
@ -910,8 +909,8 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
}
public void restoreState(Bundle bundle) {
if (bundle != null && bundle.containsKey(SCROLL_POSITION)) {
int position= bundle.getInt(SCROLL_POSITION, 0);
if (bundle != null && bundle.containsKey(ITEM_POSITION)) {
int position= bundle.getInt(ITEM_POSITION, 0);
int itemsCount = getListView().getAdapter().getCount();
if (itemsCount > 0 && itemsCount > position) {
if (position == 1) {