From 760e218475c8487b097faf36231e2658e70c7e7e Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Wed, 5 Jul 2017 12:47:09 +0300 Subject: [PATCH] Update favorite group with aidl --- .../net/osmand/aidl/IOsmAndAidlInterface.aidl | 2 + OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java | 20 +++++++ .../net/osmand/aidl/OsmandAidlService.java | 10 ++++ .../group/UpdateFavoriteGroupParams.aidl | 3 + .../group/UpdateFavoriteGroupParams.java | 55 +++++++++++++++++++ 5 files changed, 90 insertions(+) create mode 100644 OsmAnd/src/net/osmand/aidl/favorite/group/UpdateFavoriteGroupParams.aidl create mode 100644 OsmAnd/src/net/osmand/aidl/favorite/group/UpdateFavoriteGroupParams.java diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index 8d72b17565..9529a1933b 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.group.AFavoriteGroup; import net.osmand.aidl.favorite.group.AddFavoriteGroupParams; import net.osmand.aidl.favorite.group.RemoveFavoriteGroupParams; +import net.osmand.aidl.favorite.group.UpdateFavoriteGroupParams; import net.osmand.aidl.favorite.AFavorite; import net.osmand.aidl.favorite.AddFavoriteParams; @@ -42,6 +43,7 @@ interface IOsmAndAidlInterface { boolean addFavoriteGroup(in AddFavoriteGroupParams params); boolean removeFavoriteGroup(in RemoveFavoriteGroupParams params); + boolean updateFavoriteGroup(in UpdateFavoriteGroupParams 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 13b192a418..3e9f04c328 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -380,6 +380,26 @@ public class OsmandAidlApi { } } + boolean updateFavoriteGroup(AFavoriteGroup gPrev, AFavoriteGroup gNew) { + if (gPrev != null && gNew != null) { + FavouritesDbHelper favoritesHelper = app.getFavorites(); + List groups = favoritesHelper.getFavoriteGroups(); + for (FavouritesDbHelper.FavoriteGroup g : groups) { + if (g.name.equals(gPrev.getName())) { + int color = 0; + if (!Algorithms.isEmpty(gNew.getColor())) { + color = ColorDialogs.getColorByTag(gNew.getColor()); + } + favoritesHelper.editFavouriteGroup(g, gNew.getName(), color, gNew.isVisible()); + 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 2f9db6c7b2..512e9165f3 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -11,6 +11,7 @@ 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.favorite.group.UpdateFavoriteGroupParams; import net.osmand.aidl.gpx.ASelectedGpxFile; import net.osmand.aidl.gpx.HideGpxParams; import net.osmand.aidl.gpx.ImportGpxParams; @@ -69,6 +70,15 @@ public class OsmandAidlService extends Service { } } + @Override + public boolean updateFavoriteGroup(UpdateFavoriteGroupParams params) throws RemoteException { + try { + return params != null && getApi().updateFavoriteGroup(params.getFavoriteGroupPrev(), params.getFavoriteGroupNew()); + } catch (Exception e) { + return false; + } + } + @Override public boolean addFavorite(AddFavoriteParams params) throws RemoteException { try { diff --git a/OsmAnd/src/net/osmand/aidl/favorite/group/UpdateFavoriteGroupParams.aidl b/OsmAnd/src/net/osmand/aidl/favorite/group/UpdateFavoriteGroupParams.aidl new file mode 100644 index 0000000000..e9001a8c5e --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/group/UpdateFavoriteGroupParams.aidl @@ -0,0 +1,3 @@ +package net.osmand.aidl.favorite.group; + +parcelable UpdateFavoriteGroupParams; \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/favorite/group/UpdateFavoriteGroupParams.java b/OsmAnd/src/net/osmand/aidl/favorite/group/UpdateFavoriteGroupParams.java new file mode 100644 index 0000000000..0ea52e1fda --- /dev/null +++ b/OsmAnd/src/net/osmand/aidl/favorite/group/UpdateFavoriteGroupParams.java @@ -0,0 +1,55 @@ +package net.osmand.aidl.favorite.group; + +import android.os.Parcel; +import android.os.Parcelable; + +public class UpdateFavoriteGroupParams implements Parcelable { + + private AFavoriteGroup favoriteGroupPrev; + private AFavoriteGroup favoriteGroupNew; + + public UpdateFavoriteGroupParams(AFavoriteGroup favoriteGroup, AFavoriteGroup favoriteGroupNew) { + this.favoriteGroupPrev = favoriteGroup; + this.favoriteGroupNew = favoriteGroupNew; + } + + public UpdateFavoriteGroupParams(Parcel in) { + readFromParcel(in); + } + + public static final Creator CREATOR = new Creator() { + @Override + public UpdateFavoriteGroupParams createFromParcel(Parcel in) { + return new UpdateFavoriteGroupParams(in); + } + + @Override + public UpdateFavoriteGroupParams[] newArray(int size) { + return new UpdateFavoriteGroupParams[size]; + } + }; + + public AFavoriteGroup getFavoriteGroupPrev() { + return favoriteGroupPrev; + } + + public AFavoriteGroup getFavoriteGroupNew() { + return favoriteGroupNew; + } + + @Override + public void writeToParcel(Parcel out, int flags) { + out.writeParcelable(favoriteGroupPrev, flags); + out.writeParcelable(favoriteGroupNew, flags); + } + + private void readFromParcel(Parcel in) { + favoriteGroupPrev = in.readParcelable(AFavoriteGroup.class.getClassLoader()); + favoriteGroupNew = in.readParcelable(AFavoriteGroup.class.getClassLoader()); + } + + @Override + public int describeContents() { + return 0; + } +} \ No newline at end of file