diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index bc0310ac15..9bd140dd63 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -5,6 +5,7 @@ import net.osmand.aidl.map.SetMapLocationParams; import net.osmand.aidl.favorite.AFavorite; import net.osmand.aidl.favorite.AddFavoriteParams; +import net.osmand.aidl.favorite.RemoveFavoriteParams; import net.osmand.aidl.mapmarker.AMapMarker; import net.osmand.aidl.mapmarker.AddMapMarkerParams; @@ -35,6 +36,7 @@ import net.osmand.aidl.maplayer.UpdateMapLayerParams; interface IOsmAndAidlInterface { boolean addFavorite(in AddFavoriteParams params); + boolean removeFavorite(in RemoveFavoriteParams params); boolean addMapMarker(in AddMapMarkerParams params); boolean removeMapMarker(in RemoveMapMarkerParams params); diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index f39a369651..2ab48fad2e 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -361,12 +361,31 @@ public class OsmandAidlApi { point.setColor(color); point.setVisible(favorite.isVisible()); favoritesHelper.addFavourite(point); + refreshMap(); return true; } else { return false; } } + boolean removeFavorite(AFavorite favorite) { + if (favorite != null) { + FavouritesDbHelper favoritesHelper = app.getFavorites(); + List favorites = favoritesHelper.getFavouritePoints(); + for (FavouritePoint f : favorites) { + if (f.getName().equals(favorite.getName()) && f.getCategory().equals(favorite.getCategory()) && + f.getLatitude() == favorite.getLat() && f.getLongitude() == favorite.getLon()) { + favoritesHelper.deleteFavourite(f); + refreshMap(); + return true; + } + } + return false; + } else { + return false; + } + } + boolean addMapMarker(AMapMarker marker) { if (marker != null) { PointDescription pd = new PointDescription( diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 8a1547e841..5cbd0583fe 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -7,6 +7,7 @@ import android.os.RemoteException; import net.osmand.aidl.calculateroute.CalculateRouteParams; import net.osmand.aidl.favorite.AddFavoriteParams; +import net.osmand.aidl.favorite.RemoveFavoriteParams; import net.osmand.aidl.gpx.ASelectedGpxFile; import net.osmand.aidl.gpx.HideGpxParams; import net.osmand.aidl.gpx.ImportGpxParams; @@ -56,6 +57,15 @@ public class OsmandAidlService extends Service { } } + @Override + public boolean removeFavorite(RemoveFavoriteParams params) throws RemoteException { + try { + return params != null && getApi().removeFavorite(params.getFavorite()); + } catch (Exception e) { + return false; + } + } + @Override public boolean addMapMarker(AddMapMarkerParams params) throws RemoteException { try { diff --git a/OsmAnd/src/net/osmand/aidl/favorite/RemoveFavoriteParams.aidl b/OsmAnd/src/net/osmand/aidl/favorite/RemoveFavoriteParams.aidl new file mode 100644 index 0000000000..37c08cd374 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/RemoveFavoriteParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.favorite; + +parcelable RemoveFavoriteParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/favorite/RemoveFavoriteParams.java b/OsmAnd/src/net/osmand/aidl/favorite/RemoveFavoriteParams.java new file mode 100644 index 0000000000..15e2ca74bd --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/RemoveFavoriteParams.java @@ -0,0 +1,47 @@ +package net.osmand.aidl.favorite; + +import android.os.Parcel; +import android.os.Parcelable; + +public class RemoveFavoriteParams implements Parcelable { + + private AFavorite favorite; + + public RemoveFavoriteParams(AFavorite favorite) { + this.favorite = favorite; + } + + public RemoveFavoriteParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public RemoveFavoriteParams createFromParcel(Parcel in) { + return new RemoveFavoriteParams(in); + } + + @Override + public RemoveFavoriteParams[] newArray(int size) { + return new RemoveFavoriteParams[size]; + } + }; + + public AFavorite getFavorite() { + return favorite; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeParcelable(favorite, flags); + } + + private void readFromParcel(Parcel in) { + favorite = in.readParcelable(AFavorite.class.getClassLoader()); + } + + @Override + public int describeContents() { + return 0; + } +}