diff --git a/OsmAnd/src/net/osmand/data/FavouritePoint.java b/OsmAnd/src/net/osmand/data/FavouritePoint.java index 414299e575..4414de8d87 100644 --- a/OsmAnd/src/net/osmand/data/FavouritePoint.java +++ b/OsmAnd/src/net/osmand/data/FavouritePoint.java @@ -16,14 +16,16 @@ import net.osmand.ResultMatcher; import net.osmand.binary.RouteDataObject; import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.settings.backend.BooleanPreference; -import net.osmand.plus.settings.backend.OsmandPreference; import net.osmand.plus.R; import net.osmand.plus.parkingpoint.ParkingPositionPlugin; +import net.osmand.plus.settings.backend.BooleanPreference; +import net.osmand.plus.settings.backend.OsmandPreference; import net.osmand.util.Algorithms; import java.io.Serializable; +import static net.osmand.plus.itinerary.ItineraryHelper.PASSED_TIMESTAMP; + public class FavouritePoint implements Serializable, LocationPoint { private static final long serialVersionUID = 729654300829771466L; @@ -47,6 +49,7 @@ public class FavouritePoint implements Serializable, LocationPoint { private BackgroundType backgroundType = null; private double altitude = Double.NaN; private long timestamp; + private long passedTimestamp; public FavouritePoint() { } @@ -90,6 +93,7 @@ public class FavouritePoint implements Serializable, LocationPoint { this.backgroundType = favouritePoint.backgroundType; this.altitude = favouritePoint.altitude; this.timestamp = favouritePoint.timestamp; + this.passedTimestamp = favouritePoint.passedTimestamp; initPersonalType(); } @@ -237,6 +241,14 @@ public class FavouritePoint implements Serializable, LocationPoint { this.timestamp = timestamp; } + public long getPassedTimestamp() { + return passedTimestamp; + } + + public void setPassedTimestamp(long passedTimestamp) { + this.passedTimestamp = passedTimestamp; + } + public String getCategory() { return category; } @@ -322,8 +334,11 @@ public class FavouritePoint implements Serializable, LocationPoint { } else if (!originObjectName.equals(fp.originObjectName)) return false; - return (this.latitude == fp.latitude) && (this.longitude == fp.longitude) && - (this.altitude == fp.altitude) && (this.timestamp == fp.timestamp); + return (this.latitude == fp.latitude) + && (this.longitude == fp.longitude) + && (this.altitude == fp.altitude) + && (this.timestamp == fp.timestamp) + && (this.passedTimestamp == fp.passedTimestamp); } @Override @@ -334,6 +349,7 @@ public class FavouritePoint implements Serializable, LocationPoint { result = prime * result + (int) Math.floor(longitude * 10000); result = prime * result + (int) Math.floor(altitude * 10000); result = prime * result + (int) Math.floor(timestamp * 10000); + result = prime * result + (int) Math.floor(passedTimestamp * 10000); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((category == null) ? 0 : category.hashCode()); result = prime * result + ((description == null) ? 0 : description.hashCode()); @@ -467,6 +483,11 @@ public class FavouritePoint implements Serializable, LocationPoint { if (iconName != null) { fp.setIconIdFromName(ctx, iconName); } + if (pt.getExtensionsToWrite().containsKey(PASSED_TIMESTAMP)) { + String time = pt.getExtensionsToWrite().get(PASSED_TIMESTAMP); + fp.setPassedTimestamp(Algorithms.parseLongSilently(time, 0)); + } + BackgroundType backgroundType = BackgroundType.getByTypeName(pt.getBackgroundType(), null); fp.setBackgroundType(backgroundType); return fp; @@ -484,6 +505,9 @@ public class FavouritePoint implements Serializable, LocationPoint { if (isAddressSpecified()) { pt.getExtensionsToWrite().put(ADDRESS_EXTENSION, getAddress()); } + if (getPassedTimestamp() != 0) { + pt.getExtensionsToWrite().put(PASSED_TIMESTAMP, String.valueOf(getPassedTimestamp())); + } if (iconId != 0) { pt.setIconName(getIconEntryName(ctx).substring(3)); } diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index bd8bb99104..36321520ac 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -14,12 +14,13 @@ import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.WptPt; import net.osmand.PlatformUtil; import net.osmand.data.FavouritePoint; +import net.osmand.data.FavouritePoint.SpecialPointType; import net.osmand.data.LatLon; import net.osmand.plus.GeocodingLookupService.AddressLookupRequest; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteCursor; -import net.osmand.plus.mapmarkers.MapMarkersGroup; import net.osmand.plus.itinerary.ItineraryHelper; +import net.osmand.plus.mapmarkers.MapMarkersGroup; import net.osmand.util.Algorithms; import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; @@ -238,7 +239,7 @@ public class FavouritesDbHelper { }); } - public FavouritePoint getSpecialPoint(FavouritePoint.SpecialPointType pointType) { + public FavouritePoint getSpecialPoint(SpecialPointType pointType) { for (FavouritePoint fp : cachedFavoritePoints) { if (fp.getSpecialPointType() == pointType) { return fp; @@ -710,6 +711,17 @@ public class FavouritesDbHelper { return null; } + @Nullable + public FavouritePoint getFavByLatLon(@NonNull LatLon latLon, String name) { + for (FavouritePoint fav : cachedFavoritePoints) { + if (latLon.equals(new LatLon(fav.getLatitude(), fav.getLongitude())) + && Algorithms.stringsEqual(fav.getName(), name)) { + return fav; + } + } + return null; + } + public List getFavoriteGroups() { return favoriteGroups; } @@ -943,7 +955,7 @@ public class FavouritesDbHelper { public void onUpgrade(SQLiteConnection db, int oldVersion, int newVersion) { if (oldVersion == 1) { db.execSQL("ALTER TABLE " + FAVOURITE_TABLE_NAME + " ADD " + FAVOURITE_COL_CATEGORY + " text"); - db.execSQL("UPDATE " + FAVOURITE_TABLE_NAME + " SET category = ?", new Object[]{""}); //$NON-NLS-1$ //$NON-NLS-2$ + db.execSQL("UPDATE " + FAVOURITE_TABLE_NAME + " SET category = ?", new Object[] {""}); //$NON-NLS-1$ //$NON-NLS-2$ } } @@ -984,108 +996,4 @@ public class FavouritesDbHelper { recalculateCachedFavPoints(); } } - - public boolean deleteFavouriteDB(FavouritePoint p) { - SQLiteConnection db = openConnection(false); - if (db != null) { - try { - db.execSQL( - "DELETE FROM " + FAVOURITE_TABLE_NAME + " WHERE category = ? AND " + whereNameLatLon(), new Object[]{p.getCategory(), p.getName(), p.getLatitude(), p.getLongitude()}); //$NON-NLS-1$ //$NON-NLS-2$ - FavouritePoint fp = findFavoriteByAllProperties(p.getCategory(), p.getName(), p.getLatitude(), p.getLongitude()); - if (fp != null) { - FavoriteGroup group = flatGroups.get(p.getCategory()); - if (group != null) { - group.points.remove(fp); - } - cachedFavoritePoints.remove(fp); - } - saveCurrentPointsIntoFile(); - } finally { - db.close(); - } - return true; - } - return false; - } - - - public boolean addFavouriteDB(FavouritePoint p) { - if (p.getName().isEmpty() && flatGroups.containsKey(p.getCategory())) { - return true; - } - SQLiteConnection db = openConnection(false); - if (db != null) { - try { - db.execSQL( - "INSERT INTO " + FAVOURITE_TABLE_NAME + " (" + FAVOURITE_COL_NAME + ", " + FAVOURITE_COL_CATEGORY + ", " - + FAVOURITE_COL_LAT + ", " + FAVOURITE_COL_LON + ")" + " VALUES (?, ?, ?, ?)", new Object[]{p.getName(), p.getCategory(), p.getLatitude(), p.getLongitude()}); //$NON-NLS-1$ //$NON-NLS-2$ - FavoriteGroup group = getOrCreateGroup(p, 0); - if (!p.getName().isEmpty()) { - p.setVisible(group.visible); - p.setColor(group.color); - group.points.add(p); - cachedFavoritePoints.add(p); - } - saveCurrentPointsIntoFile(); - } finally { - db.close(); - } - return true; - } - return false; - } - - - public boolean editFavouriteNameDB(FavouritePoint p, String newName, String category) { - SQLiteConnection db = openConnection(false); - if (db != null) { - try { - String oldCategory = p.getCategory(); - db.execSQL( - "UPDATE " + FAVOURITE_TABLE_NAME + " SET " + FAVOURITE_COL_NAME + " = ?, " + FAVOURITE_COL_CATEGORY + "= ? WHERE " + whereNameLatLon(), new Object[]{newName, category, p.getName(), p.getLatitude(), p.getLongitude()}); //$NON-NLS-1$ //$NON-NLS-2$ - p.setName(newName); - p.setCategory(category); - if (!oldCategory.equals(category)) { - FavoriteGroup old = flatGroups.get(oldCategory); - if (old != null) { - old.points.remove(p); - } - FavoriteGroup pg = getOrCreateGroup(p, 0); - p.setVisible(pg.visible); - p.setColor(pg.color); - pg.points.add(p); - } - sortAll(); - } finally { - db.close(); - } - return true; - } - return false; - } - - - public boolean editFavouriteDB(FavouritePoint p, double lat, double lon) { - SQLiteConnection db = openConnection(false); - if (db != null) { - try { - db.execSQL( - "UPDATE " + FAVOURITE_TABLE_NAME + " SET latitude = ?, longitude = ? WHERE " + whereNameLatLon(), new Object[]{lat, lon, p.getName(), p.getLatitude(), p.getLongitude()}); //$NON-NLS-1$ //$NON-NLS-2$ - p.setLatitude(lat); - p.setLongitude(lon); - saveCurrentPointsIntoFile(); - } finally { - db.close(); - } - return true; - } - return false; - } - - private String whereNameLatLon() { - String singleFavourite = " " + FAVOURITE_COL_NAME + "= ? AND " + FAVOURITE_COL_LAT + " = ? AND " + FAVOURITE_COL_LON + " = ?"; - return singleFavourite; - } - - } diff --git a/OsmAnd/src/net/osmand/plus/itinerary/ItineraryHelper.java b/OsmAnd/src/net/osmand/plus/itinerary/ItineraryHelper.java index ec4e711269..a8b159c584 100644 --- a/OsmAnd/src/net/osmand/plus/itinerary/ItineraryHelper.java +++ b/OsmAnd/src/net/osmand/plus/itinerary/ItineraryHelper.java @@ -12,6 +12,7 @@ import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GpxSelectionHelper; @@ -51,6 +52,8 @@ public class ItineraryHelper { private static final Log log = PlatformUtil.getLog(ItineraryHelper.class); + public static final String PASSED_TIMESTAMP = "passed_timestamp"; + private static final String CATEGORIES_SPLIT = ","; private static final String FILE_TO_SAVE = "itinerary.gpx"; private static final String FILE_TO_BACKUP = "itinerary_bak.gpx"; @@ -75,12 +78,14 @@ public class ItineraryHelper { public static class ItineraryItem { - public Object object; - public ItineraryType type; + public final Object object; + public final ItineraryType type; + public final ItineraryGroup group; - public ItineraryItem(Object object, ItineraryType type) { - this.object = object; + public ItineraryItem(ItineraryGroup group, Object object, ItineraryType type) { this.type = type; + this.group = group; + this.object = object; } } @@ -88,7 +93,7 @@ public class ItineraryHelper { public String id; public String name; - public ItineraryType type = ItineraryType.MARKERS; + public ItineraryType type = ItineraryType.POINTS; public Set wptCategories; public boolean disabled; @@ -135,8 +140,10 @@ public class ItineraryHelper { FavoriteGroup favoriteGroup = app.getFavorites().getGroup(markersGroup.getId()); if (favoriteGroup != null) { for (FavouritePoint favouritePoint : favoriteGroup.getPoints()) { - ItineraryItem itineraryItem = new ItineraryItem(favouritePoint, ItineraryType.FAVOURITES); - itineraryGroup.itineraryItems.add(itineraryItem); + if (favouritePoint.getPassedTimestamp() == 0) { + ItineraryItem itineraryItem = new ItineraryItem(itineraryGroup, favouritePoint, ItineraryType.FAVOURITES); + itineraryGroup.itineraryItems.add(itineraryItem); + } } itineraryGroups.add(itineraryGroup); } @@ -155,7 +162,7 @@ public class ItineraryHelper { if (gpxFile != null && gpxFile.error == null) { for (WptPt wptPt : gpxFile.getPoints()) { if (shouldAddWpt(wptPt, itineraryGroup.wptCategories)) { - ItineraryItem itineraryItem = new ItineraryItem(wptPt, ItineraryType.TRACK); + ItineraryItem itineraryItem = new ItineraryItem(itineraryGroup, wptPt, ItineraryType.TRACK); itineraryGroup.itineraryItems.add(itineraryItem); } } @@ -166,16 +173,22 @@ public class ItineraryHelper { private void syncMarkersGroup(ItineraryGroup itineraryGroup, MapMarkersGroup markersGroup) { for (MapMarker marker : markersGroup.getMarkers()) { - ItineraryItem itineraryItem = new ItineraryItem(marker, ItineraryType.MARKERS); - itineraryGroup.itineraryItems.add(itineraryItem); + if (!marker.history) { + PointDescription pointDescription = marker.getOriginalPointDescription(); + if (pointDescription == null || !pointDescription.isWpt() && !pointDescription.isFavorite()) { + ItineraryItem itineraryItem = new ItineraryItem(itineraryGroup, marker, ItineraryType.MARKERS); + itineraryGroup.itineraryItems.add(itineraryItem); + } + } } itineraryGroups.add(itineraryGroup); } private boolean shouldAddWpt(WptPt wptPt, Set wptCategories) { boolean addAll = wptCategories == null || wptCategories.isEmpty(); - return addAll || wptCategories.contains(wptPt.category) - || wptPt.category == null && wptCategories.contains(""); + boolean passed = wptPt.getExtensionsToRead().containsKey(PASSED_TIMESTAMP); + return !passed && (addAll || wptCategories.contains(wptPt.category) + || wptPt.category == null && wptCategories.contains("")); } private void loadGroups() { @@ -480,6 +493,31 @@ public class ItineraryHelper { } } + @Nullable + public ItineraryItem getItineraryItem(@NonNull Object object) { + for (ItineraryGroup group : itineraryGroups) { + for (ItineraryItem item : group.itineraryItems) { + if (Algorithms.objectEquals(item.object, object)) { + return item; + } + } + } + return null; + } + + @Nullable + public ItineraryGroup getItineraryGroupById(String id, ItineraryType type) { + for (ItineraryGroup group : itineraryGroups) { + if ((id == null && group.id == null) + || (group.id != null && group.id.equals(id))) { + if (type == ItineraryType.POINTS || type == group.type) { + return group; + } + } + } + return null; + } + @Nullable public MapMarkersGroup getMapMarkerGroupById(String id, ItineraryType type) { for (MapMarkersGroup group : mapMarkersGroups) { diff --git a/OsmAnd/src/net/osmand/plus/itinerary/ItineraryType.java b/OsmAnd/src/net/osmand/plus/itinerary/ItineraryType.java index 4ac1d4fcfc..20cdb309f6 100644 --- a/OsmAnd/src/net/osmand/plus/itinerary/ItineraryType.java +++ b/OsmAnd/src/net/osmand/plus/itinerary/ItineraryType.java @@ -5,7 +5,8 @@ import androidx.annotation.NonNull; public enum ItineraryType { MARKERS("markers", -1), FAVOURITES("favourites", 0), - TRACK("track", 1); + TRACK("track", 1), + POINTS("points", 2); private int typeId; private String typeName; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java index 3833b0104d..f79da1a7a1 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java @@ -79,11 +79,6 @@ public class FavouritePointMenuController extends MenuController { return fav; } - @Override - protected Object getCorrespondingMapObject() { - return mapMarker; - } - @Override public List getTransportStopRoutes() { if (transportStopController != null) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java index adc9745d50..95a266563c 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/WptPtMenuController.java @@ -84,11 +84,6 @@ public class WptPtMenuController extends MenuController { return wpt; } - @Override - protected Object getCorrespondingMapObject() { - return mapMarker; - } - /* @Override public boolean handleSingleTapOnMap() { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java index 548cb1d2e9..3e6e069841 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java @@ -4,7 +4,6 @@ import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.graphics.drawable.Drawable; -import android.os.AsyncTask; import android.os.Bundle; import android.view.View; @@ -24,13 +23,12 @@ import net.osmand.plus.activities.SavingTrackHelper; import net.osmand.plus.base.PointImageDrawable; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.editors.WptPtEditor.OnDismissListener; -import net.osmand.plus.track.SaveGpxAsyncTask; -import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener; import net.osmand.util.Algorithms; -import java.io.File; import java.util.Map; +import static net.osmand.plus.mapcontextmenu.editors.WptPtEditorFragmentNew.saveGpx; + public class WptPtEditorFragment extends PointEditorFragment { @Nullable @@ -372,20 +370,4 @@ public class WptPtEditorFragment extends PointEditorFragment { public int getPointColor() { return color == 0 ? defaultColor : color; } - - private void saveGpx(final OsmandApplication app, final GPXFile gpxFile, final boolean gpxSelected) { - new SaveGpxAsyncTask(new File(gpxFile.path), gpxFile, new SaveGpxListener() { - @Override - public void gpxSavingStarted() { - - } - - @Override - public void gpxSavingFinished(Exception errorMessage) { - if (errorMessage == null && !gpxSelected) { - app.getSelectedGpxHelper().setGpxFileToDisplay(gpxFile); - } - } - }).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); - } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java index 6ffbba1893..ff32d4cf79 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java @@ -499,7 +499,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew { return true; } - private void saveGpx(final OsmandApplication app, final GPXFile gpxFile, final boolean gpxSelected) { + public static void saveGpx(final OsmandApplication app, final GPXFile gpxFile, final boolean gpxSelected) { new SaveGpxAsyncTask(new File(gpxFile.path), gpxFile, new SaveGpxListener() { @Override public void gpxSavingStarted() {