Fix opening context menu from show along the route dialog

This commit is contained in:
crimean 2019-04-14 12:49:49 +03:00
parent 91a13bf751
commit ac6b6bf788
10 changed files with 56 additions and 26 deletions

View file

@ -75,6 +75,7 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment {
private boolean initLayout = true;
private boolean wasDrawerDisabled;
private boolean paused;
private boolean dismissing;
private int minHalfY;
private int topScreenPosY;
@ -539,6 +540,7 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment {
public void onResume() {
super.onResume();
paused = false;
dismissing = false;
ViewParent parent = view.getParent();
if (parent != null && containerLayoutListener != null) {
((View) parent).addOnLayoutChangeListener(containerLayoutListener);
@ -906,7 +908,12 @@ public abstract class ContextMenuFragment extends BaseOsmAndFragment {
updateMainViewLayout(posY);
}
public boolean isDismissing() {
return dismissing;
}
public void dismiss() {
dismissing = true;
if (isSingleFragment()) {
FragmentActivity activity = getActivity();
if (activity != null) {

View file

@ -29,6 +29,7 @@ import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.helpers.WaypointHelper.AmenityLocationPoint;
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
import net.osmand.plus.routepreparationmenu.AddPointBottomSheetDialog;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
@ -326,8 +327,12 @@ public class WaypointDialogHelper {
if (!(a instanceof MapActivity)) {
return;
}
Object object = locationPoint;
if (locationPoint instanceof AmenityLocationPoint) {
object = ((AmenityLocationPoint) locationPoint).a;
}
app.getSettings().setMapLocationToShow(locationPoint.getLatitude(), locationPoint.getLongitude(),
15, locationPoint.getPointDescription(a), false, locationPoint);
15, locationPoint.getPointDescription(a), false, object);
MapActivity.launchMapActivityMoveToTop(a);
}

View file

@ -835,7 +835,7 @@ public class WaypointHelper {
}
}
private class AmenityLocationPoint implements LocationPoint {
public class AmenityLocationPoint implements LocationPoint {
Amenity a;

View file

@ -118,6 +118,9 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe
int routeIndex = 0;
int initialMenuState = MenuState.HEADER_ONLY;
Bundle args = getArguments();
if (args == null) {
args = savedInstanceState;
}
if (args != null) {
routeIndex = args.getInt(ROUTE_INDEX_KEY);
useRouteInfoMenu = args.getBoolean(USE_ROUTE_INFO_MENU_KEY, false);

View file

@ -1755,7 +1755,14 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
}
public boolean isVisible() {
return findMenuFragment() != null;
WeakReference<MapRouteInfoMenuFragment> fragmentRef = findMenuFragment();
if (fragmentRef != null) {
MapRouteInfoMenuFragment f = fragmentRef.get();
if (f != null) {
return f.isVisible() && !f.isDismissing();
}
}
return false;
}
public WeakReference<MapRouteInfoMenuFragment> findMenuFragment() {

View file

@ -4,8 +4,6 @@ import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.view.Gravity;
import android.view.LayoutInflater;
@ -36,7 +34,7 @@ import net.osmand.util.MapUtils;
import java.util.List;
public class MapRouteInfoMenuFragment extends ContextMenuFragment {
public static final String TAG = "MapRouteInfoMenuFragment";
public static final String TAG = MapRouteInfoMenuFragment.class.getName();
@Nullable
private MapRouteInfoMenu menu;
@ -73,11 +71,6 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
return 0;
}
@Override
public boolean isSingleFragment() {
return true;
}
@Override
public int getInitialMenuState() {
if (menu != null) {
@ -425,18 +418,6 @@ public class MapRouteInfoMenuFragment extends ContextMenuFragment {
.commitAllowingStateLoss();
}
public void dismiss() {
FragmentActivity activity = getActivity();
if (activity != null) {
try {
activity.getSupportFragmentManager().popBackStack(TAG,
FragmentManager.POP_BACK_STACK_INCLUSIVE);
} catch (Exception e) {
//
}
}
}
public void applyDayNightMode() {
MapActivity ctx = getMapActivity();
View mainView = getMainView();

View file

@ -130,6 +130,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
}
if (requestCode == ShowAlongTheRouteBottomSheet.REQUEST_CODE
&& resultCode == ShowAlongTheRouteBottomSheet.SHOW_CONTENT_ITEM_REQUEST_CODE) {
mapActivity.getMapRouteInfoMenu().hide();
dismiss();
}
}

View file

@ -47,6 +47,7 @@ public class ShowAlongTheRouteBottomSheet extends MenuBottomSheetDialogFragment
public static final int REQUEST_CODE = 2;
public static final int SHOW_CONTENT_ITEM_REQUEST_CODE = 3;
public static final String EXPAND_TYPE_KEY = "expand_type_key";
private OsmandApplication app;
@ -55,6 +56,7 @@ public class ShowAlongTheRouteBottomSheet extends MenuBottomSheetDialogFragment
private ExpandableListView expListView;
private ExpandableListAdapter adapter;
private int expandIndex = -1;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -71,6 +73,7 @@ public class ShowAlongTheRouteBottomSheet extends MenuBottomSheetDialogFragment
if (ctx == null || args == null) {
return;
}
int expandType = args.getInt(EXPAND_TYPE_KEY, -1);
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
final View titleView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.bottom_sheet_item_toolbar_title, null);
@ -93,6 +96,16 @@ public class ShowAlongTheRouteBottomSheet extends MenuBottomSheetDialogFragment
items.add(titleItem);
final ContentItem contentItem = getAdapterContentItems();
if (expandType != -1) {
ArrayList<ContentItem> subItems = contentItem.getSubItems();
for (int i = 0; i < subItems.size(); i++) {
ContentItem item = subItems.get(i);
if (expandType == item.type) {
expandIndex = i;
break;
}
}
}
items.add(new SimpleDividerItem(app));
@ -175,6 +188,10 @@ public class ShowAlongTheRouteBottomSheet extends MenuBottomSheetDialogFragment
public void onResume() {
super.onResume();
app.getRoutingHelper().addListener(this);
if (expandIndex != -1) {
expListView.expandGroup(expandIndex);
setupHeightAndBackground(getView());
}
}
@ -225,12 +242,12 @@ public class ShowAlongTheRouteBottomSheet extends MenuBottomSheetDialogFragment
convertView.findViewById(R.id.waypoint_container).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
WaypointDialogHelper.showOnMap(app, mapActivity, item.point.getPoint(), false);
Fragment fragment = getTargetFragment();
if (fragment != null) {
fragment.onActivityResult(getTargetRequestCode(), SHOW_CONTENT_ITEM_REQUEST_CODE, null);
}
dismiss();
WaypointDialogHelper.showOnMap(app, mapActivity, item.point.getPoint(), false);
}
});

View file

@ -100,6 +100,9 @@ public class WaypointsFragment extends BaseOsmAndFragment implements ObservableS
}
AndroidUtils.addStatusBarPadding21v(mapActivity, view);
Bundle args = getArguments();
if (args == null) {
args = savedInstanceState;
}
if (args != null) {
useRouteInfoMenu = args.getBoolean(USE_ROUTE_INFO_MENU_KEY, false);
}

View file

@ -2,6 +2,7 @@ package net.osmand.plus.views.mapwidgets;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.ColorInt;
import android.support.annotation.ColorRes;
import android.support.annotation.DrawableRes;
@ -35,7 +36,7 @@ import net.osmand.plus.helpers.WaypointDialogHelper;
import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
import net.osmand.plus.routepreparationmenu.WaypointsFragment;
import net.osmand.plus.routepreparationmenu.ShowAlongTheRouteBottomSheet;
import net.osmand.plus.routing.RouteDirectionInfo;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
@ -1005,7 +1006,12 @@ public class MapInfoWidgetsFactory {
@Override
public void onClick(View view) {
map.hideContextAndRouteInfoMenues();
WaypointsFragment.showInstance(map.getSupportFragmentManager());
ShowAlongTheRouteBottomSheet fragment = new ShowAlongTheRouteBottomSheet();
Bundle args = new Bundle();
args.putInt(ShowAlongTheRouteBottomSheet.EXPAND_TYPE_KEY, pnt.type);
fragment.setArguments(args);
fragment.setUsedOnMap(false);
fragment.show(map.getSupportFragmentManager(), ShowAlongTheRouteBottomSheet.TAG);
}
});
remove.setOnClickListener(new OnClickListener() {