From 7abae45ba8c8e0a02649333fb431da75387cba5e Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 1 Sep 2017 17:33:23 +0300 Subject: [PATCH] Show marker on map after click on history map markers list item --- .../mapmarkers/MapMarkersHistoryFragment.java | 15 ++++++++++++++ .../adapters/MapMarkersHistoryAdapter.java | 20 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java index cb81e08396..f5ef8026e3 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersHistoryFragment.java @@ -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; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java index ee9b3bdd86..2a0f8816d1 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersHistoryAdapter.java @@ -16,15 +16,26 @@ public class MapMarkersHistoryAdapter extends RecyclerView.Adapter 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