Move to marker on map on list item click

This commit is contained in:
Alexander Sytnyk 2017-08-30 13:11:59 +03:00
parent 7e52ff30e9
commit 396dec1482
2 changed files with 14 additions and 4 deletions

View file

@ -2,14 +2,15 @@ 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;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter;
import net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter.MapMarkersActiveAdapterListener;
@ -21,13 +22,18 @@ public class MapMarkersActiveFragment extends Fragment {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final RecyclerView recyclerView = new RecyclerView(getContext());
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
MapActivity mapActivity = (MapActivity) getActivity();
final MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null) {
MapMarkersActiveAdapter adapter = new MapMarkersActiveAdapter(mapActivity);
final MapMarkersActiveAdapter adapter = new MapMarkersActiveAdapter(mapActivity);
adapter.setAdapterListener(new MapMarkersActiveAdapterListener() {
@Override
public void onItemClick(View view) {
Toast.makeText(getContext(), recyclerView.indexOfChild(view) + "", Toast.LENGTH_SHORT).show();
int pos = recyclerView.indexOfChild(view);
MapMarker marker = adapter.getItem(pos);
mapActivity.getMyApplication().getSettings().setMapLocationToShow(marker.getLatitude(), marker.getLongitude(),
15, marker.getPointDescription(mapActivity), true, marker);
MapActivity.launchMapActivityMoveToTop(mapActivity);
((DialogFragment) getParentFragment()).dismiss();
}
});
recyclerView.setAdapter(adapter);

View file

@ -92,6 +92,10 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
return markers.size();
}
public MapMarker getItem(int position) {
return markers.get(position);
}
private void calculateLocationParams() {
MapViewTrackingUtilities utilities = mapActivity.getMapViewTrackingUtilities();