Show marker on map after click on history map markers list item

This commit is contained in:
Alex 2017-09-01 17:33:23 +03:00
parent 0dcb35b8d3
commit 7abae45ba8
2 changed files with 35 additions and 0 deletions

View file

@ -2,6 +2,7 @@ package net.osmand.plus.mapmarkers;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView;
@ -9,6 +10,8 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; 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.activities.MapActivity;
import net.osmand.plus.mapmarkers.adapters.MapMarkersHistoryAdapter; import net.osmand.plus.mapmarkers.adapters.MapMarkersHistoryAdapter;
@ -24,6 +27,18 @@ public class MapMarkersHistoryFragment extends Fragment {
final MapActivity mapActivity = (MapActivity) getActivity(); final MapActivity mapActivity = (MapActivity) getActivity();
adapter = new MapMarkersHistoryAdapter(mapActivity.getMyApplication()); 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); recyclerView.setAdapter(adapter);
return recyclerView; return recyclerView;

View file

@ -16,15 +16,26 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<MapMarkerItem
private OsmandApplication app; private OsmandApplication app;
private List<MapMarker> markers; private List<MapMarker> markers;
private MapMarkersHistoryAdapterListener listener;
public MapMarkersHistoryAdapter(OsmandApplication app) { public MapMarkersHistoryAdapter(OsmandApplication app) {
this.app = app; this.app = app;
markers = app.getMapMarkersHelper().getMapMarkersHistory(); markers = app.getMapMarkersHelper().getMapMarkersHistory();
} }
public void setAdapterListener(MapMarkersHistoryAdapterListener listener) {
this.listener = listener;
}
@Override @Override
public MapMarkerItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) { public MapMarkerItemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_new, viewGroup, false); 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); return new MapMarkerItemViewHolder(view);
} }
@ -45,4 +56,13 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter<MapMarkerItem
public int getItemCount() { public int getItemCount() {
return markers.size(); return markers.size();
} }
public MapMarker getItem(int position) {
return markers.get(position);
}
public interface MapMarkersHistoryAdapterListener {
void onItemClick(View view);
}
} }