Show marker on map after click on history map markers list item
This commit is contained in:
parent
0dcb35b8d3
commit
7abae45ba8
2 changed files with 35 additions and 0 deletions
|
@ -2,6 +2,7 @@ package net.osmand.plus.mapmarkers;
|
|||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
@ -9,6 +10,8 @@ import android.view.LayoutInflater;
|
|||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.mapmarkers.adapters.MapMarkersHistoryAdapter;
|
||||
|
||||
|
@ -24,6 +27,18 @@ public class MapMarkersHistoryFragment extends Fragment {
|
|||
final MapActivity mapActivity = (MapActivity) getActivity();
|
||||
|
||||
adapter = new MapMarkersHistoryAdapter(mapActivity.getMyApplication());
|
||||
adapter.setAdapterListener(new MapMarkersHistoryAdapter.MapMarkersHistoryAdapterListener() {
|
||||
@Override
|
||||
public void onItemClick(View view) {
|
||||
int pos = recyclerView.indexOfChild(view);
|
||||
MapMarker marker = adapter.getItem(pos);
|
||||
mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(),
|
||||
15, new PointDescription(PointDescription.POINT_TYPE_LOCATION, marker.getPointDescription(mapActivity).getName()),
|
||||
false, null);
|
||||
MapActivity.launchMapActivityMoveToTop(mapActivity);
|
||||
((DialogFragment) getParentFragment()).dismiss();
|
||||
}
|
||||
});
|
||||
recyclerView.setAdapter(adapter);
|
||||
|
||||
return recyclerView;
|
||||
|
|
|
@ -16,15 +16,26 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<MapMarkerItem
|
|||
|
||||
private OsmandApplication app;
|
||||
private List<MapMarker> markers;
|
||||
private MapMarkersHistoryAdapterListener listener;
|
||||
|
||||
public MapMarkersHistoryAdapter(OsmandApplication app) {
|
||||
this.app = app;
|
||||
markers = app.getMapMarkersHelper().getMapMarkersHistory();
|
||||
}
|
||||
|
||||
public void setAdapterListener(MapMarkersHistoryAdapterListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MapMarkerItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
|
||||
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_new, viewGroup, false);
|
||||
view.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
listener.onItemClick(view);
|
||||
}
|
||||
});
|
||||
return new MapMarkerItemViewHolder(view);
|
||||
}
|
||||
|
||||
|
@ -45,4 +56,13 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<MapMarkerItem
|
|||
public int getItemCount() {
|
||||
return markers.size();
|
||||
}
|
||||
|
||||
public MapMarker getItem(int position) {
|
||||
return markers.get(position);
|
||||
}
|
||||
|
||||
public interface MapMarkersHistoryAdapterListener {
|
||||
|
||||
void onItemClick(View view);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue