Update favorite group with aidl

This commit is contained in:
Alexander Sytnyk 2017-07-05 12:47:09 +03:00
parent a89946290b
commit 760e218475
5 changed files with 90 additions and 0 deletions

View file

@ -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);

View file

@ -380,6 +380,26 @@ public class OsmandAidlApi {
}
}
boolean updateFavoriteGroup(AFavoriteGroup gPrev, AFavoriteGroup gNew) {
if (gPrev != null && gNew != null) {
FavouritesDbHelper favoritesHelper = app.getFavorites();
List<FavouritesDbHelper.FavoriteGroup> 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();

View file

@ -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 {

View file

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

View file

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