Search in sources :

Example 1 with PointType

use of net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.PointType in project Osmand by osmandapp.

the class AddPointBottomSheetDialog method getAdapterOnClickListener.

private OnClickListener getAdapterOnClickListener(final List<Object> items) {
    return new OnClickListener() {

        @Override
        public void onClick(View v) {
            MapActivity mapActivity = (MapActivity) getActivity();
            RecyclerView.ViewHolder viewHolder = (RecyclerView.ViewHolder) v.getTag();
            int position = viewHolder != null ? viewHolder.getAdapterPosition() : RecyclerView.NO_POSITION;
            if (mapActivity == null || position == RecyclerView.NO_POSITION) {
                return;
            }
            Object item = items.get(position);
            if (item.equals(FAVORITES)) {
                openFavoritesDialog();
            } else if (item.equals(MARKERS)) {
                MapRouteInfoMenu menu = mapActivity.getMapRouteInfoMenu();
                menu.selectMapMarker(-1, pointType);
                dismiss();
            } else if (item instanceof MapMarker) {
                MapRouteInfoMenu menu = mapActivity.getMapRouteInfoMenu();
                menu.selectMapMarker((MapMarker) item, pointType);
                dismiss();
            } else {
                TargetPointsHelper targetPointsHelper = mapActivity.getMyApplication().getTargetPointsHelper();
                Pair<LatLon, PointDescription> pair = getLocationAndDescrFromItem(item);
                LatLon ll = pair.first;
                PointDescription name = pair.second;
                if (ll == null) {
                    if (item instanceof PointType) {
                        AddPointBottomSheetDialog.showInstance(mapActivity, (PointType) item);
                    } else {
                        dismiss();
                    }
                } else {
                    FavouritesHelper favorites = requiredMyApplication().getFavoritesHelper();
                    switch(pointType) {
                        case START:
                            targetPointsHelper.setStartPoint(ll, true, name);
                            break;
                        case TARGET:
                            targetPointsHelper.navigateToPoint(ll, true, -1, name);
                            break;
                        case INTERMEDIATE:
                            targetPointsHelper.navigateToPoint(ll, true, targetPointsHelper.getIntermediatePoints().size(), name);
                            break;
                        case HOME:
                            favorites.setSpecialPoint(ll, FavouritePoint.SpecialPointType.HOME, null);
                            break;
                        case WORK:
                            favorites.setSpecialPoint(ll, FavouritePoint.SpecialPointType.WORK, null);
                            break;
                        case PARKING:
                            favorites.setSpecialPoint(ll, FavouritePoint.SpecialPointType.PARKING, null);
                            break;
                    }
                    dismiss();
                }
            }
        }
    };
}
Also used : MapMarker(net.osmand.plus.mapmarkers.MapMarker) FavouritesHelper(net.osmand.plus.myplaces.FavouritesHelper) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) FavouritePoint(net.osmand.data.FavouritePoint) TargetPoint(net.osmand.plus.helpers.TargetPointsHelper.TargetPoint) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) OnClickListener(android.view.View.OnClickListener) PointType(net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.PointType) RecyclerView(androidx.recyclerview.widget.RecyclerView) TargetPointsHelper(net.osmand.plus.helpers.TargetPointsHelper) MapActivity(net.osmand.plus.activities.MapActivity)

Example 2 with PointType

use of net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.PointType in project Osmand by osmandapp.

the class AddPointBottomSheetDialog method getLocationAndDescrFromItem.

private Pair<LatLon, PointDescription> getLocationAndDescrFromItem(Object item) {
    PointDescription name = null;
    LatLon ll = null;
    if (item instanceof FavouritePoint) {
        FavouritePoint point = (FavouritePoint) item;
        ll = new LatLon(point.getLatitude(), point.getLongitude());
        name = point.getPointDescription(requireActivity());
    } else if (item instanceof PointType) {
        MapActivity mapActivity = (MapActivity) getActivity();
        if (mapActivity != null) {
            FavouritesHelper favorites = mapActivity.getMyApplication().getFavoritesHelper();
            FavouritePoint point = null;
            if (item == PointType.HOME) {
                point = favorites.getSpecialPoint(FavouritePoint.SpecialPointType.HOME);
            } else if (item == PointType.WORK) {
                point = favorites.getSpecialPoint(FavouritePoint.SpecialPointType.WORK);
            } else if (item == PointType.PARKING) {
                point = favorites.getSpecialPoint(FavouritePoint.SpecialPointType.PARKING);
            }
            if (point != null) {
                ll = new LatLon(point.getLatitude(), point.getLongitude());
                name = point.getPointDescription(mapActivity);
            }
        }
    }
    return new Pair<>(ll, name);
}
Also used : LatLon(net.osmand.data.LatLon) FavouritePoint(net.osmand.data.FavouritePoint) FavouritesHelper(net.osmand.plus.myplaces.FavouritesHelper) PointDescription(net.osmand.data.PointDescription) PointType(net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.PointType) MapActivity(net.osmand.plus.activities.MapActivity) Pair(android.util.Pair)

Aggregations

FavouritePoint (net.osmand.data.FavouritePoint)2 LatLon (net.osmand.data.LatLon)2 PointDescription (net.osmand.data.PointDescription)2 MapActivity (net.osmand.plus.activities.MapActivity)2 FavouritesHelper (net.osmand.plus.myplaces.FavouritesHelper)2 PointType (net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.PointType)2 Pair (android.util.Pair)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 TargetPointsHelper (net.osmand.plus.helpers.TargetPointsHelper)1 TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)1 MapMarker (net.osmand.plus.mapmarkers.MapMarker)1