Search in sources :

Example 16 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class MapMarkersActiveFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    final MapActivity mapActivity = (MapActivity) getActivity();
    final View mainView = inflater.inflate(R.layout.fragment_map_markers_active, container, false);
    final EmptyStateRecyclerView recyclerView = (EmptyStateRecyclerView) mainView.findViewById(R.id.list);
    recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
    adapter = new MapMarkersActiveAdapter(mapActivity);
    final ItemTouchHelper touchHelper = new ItemTouchHelper(new MapMarkersItemTouchHelperCallback(mapActivity, adapter));
    touchHelper.attachToRecyclerView(recyclerView);
    adapter.setAdapterListener(new MapMarkersActiveAdapterListener() {

        private int fromPosition;

        private int toPosition;

        @Override
        public void onItemClick(View view) {
            int pos = recyclerView.getChildAdapterPosition(view);
            if (pos == RecyclerView.NO_POSITION) {
                return;
            }
            MapMarker marker = adapter.getItem(pos);
            OsmandApplication app = mapActivity.getMyApplication();
            if (app.getSettings().SELECT_MARKER_ON_SINGLE_TAP.get()) {
                app.getMapMarkersHelper().moveMarkerToTop(marker);
                updateAdapter();
            } else {
                FavouritePoint fav = marker.favouritePoint == null ? app.getFavorites().getVisibleFavByLatLon(marker.point) : marker.favouritePoint;
                if (fav != null) {
                    showMap(marker.point, fav.getPointDescription(), fav);
                    return;
                }
                WptPt pt = marker.wptPt == null ? app.getSelectedGpxHelper().getVisibleWayPointByLatLon(marker.point) : marker.wptPt;
                if (pt != null) {
                    showMap(marker.point, pt.getPointDescription(mapActivity), pt);
                    return;
                }
                Amenity mapObj = mapActivity.getMapLayers().getMapMarkersLayer().getMapObjectByMarker(marker);
                PointDescription desc = mapObj == null ? marker.getPointDescription(mapActivity) : mapActivity.getMapLayers().getPoiMapLayer().getObjectName(mapObj);
                showMap(marker.point, desc, mapObj == null ? marker : mapObj);
            }
        }

        private void showMap(LatLon latLon, PointDescription desc, Object objToShow) {
            mapActivity.getMyApplication().getSettings().setMapLocationToShow(latLon.getLatitude(), latLon.getLongitude(), 15, desc, true, objToShow);
            MapActivity.launchMapActivityMoveToTop(mapActivity);
            ((DialogFragment) getParentFragment()).dismiss();
        }

        @Override
        public void onDragStarted(RecyclerView.ViewHolder holder) {
            compassUpdateAllowed = false;
            fromPosition = holder.getAdapterPosition();
            touchHelper.startDrag(holder);
        }

        @Override
        public void onDragOrSwipeEnded(RecyclerView.ViewHolder holder) {
            compassUpdateAllowed = true;
            toPosition = holder.getAdapterPosition();
            if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
                hideSnackbar();
                mapActivity.getMyApplication().getMapMarkersHelper().reorderActiveMarkersIfNeeded();
                adapter.notifyDataSetChanged();
            }
        }

        @Override
        public void onSwipeStarted() {
            compassUpdateAllowed = false;
        }
    });
    final View emptyView = mainView.findViewById(R.id.empty_view);
    ImageView emptyImageView = (ImageView) emptyView.findViewById(R.id.empty_state_image_view);
    if (Build.VERSION.SDK_INT >= 18) {
        emptyImageView.setImageResource(mapActivity.getMyApplication().getSettings().isLightContent() ? R.drawable.ic_empty_state_marker_list_day : R.drawable.ic_empty_state_marker_list_night);
    } else {
        emptyImageView.setVisibility(View.INVISIBLE);
    }
    recyclerView.setEmptyView(emptyView);
    recyclerView.setAdapter(adapter);
    recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            compassUpdateAllowed = newState == RecyclerView.SCROLL_STATE_IDLE;
        }
    });
    return mainView;
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) Amenity(net.osmand.data.Amenity) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) OsmandApplication(net.osmand.plus.OsmandApplication) FavouritePoint(net.osmand.data.FavouritePoint) EmptyStateRecyclerView(net.osmand.plus.widgets.EmptyStateRecyclerView) MapMarkersActiveAdapterListener(net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter.MapMarkersActiveAdapterListener) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) EmptyStateRecyclerView(net.osmand.plus.widgets.EmptyStateRecyclerView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) FavouritePoint(net.osmand.data.FavouritePoint) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) LatLon(net.osmand.data.LatLon) MapMarkersItemTouchHelperCallback(net.osmand.plus.mapmarkers.adapters.MapMarkersItemTouchHelperCallback) PointDescription(net.osmand.data.PointDescription) EmptyStateRecyclerView(net.osmand.plus.widgets.EmptyStateRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) MapMarkersActiveAdapter(net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter) ImageView(android.widget.ImageView) MapActivity(net.osmand.plus.activities.MapActivity) Nullable(android.support.annotation.Nullable)

