use of net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter 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;
}
Aggregations