Remove favorite with aidl

This commit is contained in:
Alexander Sytnyk 2017-07-04 13:47:08 +03:00
parent d57ca20e18
commit 0998074605
5 changed files with 81 additions and 0 deletions

View file

@ -5,6 +5,7 @@ import net.osmand.aidl.map.SetMapLocationParams;
import net.osmand.aidl.favorite.AFavorite; import net.osmand.aidl.favorite.AFavorite;
import net.osmand.aidl.favorite.AddFavoriteParams; import net.osmand.aidl.favorite.AddFavoriteParams;
import net.osmand.aidl.favorite.RemoveFavoriteParams;
import net.osmand.aidl.mapmarker.AMapMarker; import net.osmand.aidl.mapmarker.AMapMarker;
import net.osmand.aidl.mapmarker.AddMapMarkerParams; import net.osmand.aidl.mapmarker.AddMapMarkerParams;
@ -35,6 +36,7 @@ import net.osmand.aidl.maplayer.UpdateMapLayerParams;
interface IOsmAndAidlInterface { interface IOsmAndAidlInterface {
boolean addFavorite(in AddFavoriteParams params); boolean addFavorite(in AddFavoriteParams params);
boolean removeFavorite(in RemoveFavoriteParams params);
boolean addMapMarker(in AddMapMarkerParams params); boolean addMapMarker(in AddMapMarkerParams params);
boolean removeMapMarker(in RemoveMapMarkerParams params); boolean removeMapMarker(in RemoveMapMarkerParams params);

View file

@ -361,12 +361,31 @@ public class OsmandAidlApi {
point.setColor(color); point.setColor(color);
point.setVisible(favorite.isVisible()); point.setVisible(favorite.isVisible());
favoritesHelper.addFavourite(point); favoritesHelper.addFavourite(point);
refreshMap();
return true; return true;
} else { } else {
return false; return false;
} }
} }
boolean removeFavorite(AFavorite favorite) {
if (favorite != null) {
FavouritesDbHelper favoritesHelper = app.getFavorites();
List<FavouritePoint> 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) { boolean addMapMarker(AMapMarker marker) {
if (marker != null) { if (marker != null) {
PointDescription pd = new PointDescription( PointDescription pd = new PointDescription(

View file

@ -7,6 +7,7 @@ import android.os.RemoteException;
import net.osmand.aidl.calculateroute.CalculateRouteParams; import net.osmand.aidl.calculateroute.CalculateRouteParams;
import net.osmand.aidl.favorite.AddFavoriteParams; import net.osmand.aidl.favorite.AddFavoriteParams;
import net.osmand.aidl.favorite.RemoveFavoriteParams;
import net.osmand.aidl.gpx.ASelectedGpxFile; import net.osmand.aidl.gpx.ASelectedGpxFile;
import net.osmand.aidl.gpx.HideGpxParams; import net.osmand.aidl.gpx.HideGpxParams;
import net.osmand.aidl.gpx.ImportGpxParams; 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 @Override
public boolean addMapMarker(AddMapMarkerParams params) throws RemoteException { public boolean addMapMarker(AddMapMarkerParams params) throws RemoteException {
try { try {

View file

@ -0,0 +1,3 @@
package net.osmand.aidl.favorite;
parcelable RemoveFavoriteParams;

View file

@ -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<RemoveFavoriteParams> CREATOR = new Creator<RemoveFavoriteParams>() {
@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;
}
}