Example 17 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class FavouritesAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
    if (holder instanceof FavouritesViewHolder) {
        OsmandApplication app = (OsmandApplication) ((Activity) context).getApplication();
        IconsCache iconsCache = app.getIconsCache();
        FavouritesViewHolder favouritesViewHolder = (FavouritesViewHolder) holder;
        FavouritePoint favouritePoint = getItem(position);
        favouritesViewHolder.title.setText(favouritePoint.getName());
        if (favouritePoint.getCategory().equals("")) {
            favouritesViewHolder.description.setText(R.string.shared_string_favorites);
        } else {
            favouritesViewHolder.description.setText(favouritePoint.getCategory());
        }
        Location myloc = app.getLocationProvider().getLastKnownLocation();
        favouritesViewHolder.favouriteImage.setImageDrawable(FavoriteImageDrawable.getOrCreate(context, favouritePoint.getColor(), false));
        if (myloc == null) {
            return;
        }
        float dist = (float) MapUtils.getDistance(favouritePoint.getLatitude(), favouritePoint.getLongitude(), myloc.getLatitude(), myloc.getLongitude());
        favouritesViewHolder.distance.setText(OsmAndFormatter.getFormattedDistance(dist, app));
        favouritesViewHolder.arrowImage.setImageDrawable(iconsCache.getIcon(R.drawable.ic_direction_arrow));
        DashLocationFragment.updateLocationView(useCenter, location, heading, favouritesViewHolder.arrowImage, favouritesViewHolder.distance, favouritePoint.getLatitude(), favouritePoint.getLongitude(), screenOrientation, app, context);
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) FavouritePoint(net.osmand.data.FavouritePoint) IconsCache(net.osmand.plus.IconsCache) Location(net.osmand.Location)

Example 18 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class FavouritesBottomSheetMenuFragment method sortFavourites.

private void sortFavourites() {
    if (location != null) {
        latLon = new LatLon(location.getLatitude(), location.getLongitude());
    } else if (sortByDist) {
        return;
    }
    final Collator inst = Collator.getInstance();
    Collections.sort(favouritePoints, new Comparator<FavouritePoint>() {

        @Override
        public int compare(FavouritePoint lhs, FavouritePoint rhs) {
            if (sortByDist) {
                double ld = MapUtils.getDistance(latLon, lhs.getLatitude(), lhs.getLongitude());
                double rd = MapUtils.getDistance(latLon, rhs.getLatitude(), rhs.getLongitude());
                return Double.compare(ld, rd);
            }
            return inst.compare(lhs.getName(), rhs.getName());
        }
    });
    sortByDist = !sortByDist;
    isSorted = true;
    adapter.notifyDataSetChanged();
    recyclerView.getLayoutManager().scrollToPosition(0);
}
Also used : LatLon(net.osmand.data.LatLon) FavouritePoint(net.osmand.data.FavouritePoint) Collator(java.text.Collator)

Example 19 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class OsmandAidlApi method removeFavorite.

boolean removeFavorite(AFavorite favorite) {
    if (favorite != null) {
        FavouritesDbHelper favoritesHelper = app.getFavorites();
        List<FavouritePoint> favorites = favoritesHelper.getFavouritePoints();
        for (FavouritePoint f : favorites) {
            if (f.getName().equals(favorite.getName()) && f.getCategory().equals(favorite.getCategory()) && f.getLatitude() == favorite.getLat() && f.getLongitude() == favorite.getLon()) {
                favoritesHelper.deleteFavourite(f);
                refreshMap();
                return true;
            }
        }
        return false;
    } else {
        return false;
    }
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) FavouritesDbHelper(net.osmand.plus.FavouritesDbHelper)

Example 20 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class FavouritesDbHelper method checkDuplicates.

public static AlertDialog.Builder checkDuplicates(FavouritePoint p, FavouritesDbHelper fdb, Context uiContext) {
    boolean emoticons = false;
    String index = "";
    int number = 0;
    String name = checkEmoticons(p.getName());
    String category = checkEmoticons(p.getCategory());
    p.setCategory(category);
    String description = null;
    if (p.getDescription() != null) {
        description = checkEmoticons(p.getDescription());
    }
    p.setDescription(description);
    if (name.length() != p.getName().length()) {
        emoticons = true;
    }
    boolean fl = true;
    while (fl) {
        fl = false;
        for (FavouritePoint fp : fdb.getFavouritePoints()) {
            if (fp.getName().equals(name) && p.getLatitude() != fp.getLatitude() && p.getLongitude() != fp.getLongitude()) {
                number++;
                index = " (" + number + ")";
                name = p.getName() + index;
                fl = true;
                break;
            }
        }
    }
    if ((index.length() > 0 || emoticons)) {
        AlertDialog.Builder builder = new AlertDialog.Builder(uiContext);
        builder.setTitle(R.string.fav_point_dublicate);
        if (emoticons) {
            builder.setMessage(uiContext.getString(R.string.fav_point_emoticons_message, name));
        } else {
            builder.setMessage(uiContext.getString(R.string.fav_point_dublicate_message, name));
        }
        p.setName(name);
        return builder;
    }
    return null;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) FavouritePoint(net.osmand.data.FavouritePoint) FavouritePoint(net.osmand.data.FavouritePoint)

Aggregations

FavouritePoint (net.osmand.data.FavouritePoint)51 LatLon (net.osmand.data.LatLon)16 PointDescription (net.osmand.data.PointDescription)10 FavouritesDbHelper (net.osmand.plus.FavouritesDbHelper)10 View (android.view.View)9 ArrayList (java.util.ArrayList)9 AlertDialog (android.support.v7.app.AlertDialog)8 OsmandApplication (net.osmand.plus.OsmandApplication)8 TextView (android.widget.TextView)7 WptPt (net.osmand.plus.GPXUtilities.WptPt)7 MapActivity (net.osmand.plus.activities.MapActivity)7 DialogInterface (android.content.DialogInterface)6 ImageView (android.widget.ImageView)6 Amenity (net.osmand.data.Amenity)6 Paint (android.graphics.Paint)5 AdapterView (android.widget.AdapterView)5 ListView (android.widget.ListView)5 FavoriteGroup (net.osmand.plus.FavouritesDbHelper.FavoriteGroup)5 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)5 Collator (java.text.Collator)4