fix use a more universal method for adding altitude

This commit is contained in:
Skalii 2021-02-25 05:04:43 +02:00
parent a702787f09
commit 066ee38de2
3 changed files with 8 additions and 20 deletions

View file

@ -361,6 +361,9 @@ public class FavouritesDbHelper {
} }
public boolean addFavourite(FavouritePoint p, boolean saveImmediately) { public boolean addFavourite(FavouritePoint p, boolean saveImmediately) {
if (p.getAltitude() == 0) {
p.initAltitude(context);
}
if (p.getName().isEmpty() && flatGroups.containsKey(p.getCategory())) { if (p.getName().isEmpty() && flatGroups.containsKey(p.getCategory())) {
return true; return true;
} }
@ -543,6 +546,9 @@ public class FavouritesDbHelper {
private boolean editFavourite(@NonNull FavouritePoint p, double lat, double lon, @Nullable String description) { private boolean editFavourite(@NonNull FavouritePoint p, double lat, double lon, @Nullable String description) {
cancelAddressRequest(p); cancelAddressRequest(p);
if (p.getLatitude() != lat && p.getLongitude() != lon) {
p.initAltitude(context);
}
p.setLatitude(lat); p.setLatitude(lat);
p.setLongitude(lon); p.setLongitude(lon);
if (description != null) { if (description != null) {

View file

@ -39,10 +39,6 @@ class FavoritesImportTask extends BaseLoadAsyncTask<Void, Void, GPXFile> {
for (FavouritePoint favourite : favourites) { for (FavouritePoint favourite : favourites) {
favoritesHelper.deleteFavourite(favourite, false); favoritesHelper.deleteFavourite(favourite, false);
favoritesHelper.addFavourite(favourite, false); favoritesHelper.addFavourite(favourite, false);
double alt = favourite.getAltitude();
if (Double.isNaN(alt) || alt == 0) {
favourite.initAltitude(app);
}
} }
favoritesHelper.sortAll(); favoritesHelper.sortAll();
favoritesHelper.saveCurrentPointsIntoFile(); favoritesHelper.saveCurrentPointsIntoFile();

View file

@ -41,17 +41,8 @@ public class FavoritePointEditor extends PointEditor {
favorite.setDescription(""); favorite.setDescription("");
favorite.setAddress(address.isEmpty() ? title : address); favorite.setAddress(address.isEmpty() ? title : address);
favorite.setOriginObjectName(originObjectName); favorite.setOriginObjectName(originObjectName);
if (Double.isNaN(altitude) || altitude == 0) {
favorite.initAltitude(app, new Runnable() {
@Override
public void run() {
FavoritePointEditorFragmentNew.showInstance(mapActivity); FavoritePointEditorFragmentNew.showInstance(mapActivity);
} }
});
} else {
FavoritePointEditorFragmentNew.showInstance(mapActivity);
}
}
public void add(LatLon latLon, String title, String originObjectName, String categoryName, int categoryColor, final boolean autoFill) { public void add(LatLon latLon, String title, String originObjectName, String categoryName, int categoryColor, final boolean autoFill) {
final MapActivity mapActivity = getMapActivity(); final MapActivity mapActivity = getMapActivity();
@ -73,13 +64,8 @@ public class FavoritePointEditor extends PointEditor {
favorite.setDescription(""); favorite.setDescription("");
favorite.setAddress(""); favorite.setAddress("");
favorite.setOriginObjectName(originObjectName); favorite.setOriginObjectName(originObjectName);
favorite.initAltitude(app, new Runnable() {
@Override
public void run() {
FavoritePointEditorFragmentNew.showAutoFillInstance(mapActivity, autoFill); FavoritePointEditorFragmentNew.showAutoFillInstance(mapActivity, autoFill);
} }
});
}
public void edit(FavouritePoint favorite) { public void edit(FavouritePoint favorite) {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();