Fix dismiss and back navigation

This commit is contained in:
PavelRatushny 2017-08-04 18:13:27 +03:00
parent 26e31fb9bf
commit f1961eb031
5 changed files with 40 additions and 9 deletions

View file

@ -36,6 +36,7 @@ import java.util.List;
public class TrackActivity extends TabActivity {
public static final String TRACK_FILE_NAME = "TRACK_FILE_NAME";
public static final String OPEN_POINTS_TAB = "OPEN_POINTS_TAB";
public static final String CURRENT_RECORDING = "CURRENT_RECORDING";
protected List<WeakReference<Fragment>> fragList = new ArrayList<>();
protected PagerSlidingTabStrip slidingTabLayout;
@ -47,6 +48,7 @@ public class TrackActivity extends TabActivity {
private List<GpxDisplayGroup> displayGroups;
private List<GpxDisplayGroup> originalGroups = new ArrayList<>();
private boolean stopped = false;
public boolean openPointsTab = false;
public PagerSlidingTabStrip getSlidingTabLayout() {
return slidingTabLayout;
@ -75,6 +77,9 @@ public class TrackActivity extends TabActivity {
}
actionBar.setElevation(0);
}
if (intent.hasExtra(OPEN_POINTS_TAB)) {
openPointsTab = true;
}
setContentView(R.layout.tab_content);
}
@ -188,6 +193,9 @@ public class TrackActivity extends TabActivity {
if (isHavingWayPoints() || isHavingRoutePoints()) {
((OsmandFragmentPagerAdapter) mViewPager.getAdapter()).addTab(
getTabIndicator(R.string.points, TrackPointFragment.class));
if (openPointsTab) {
mViewPager.setCurrentItem(1, false);
}
} else {
slidingTabLayout.setVisibility(View.GONE);
getSupportActionBar().setElevation(AndroidUtils.dpToPx(getMyApplication(), 4f));

View file

@ -13,6 +13,7 @@ public class WptPtEditor extends PointEditor {
private GPXFile gpxFile;
private WptPt wpt;
private boolean gpxSelected;
private boolean newGpxPointProcessing;
public static final String TAG = "WptPtEditorFragment";
@ -20,8 +21,16 @@ public class WptPtEditor extends PointEditor {
super(mapActivity);
}
public void setNewGpxPointProcessing(boolean newGpxPointProcessing) {
this.newGpxPointProcessing = newGpxPointProcessing;
}
public boolean isNewGpxPointProcessing() {
return newGpxPointProcessing;
}
public interface OnDismissListener {
void openTrackActivity();
void onDismiss();
}
public void setOnDismissListener(OnDismissListener listener) {

View file

@ -14,6 +14,7 @@ import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.mapcontextmenu.editors.WptPtEditor.OnDismissListener;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
@ -75,12 +76,13 @@ public class WptPtEditorFragment extends PointEditorFragment {
}
@Override
public void dismiss() {
super.dismiss();
WptPtEditor.OnDismissListener listener = editor.getOnDismissListener();
public void dismiss(boolean includingMenu) {
super.dismiss(includingMenu);
OnDismissListener listener = editor.getOnDismissListener();
if (listener != null) {
listener.openTrackActivity();
listener.onDismiss();
}
editor.setNewGpxPointProcessing(false);
editor.setOnDismissListener(null);
}
@ -91,10 +93,14 @@ public class WptPtEditorFragment extends PointEditorFragment {
@Override
public String getToolbarTitle() {
if (editor.isNew()) {
return getMapActivity().getResources().getString(R.string.context_menu_item_add_waypoint);
if (editor.isNewGpxPointProcessing()) {
return getMapActivity().getResources().getString(R.string.save_gpx_waypoint);
} else {
return getMapActivity().getResources().getString(R.string.shared_string_edit);
if (editor.isNew()) {
return getMapActivity().getResources().getString(R.string.context_menu_item_add_waypoint);
} else {
return getMapActivity().getResources().getString(R.string.shared_string_edit);
}
}
}

View file

@ -178,6 +178,10 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
}
private void addPoint(PointDescription pointDescription) {
Intent currentIntent = getTrackActivity().getIntent();
if (currentIntent != null) {
currentIntent.putExtra(TrackActivity.OPEN_POINTS_TAB, true);
}
final OsmandSettings settings = app.getSettings();
GPXFile gpx = getGpx();
LatLon location = settings.getLastKnownMapLocation();
@ -339,6 +343,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment {
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
getTrackActivity().getClearToolbar(false);
MenuItem mi = createMenuItem(menu, SEARCH_ID, R.string.search_poi_filter, R.drawable.ic_action_search_dark,
R.drawable.ic_action_search_dark, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
searchView = new SearchView(getActivity());

View file

@ -52,10 +52,12 @@ public class AddGpxPointBottomSheetHelper implements OnDismissListener {
if (pointDescription.isWpt()) {
WptPtEditor editor = activity.getContextMenu().getWptPtPointEditor();
editor.setOnDismissListener(AddGpxPointBottomSheetHelper.this);
editor.setNewGpxPointProcessing(true);
editor.add(gpx, latLon, titleText);
} else if (pointDescription.isRte()) {
RtePtEditor editor = activity.getContextMenu().getRtePtPointEditor();
editor.setOnDismissListener(AddGpxPointBottomSheetHelper.this);
editor.setNewGpxPointProcessing(true);
editor.add(gpx, latLon, titleText);
}
}
@ -126,9 +128,10 @@ public class AddGpxPointBottomSheetHelper implements OnDismissListener {
}
@Override
public void openTrackActivity() {
public void onDismiss() {
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getTrackActivity());
newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, newGpxPoint.getGpx().path);
newIntent.putExtra(TrackActivity.OPEN_POINTS_TAB, true);
newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
mapActivity.startActivity(newIntent);
}