some fixes

This commit is contained in:
Skalii 2021-02-25 03:49:52 +02:00
parent 0f81841c79
commit a702787f09
5 changed files with 26 additions and 30 deletions

View file

@ -59,6 +59,7 @@ public class FavouritePoint implements Serializable, LocationPoint {
name = ""; name = "";
} }
this.name = name; this.name = name;
timestamp = System.currentTimeMillis();
initPersonalType(); initPersonalType();
} }
@ -71,7 +72,7 @@ public class FavouritePoint implements Serializable, LocationPoint {
} }
this.name = name; this.name = name;
this.altitude = altitude; this.altitude = altitude;
this.timestamp = timestamp; this.timestamp = timestamp != 0 ? timestamp : System.currentTimeMillis();
initPersonalType(); initPersonalType();
} }
@ -102,6 +103,10 @@ public class FavouritePoint implements Serializable, LocationPoint {
} }
} }
public void initAltitude(final OsmandApplication app) {
initAltitude(app, null);
}
public void initAltitude(final OsmandApplication app, final Runnable callback) { public void initAltitude(final OsmandApplication app, final Runnable callback) {
app.getLocationProvider().getRouteSegment(new Location("", latitude, longitude), null, false, new ResultMatcher<RouteDataObject>() { app.getLocationProvider().getRouteSegment(new Location("", latitude, longitude), null, false, new ResultMatcher<RouteDataObject>() {
@ -110,9 +115,10 @@ public class FavouritePoint implements Serializable, LocationPoint {
if (routeDataObject != null) { if (routeDataObject != null) {
routeDataObject.calculateHeightArray(new LatLon(latitude, longitude)); routeDataObject.calculateHeightArray(new LatLon(latitude, longitude));
altitude = routeDataObject.heightByCurrentLocation; altitude = routeDataObject.heightByCurrentLocation;
} else {
} }
callback.run(); if (callback != null) {
callback.run();
}
return true; return true;
} }

View file

@ -24,7 +24,7 @@ class FavoritesImportTask extends BaseLoadAsyncTask<Void, Void, GPXFile> {
private boolean forceImportFavourites; private boolean forceImportFavourites;
public FavoritesImportTask(@NonNull FragmentActivity activity, @NonNull GPXFile gpxFile, public FavoritesImportTask(@NonNull FragmentActivity activity, @NonNull GPXFile gpxFile,
@NonNull String fileName, boolean forceImportFavourites) { @NonNull String fileName, boolean forceImportFavourites) {
super(activity); super(activity);
this.gpxFile = gpxFile; this.gpxFile = gpxFile;
this.fileName = fileName; this.fileName = fileName;
@ -39,6 +39,10 @@ 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

@ -687,7 +687,7 @@ public class ImportHelper {
} else { } else {
fpCat = p.category; fpCat = p.category;
} }
final FavouritePoint point = new FavouritePoint(p.lat, p.lon, p.name, fpCat, p.ele, p.time); final FavouritePoint point = new FavouritePoint(p.lat, p.lon, p.name, fpCat, p.ele, 0);
if (p.desc != null) { if (p.desc != null) {
point.setDescription(p.desc); point.setDescription(p.desc);
} }
@ -698,17 +698,7 @@ public class ImportHelper {
point.setIconIdFromName(app, iconName); point.setIconIdFromName(app, iconName);
} }
point.setBackgroundType(BackgroundType.getByTypeName(p.getBackgroundType(), DEFAULT_BACKGROUND_TYPE)); point.setBackgroundType(BackgroundType.getByTypeName(p.getBackgroundType(), DEFAULT_BACKGROUND_TYPE));
if (Double.isNaN(p.ele) || p.ele == 0) { favourites.add(point);
point.initAltitude(app, new Runnable() {
@Override
public void run() {
favourites.add(point);
}
});
} else {
favourites.add(point);
}
} }
} }
return favourites; return favourites;

View file

@ -37,7 +37,7 @@ public class FavoritePointEditor extends PointEditor {
if (!Algorithms.isEmpty(lastCategory) && !app.getFavorites().groupExists(lastCategory)) { if (!Algorithms.isEmpty(lastCategory) && !app.getFavorites().groupExists(lastCategory)) {
lastCategory = ""; lastCategory = "";
} }
favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, lastCategory, (float) altitude, timestamp); favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, lastCategory, altitude, timestamp);
favorite.setDescription(""); favorite.setDescription("");
favorite.setAddress(address.isEmpty() ? title : address); favorite.setAddress(address.isEmpty() ? title : address);
favorite.setOriginObjectName(originObjectName); favorite.setOriginObjectName(originObjectName);
@ -53,7 +53,7 @@ public class FavoritePointEditor extends PointEditor {
} }
} }
public void add(LatLon latLon, String title, String originObjectName, String categoryName, int categoryColor, final boolean autoFill, double altitude, long timestamp) { public void add(LatLon latLon, String title, String originObjectName, String categoryName, int categoryColor, final boolean autoFill) {
final MapActivity mapActivity = getMapActivity(); final MapActivity mapActivity = getMapActivity();
if (latLon == null || mapActivity == null) { if (latLon == null || mapActivity == null) {
return; return;
@ -69,20 +69,16 @@ public class FavoritePointEditor extends PointEditor {
categoryName = ""; categoryName = "";
} }
favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, categoryName, (float) altitude, timestamp); favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, categoryName);
favorite.setDescription(""); favorite.setDescription("");
favorite.setAddress(""); favorite.setAddress("");
favorite.setOriginObjectName(originObjectName); favorite.setOriginObjectName(originObjectName);
if (Double.isNaN(altitude) || altitude == 0) { favorite.initAltitude(app, new Runnable() {
favorite.initAltitude(app, new Runnable() { @Override
@Override public void run() {
public void run() { FavoritePointEditorFragmentNew.showAutoFillInstance(mapActivity, autoFill);
FavoritePointEditorFragmentNew.showAutoFillInstance(mapActivity, autoFill); }
} });
});
} else {
FavoritePointEditorFragmentNew.showAutoFillInstance(mapActivity, autoFill);
}
} }
public void edit(FavouritePoint favorite) { public void edit(FavouritePoint favorite) {

View file

@ -119,7 +119,7 @@ public class FavoriteAction extends QuickAction {
FavoritePointEditor favoritePointEditor = mapActivity.getContextMenu().getFavoritePointEditor(); FavoritePointEditor favoritePointEditor = mapActivity.getContextMenu().getFavoritePointEditor();
if (favoritePointEditor != null) { if (favoritePointEditor != null) {
favoritePointEditor.add(latLon, title, "", getParams().get(KEY_CATEGORY_NAME), favoritePointEditor.add(latLon, title, "", getParams().get(KEY_CATEGORY_NAME),
Integer.valueOf(getParams().get(KEY_CATEGORY_COLOR)), autoFill, 0, 0); Integer.valueOf(getParams().get(KEY_CATEGORY_COLOR)), autoFill);
} }
} }