Fixed bug with wrong time left in context menu when adding parking

This commit is contained in:
Alexey Kulish 2015-11-01 18:29:10 +03:00
parent 2e331cbd8b
commit 5a25ad165c
4 changed files with 131 additions and 5 deletions

View file

@ -7,6 +7,8 @@ import net.osmand.data.Amenity;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.GPXUtilities;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
@ -23,6 +25,7 @@ import net.osmand.plus.mapcontextmenu.controllers.ParkingPositionMenuController;
import net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController;
import net.osmand.plus.mapcontextmenu.controllers.AudioVideoNoteMenuController;
import net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController;
import net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController;
import net.osmand.plus.mapcontextmenu.other.ShareMenu;
import net.osmand.plus.osmedit.OsmPoint;
import net.osmand.plus.osmo.OsMoGroupsStorage.OsMoDevice;
@ -99,6 +102,8 @@ public abstract class MenuController extends BaseMenuController {
menuController = new AudioVideoNoteMenuController(app, mapActivity, (Recording) object);
} else if (object instanceof OsmPoint) {
menuController = new EditPOIMenuController(app, mapActivity, pointDescription, (OsmPoint) object);
} else if (object instanceof WptPt) {
menuController = new WptPtMenuController(app, mapActivity, (WptPt) object);
} else if (object instanceof LatLon) {
if (pointDescription.isParking()) {
menuController = new ParkingPositionMenuController(app, mapActivity, pointDescription);

View file

@ -0,0 +1,36 @@
package net.osmand.plus.mapcontextmenu.builders;
import android.view.View;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
import net.osmand.util.Algorithms;
public class WptPtMenuBuilder extends MenuBuilder {
private final WptPt wpt;
public WptPtMenuBuilder(OsmandApplication app, final WptPt wpt) {
super(app);
this.wpt = wpt;
}
@Override
protected boolean needBuildPlainMenuItems() {
return false;
}
@Override
public void build(View view) {
super.build(view);
if (!Algorithms.isEmpty(wpt.desc)) {
buildRow(view, R.drawable.ic_action_note_dark, wpt.desc, 0);
}
buildPlainMenuItems(view);
}
}

View file

@ -0,0 +1,77 @@
package net.osmand.plus.mapcontextmenu.controllers;
import android.graphics.drawable.Drawable;
import net.osmand.plus.GPXUtilities.WptPt;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.mapcontextmenu.builders.FavouritePointMenuBuilder;
import net.osmand.plus.mapcontextmenu.builders.WptPtMenuBuilder;
import net.osmand.util.Algorithms;
public class WptPtMenuController extends MenuController {
private WptPt wpt;
public WptPtMenuController(OsmandApplication app, MapActivity mapActivity, final WptPt wpt) {
super(new WptPtMenuBuilder(app, wpt), mapActivity);
this.wpt = wpt;
}
@Override
protected int getSupportedMenuStatesPortrait() {
return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN;
}
/*
@Override
public boolean handleSingleTapOnMap() {
Fragment fragment = getMapActivity().getSupportFragmentManager().findFragmentByTag(FavoritePointEditor.TAG);
if (fragment != null) {
((FavoritePointEditorFragment)fragment).dismiss();
return true;
}
return false;
}
*/
@Override
public boolean needStreetName() {
return false;
}
@Override
public boolean needTypeStr() {
return true;
}
@Override
public Drawable getLeftIcon() {
return FavoriteImageDrawable.getOrCreate(getMapActivity().getMyApplication(), wpt.getColor(), 0);
}
@Override
public Drawable getSecondLineIcon() {
return getIcon(R.drawable.ic_small_group);
}
/*
@Override
public int getFavActionIconId() {
return R.drawable.ic_action_edit_dark;
}
*/
@Override
public String getTypeStr() {
return wpt.category != null ? wpt.category : getMapActivity().getString(R.string.shared_string_none);
}
@Override
public String getNameStr() {
return wpt.name != null ? wpt.name : getMapActivity().getString(R.string.gpx_wpt);
}
}

View file

@ -261,6 +261,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
}
addOrRemoveParkingEvent(false);
setParkingPosition(mapActivity, latitude, longitude, false);
showContextMenuIfNeeded(mapActivity);
mapActivity.getMapView().refreshMap();
}
});
@ -268,7 +269,17 @@ public class ParkingPositionPlugin extends OsmandPlugin {
choose.show();
}
private void showContextMenuIfNeeded(final MapActivity mapActivity) {
if (parkingLayer != null) {
MapContextMenu menu = mapActivity.getContextMenu();
if (menu.isVisible()) {
menu.show(new LatLon(parkingPosition.getLatitude(), parkingPosition.getLongitude()),
parkingLayer.getObjectName(parkingPosition), parkingPosition);
}
}
}
/**
* Method creates confirmation dialog for deletion of a parking location.
*/
@ -361,6 +372,7 @@ public class ParkingPositionPlugin extends OsmandPlugin {
} else {
addOrRemoveParkingEvent(false);
}
showContextMenuIfNeeded(mapActivity);
}
});
setTime.create();
@ -412,10 +424,6 @@ public class ParkingPositionPlugin extends OsmandPlugin {
setParkingType(isLimited);
setParkingStartTime(Calendar.getInstance().getTimeInMillis());
if (parkingLayer != null) {
MapContextMenu menu = mapActivity.getContextMenu();
if (menu.isVisible()) {
menu.show(new LatLon(latitude, longitude), parkingLayer.getObjectName(parkingPosition), parkingPosition);
}
parkingLayer.refresh();
}
}