Add opening of marker menu on map from groups

This commit is contained in:
Alex 2017-10-19 12:01:45 +03:00 committed by Alexander Sytnyk
parent e19731c25a
commit 6603af405c
2 changed files with 37 additions and 2 deletions

View file

@ -10,6 +10,7 @@ import android.graphics.Rect;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.LinearLayoutManager;
@ -203,6 +204,24 @@ public class MapMarkersGroupsFragment extends Fragment implements OsmAndCompassL
itemTouchHelper.attachToRecyclerView(recyclerView); itemTouchHelper.attachToRecyclerView(recyclerView);
adapter = new MapMarkersGroupsAdapter(mapActivity); adapter = new MapMarkersGroupsAdapter(mapActivity);
adapter.setListener(new MapMarkersGroupsAdapter.MapMarkersGroupsAdapterListener() {
@Override
public void onItemClick(View view) {
int pos = recyclerView.getChildAdapterPosition(view);
if (pos == RecyclerView.NO_POSITION) {
return;
}
Object item = adapter.getItem(pos);
if (item instanceof MapMarker) {
MapMarker marker = (MapMarker) item;
mapActivity.getMyApplication().getSettings()
.setMapLocationToShow(marker.getLatitude(), marker.getLongitude(), 15, null, false, null);
MapActivity.launchMapActivityMoveToTop(mapActivity);
MarkerMenuOnMapFragment.showInstance(mapActivity, marker);
((DialogFragment) getParentFragment()).dismiss();
}
}
});
recyclerView.setAdapter(adapter); recyclerView.setAdapter(adapter);
return recyclerView; return recyclerView;
} }

View file

@ -12,9 +12,9 @@ import android.widget.TextView;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper.GroupHeader;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup; import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.MapMarkersHelper.GroupHeader;
import net.osmand.plus.MapMarkersHelper.ShowHideHistoryButton; import net.osmand.plus.MapMarkersHelper.ShowHideHistoryButton;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
@ -52,6 +52,12 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
private List<MapMarker> showDirectionMarkers; private List<MapMarker> showDirectionMarkers;
private Snackbar snackbar; private Snackbar snackbar;
private MapMarkersGroupsAdapterListener listener;
public void setListener(MapMarkersGroupsAdapterListener listener) {
this.listener = listener;
}
public MapMarkersGroupsAdapter(MapActivity mapActivity) { public MapMarkersGroupsAdapter(MapActivity mapActivity) {
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
app = mapActivity.getMyApplication(); app = mapActivity.getMyApplication();
@ -150,7 +156,12 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) { public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
if (viewType == MARKER_TYPE) { if (viewType == MARKER_TYPE) {
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.setClickable(true); view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
listener.onItemClick(view);
}
});
return new MapMarkerItemViewHolder(view); return new MapMarkerItemViewHolder(view);
} else if (viewType == HEADER_TYPE) { } else if (viewType == HEADER_TYPE) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_header, viewGroup, false); View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_header, viewGroup, false);
@ -476,4 +487,9 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
} }
return index; return index;
} }
public interface MapMarkersGroupsAdapterListener {
void onItemClick(View view);
}
} }