Create context menu for synced items

This commit is contained in:
PavelRatushny 2017-11-20 17:52:34 +02:00
parent 0bac55aab6
commit d7b5732b4b
6 changed files with 112 additions and 20 deletions

View file

@ -587,6 +587,24 @@ public class MapMarkersHelper {
return false;
}
public MapMarker getMapMarker(WptPt wptPt) {
for (MapMarker marker : mapMarkers) {
if (marker.wptPt == wptPt) {
return marker;
}
}
return null;
}
public MapMarker getMapMarker(FavouritePoint favouritePoint) {
for (MapMarker marker : mapMarkers) {
if (marker.favouritePoint == favouritePoint) {
return marker;
}
}
return null;
}
private void addNewMarkerIfNeeded(MarkersSyncGroup group, List<MapMarker> markers, LatLon latLon, String name, boolean enabled, FavouritePoint favouritePoint, WptPt wptPt) {
boolean exists = false;

View file

@ -1,6 +1,7 @@
package net.osmand.plus.mapcontextmenu.controllers;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.support.v4.app.Fragment;
import net.osmand.data.Amenity;
@ -8,6 +9,9 @@ import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.TransportStop;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
@ -24,6 +28,32 @@ public class FavouritePointMenuController extends MenuController {
public FavouritePointMenuController(MapActivity mapActivity, PointDescription pointDescription, final FavouritePoint fav) {
super(new FavouritePointMenuBuilder(mapActivity, fav), pointDescription, mapActivity);
this.fav = fav;
final MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
final MapMarker mapMarker = markersHelper.getMapMarker(fav);
if (mapMarker != null) {
leftTitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
markersHelper.moveMapMarkerToHistory(mapMarker);
getMapActivity().getContextMenu().close();
}
};
leftTitleButtonController.needColorizeIcon = false;
leftTitleButtonController.caption = getMapActivity().getString(R.string.mark_passed);
leftTitleButtonController.leftIconId = isLight() ? R.drawable.passed_icon_light : R.drawable.passed_icon_dark;
leftSubtitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
markersHelper.moveMarkerToTop(mapMarker);
getMapActivity().getContextMenu().close();
}
};
leftSubtitleButtonController.caption = getMapActivity().getString(R.string.show_on_top_bar);
leftSubtitleButtonController.leftIcon = createShowOnTopbarIcon();
}
}
@Override
@ -114,4 +144,12 @@ public class FavouritePointMenuController extends MenuController {
addMyLocationToPlainItems(latLon);
}
}
private Drawable createShowOnTopbarIcon() {
IconsCache ic = getMapActivity().getMyApplication().getIconsCache();
Drawable background = ic.getIcon(R.drawable.ic_action_device_top,
isLight() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark);
Drawable topbar = ic.getIcon(R.drawable.ic_action_device_topbar, R.color.dashboard_blue);
return new LayerDrawable(new Drawable[]{background, topbar});
}
}

View file

@ -1,10 +1,14 @@
package net.osmand.plus.mapcontextmenu.controllers;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.support.v4.content.ContextCompat;
import net.osmand.data.PointDescription;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.IconsCache;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
@ -19,6 +23,32 @@ public class WptPtMenuController extends MenuController {
public WptPtMenuController(MapActivity mapActivity, PointDescription pointDescription, WptPt wpt) {
super(new WptPtMenuBuilder(mapActivity, wpt), pointDescription, mapActivity);
this.wpt = wpt;
final MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
final MapMarker mapMarker = markersHelper.getMapMarker(wpt);
if (mapMarker != null) {
leftTitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
markersHelper.moveMapMarkerToHistory(mapMarker);
getMapActivity().getContextMenu().close();
}
};
leftTitleButtonController.needColorizeIcon = false;
leftTitleButtonController.caption = getMapActivity().getString(R.string.mark_passed);
leftTitleButtonController.leftIconId = isLight() ? R.drawable.passed_icon_light : R.drawable.passed_icon_dark;
leftSubtitleButtonController = new TitleButtonController() {
@Override
public void buttonPressed() {
markersHelper.moveMarkerToTop(mapMarker);
getMapActivity().getContextMenu().close();
}
};
leftSubtitleButtonController.caption = getMapActivity().getString(R.string.show_on_top_bar);
leftSubtitleButtonController.leftIcon = createShowOnTopbarIcon();
}
}
@Override
@ -79,4 +109,12 @@ public class WptPtMenuController extends MenuController {
public String getCommonTypeStr() {
return getMapActivity().getString(R.string.gpx_wpt);
}
private Drawable createShowOnTopbarIcon() {
IconsCache ic = getMapActivity().getMyApplication().getIconsCache();
Drawable background = ic.getIcon(R.drawable.ic_action_device_top,
isLight() ? R.color.on_map_icon_color : R.color.ctx_menu_info_text_dark);
Drawable topbar = ic.getIcon(R.drawable.ic_action_device_topbar, R.color.dashboard_blue);
return new LayerDrawable(new Drawable[]{background, topbar});
}
}

View file

@ -183,9 +183,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
int ex = (int) point.x;
int ey = (int) point.y;
for (FavouritePoint n : getPoints()) {
if (!mapMarkersHelper.isSynced(n)) {
getFavFromPoint(tb, res, r, ex, ey, n);
}
getFavFromPoint(tb, res, r, ex, ey, n);
}
}

View file

@ -542,15 +542,13 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
int ex = (int) point.x;
int ey = (int) point.y;
for (SelectedGpxFile g : selectedGpxHelper.getSelectedGPXFiles()) {
if (!isSynced(g)) {
List<WptPt> pts = getListStarPoints(g);
// int fcolor = g.getColor() == 0 ? clr : g.getColor();
for (WptPt n : pts) {
int x = (int) tb.getPixXFromLatLon(n.lat, n.lon);
int y = (int) tb.getPixYFromLatLon(n.lat, n.lon);
if (calculateBelongs(ex, ey, x, y, r)) {
res.add(n);
}
List<WptPt> pts = getListStarPoints(g);
// int fcolor = g.getColor() == 0 ? clr : g.getColor();
for (WptPt n : pts) {
int x = (int) tb.getPixXFromLatLon(n.lat, n.lon);
int y = (int) tb.getPixYFromLatLon(n.lat, n.lon);
if (calculateBelongs(ex, ey, x, y, r)) {
res.add(n);
}
}
}

View file

@ -512,14 +512,16 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
int r = getRadiusPoi(tileBox);
for (int i = 0; i < markers.size(); i++) {
MapMarker marker = markers.get(i);
LatLon latLon = marker.point;
if (latLon != null) {
int ex = (int) point.x;
int ey = (int) point.y;
int x = (int) tileBox.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
int y = (int) tileBox.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
if (calculateBelongs(ex, ey, x, y, r)) {
o.add(marker);
if (marker.wptPt == null && marker.favouritePoint == null) {
LatLon latLon = marker.point;
if (latLon != null) {
int ex = (int) point.x;
int ey = (int) point.y;
int x = (int) tileBox.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
int y = (int) tileBox.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
if (calculateBelongs(ex, ey, x, y, r)) {
o.add(marker);
}
}
}
}