Merge pull request #4030 from osmandapp/osmo_api_improvements

Update favorite with aidl
This commit is contained in:
Alexey 2017-07-04 17:42:32 +03:00 committed by GitHub
commit 6621c16a9b
5 changed files with 94 additions and 0 deletions

View file

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

View file

@ -386,6 +386,30 @@ 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());
}
refreshMap();
return true;
}
}
return false;
} else {
return false;
}
}
boolean addMapMarker(AMapMarker marker) {
if (marker != null) {
PointDescription pd = new PointDescription(

View file

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

View file

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

View file

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