Update favorite with aidl
This commit is contained in:
parent
0998074605
commit
0a64809b6b
5 changed files with 102 additions and 0 deletions
|
@ -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);
|
||||
|
|
|
@ -386,6 +386,38 @@ public class OsmandAidlApi {
|
|||
}
|
||||
}
|
||||
|
||||
boolean updateFavorite(AFavorite fPrev, AFavorite fNew) {
|
||||
if (fPrev != null && fNew != null) {
|
||||
FavouritesDbHelper favoritesHelper = app.getFavorites();
|
||||
List<FavouritePoint> 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(
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
package net.osmand.aidl.favorite;
|
||||
|
||||
parcelable UpdateFavoriteParams;
|
|
@ -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<UpdateFavoriteParams> CREATOR = new Creator<UpdateFavoriteParams>() {
|
||||
@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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue