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;
}
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);
}
}
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);
}
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;
}
}
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;
}
Aggregations