diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index 9bd140dd63..0a199f58a7 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -6,6 +6,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.favorite.UpdateFavoriteParams; import net.osmand.aidl.mapmarker.AMapMarker; import net.osmand.aidl.mapmarker.AddMapMarkerParams; @@ -37,6 +38,7 @@ interface IOsmAndAidlInterface { boolean addFavorite(in AddFavoriteParams params); boolean removeFavorite(in RemoveFavoriteParams params); + boolean updateFavorite(in UpdateFavoriteParams 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 2ab48fad2e..d84b276905 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -386,6 +386,38 @@ public class OsmandAidlApi { } } + boolean updateFavorite(AFavorite fPrev, AFavorite fNew) { + if (fPrev != null && fNew != null) { + FavouritesDbHelper favoritesHelper = app.getFavorites(); + List favorites = favoritesHelper.getFavouritePoints(); + for (FavouritePoint f : favorites) { + if (f.getName().equals(fPrev.getName()) && f.getCategory().equals(fPrev.getCategory()) && + f.getLatitude() == fPrev.getLat() && f.getLongitude() == fPrev.getLon()) { + if (fNew.getLat() != f.getLatitude() || fNew.getLon() != f.getLongitude()) { + favoritesHelper.editFavourite(f, fNew.getLat(), fNew.getLon()); + } + if (!fNew.getName().equals(f.getName()) || !fNew.getDescription().equals(f.getDescription()) || + !fNew.getCategory().equals(f.getCategory())) { + favoritesHelper.editFavouriteName(f, fNew.getName(), fNew.getCategory(), fNew.getDescription()); + } + int color = 0; + if (!Algorithms.isEmpty(fNew.getColor())) { + color = ColorDialogs.getColorByTag(fNew.getColor()); + } + if (color != f.getColor()) { + FavouritesDbHelper.FavoriteGroup fg = favoritesHelper.getGroup(f); + favoritesHelper.editFavouriteGroup(fg, fg.name, color, fg.visible); + } + 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 5cbd0583fe..1602c663f3 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -8,6 +8,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.favorite.UpdateFavoriteParams; import net.osmand.aidl.gpx.ASelectedGpxFile; import net.osmand.aidl.gpx.HideGpxParams; import net.osmand.aidl.gpx.ImportGpxParams; @@ -66,6 +67,15 @@ public class OsmandAidlService extends Service { } } + @Override + public boolean updateFavorite(UpdateFavoriteParams params) throws RemoteException { + try { + return params != null && getApi().updateFavorite(params.getFavoritePrev(), params.getFavoriteNew()); + } catch (Exception e) { + return false; + } + } + @Override public boolean addMapMarker(AddMapMarkerParams params) throws RemoteException { try { diff --git a/OsmAnd/src/net/osmand/aidl/favorite/UpdateFavoriteParams.aidl b/OsmAnd/src/net/osmand/aidl/favorite/UpdateFavoriteParams.aidl new file mode 100644 index 0000000000..ba4a9364d3 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/UpdateFavoriteParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.favorite; + +parcelable UpdateFavoriteParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/favorite/UpdateFavoriteParams.java b/OsmAnd/src/net/osmand/aidl/favorite/UpdateFavoriteParams.java new file mode 100644 index 0000000000..43fdfc13bd --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/UpdateFavoriteParams.java @@ -0,0 +1,55 @@ +package net.osmand.aidl.favorite; + +import android.os.Parcel; +import android.os.Parcelable; + +public class UpdateFavoriteParams implements Parcelable { + + private AFavorite favoritePrev; + private AFavorite favoriteNew; + + public UpdateFavoriteParams(AFavorite favoritePrev, AFavorite favoriteNew) { + this.favoritePrev = favoritePrev; + this.favoriteNew = favoriteNew; + } + + public UpdateFavoriteParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public UpdateFavoriteParams createFromParcel(Parcel in) { + return new UpdateFavoriteParams(in); + } + + @Override + public UpdateFavoriteParams[] newArray(int size) { + return new UpdateFavoriteParams[size]; + } + }; + + public AFavorite getFavoritePrev() { + return favoritePrev; + } + + public AFavorite getFavoriteNew() { + return favoriteNew; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeParcelable(favoritePrev, flags); + out.writeParcelable(favoriteNew, flags); + } + + private void readFromParcel(Parcel in) { + favoritePrev = in.readParcelable(AFavorite.class.getClassLoader()); + favoriteNew = in.readParcelable(AFavorite.class.getClassLoader()); + } + + @Override + public int describeContents() { + return 0; + } +}