From a89946290b4bad3e5fdbcbf48388a62da2de2cdb Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 5 Jul 2017 12:01:46 +0300 Subject: [PATCH] Remove favorite group with aidl --- .../net/osmand/aidl/IOsmAndAidlInterface.aidl | 2 + OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 16 +++++++ .../net/osmand/aidl/OsmandAidlService.java | 10 ++++ .../group/RemoveFavoriteGroupParams.aidl | 3 ++ .../group/RemoveFavoriteGroupParams.java | 47 +++++++++++++++++++ 5 files changed, 78 insertions(+) create mode 100644 OsmAnd/src/net/osmand/aidl/favorite/group/RemoveFavoriteGroupParams.aidl create mode 100644 OsmAnd/src/net/osmand/aidl/favorite/group/RemoveFavoriteGroupParams.java diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index 700122e5fd..8d72b17565 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.group.AFavoriteGroup; import net.osmand.aidl.favorite.group.AddFavoriteGroupParams; +import net.osmand.aidl.favorite.group.RemoveFavoriteGroupParams; import net.osmand.aidl.favorite.AFavorite; import net.osmand.aidl.favorite.AddFavoriteParams; @@ -40,6 +41,7 @@ import net.osmand.aidl.maplayer.UpdateMapLayerParams; interface IOsmAndAidlInterface { boolean addFavoriteGroup(in AddFavoriteGroupParams params); + boolean removeFavoriteGroup(in RemoveFavoriteGroupParams params); boolean addFavorite(in AddFavoriteParams params); boolean removeFavorite(in RemoveFavoriteParams params); diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index f14cfa64b0..13b192a418 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -364,6 +364,22 @@ public class OsmandAidlApi { } } + boolean removeFavoriteGroup(AFavoriteGroup favoriteGroup) { + if (favoriteGroup != null) { + FavouritesDbHelper favoritesHelper = app.getFavorites(); + List groups = favoritesHelper.getFavoriteGroups(); + for (FavouritesDbHelper.FavoriteGroup g : groups) { + if (g.name.equals(favoriteGroup.getName())) { + favoritesHelper.deleteGroup(g); + return true; + } + } + return false; + } else { + return false; + } + } + boolean addFavorite(AFavorite favorite) { if (favorite != null) { FavouritesDbHelper favoritesHelper = app.getFavorites(); diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index ffb1f02d15..2f9db6c7b2 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -10,6 +10,7 @@ import net.osmand.aidl.favorite.AddFavoriteParams; import net.osmand.aidl.favorite.RemoveFavoriteParams; import net.osmand.aidl.favorite.UpdateFavoriteParams; import net.osmand.aidl.favorite.group.AddFavoriteGroupParams; +import net.osmand.aidl.favorite.group.RemoveFavoriteGroupParams; import net.osmand.aidl.gpx.ASelectedGpxFile; import net.osmand.aidl.gpx.HideGpxParams; import net.osmand.aidl.gpx.ImportGpxParams; @@ -59,6 +60,15 @@ public class OsmandAidlService extends Service { } } + @Override + public boolean removeFavoriteGroup(RemoveFavoriteGroupParams params) throws RemoteException { + try { + return params != null && getApi().removeFavoriteGroup(params.getFavoriteGroup()); + } catch (Exception e) { + return false; + } + } + @Override public boolean addFavorite(AddFavoriteParams params) throws RemoteException { try { diff --git a/OsmAnd/src/net/osmand/aidl/favorite/group/RemoveFavoriteGroupParams.aidl b/OsmAnd/src/net/osmand/aidl/favorite/group/RemoveFavoriteGroupParams.aidl new file mode 100644 index 0000000000..e8b0710a01 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/group/RemoveFavoriteGroupParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.favorite.group; + +parcelable RemoveFavoriteGroupParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/favorite/group/RemoveFavoriteGroupParams.java b/OsmAnd/src/net/osmand/aidl/favorite/group/RemoveFavoriteGroupParams.java new file mode 100644 index 0000000000..0b17274440 --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/group/RemoveFavoriteGroupParams.java @@ -0,0 +1,47 @@ +package net.osmand.aidl.favorite.group; + +import android.os.Parcel; +import android.os.Parcelable; + +public class RemoveFavoriteGroupParams implements Parcelable { + + private AFavoriteGroup favoriteGroup; + + public RemoveFavoriteGroupParams(AFavoriteGroup favoriteGroup) { + this.favoriteGroup = favoriteGroup; + } + + public RemoveFavoriteGroupParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public RemoveFavoriteGroupParams createFromParcel(Parcel in) { + return new RemoveFavoriteGroupParams(in); + } + + @Override + public RemoveFavoriteGroupParams[] newArray(int size) { + return new RemoveFavoriteGroupParams[size]; + } + }; + + public AFavoriteGroup getFavoriteGroup() { + return favoriteGroup; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeParcelable(favoriteGroup, flags); + } + + private void readFromParcel(Parcel in) { + favoriteGroup = in.readParcelable(AFavoriteGroup.class.getClassLoader()); + } + + @Override + public int describeContents() { + return 0; + } +} \ No newline at end of file