Compare commits
8 commits
master
...
itinerary_
Author | SHA1 | Date | |
---|---|---|---|
|
4e86058b42 | ||
|
de9fde3df6 | ||
|
f5e68691eb | ||
|
e6caccf45f | ||
|
4cdb616c83 | ||
|
4ca520005a | ||
|
e7d2e9d2f4 | ||
|
7ce5ac4aae |
35 changed files with 1112 additions and 724 deletions
|
@ -112,7 +112,7 @@ public class GPXUtilities {
|
|||
}
|
||||
|
||||
public interface GPXExtensionsReader {
|
||||
public boolean readExtensions(GPXFile res, XmlPullParser parser) throws Exception;
|
||||
public boolean readExtensions(GPXFile res, XmlPullParser parser) throws IOException, XmlPullParserException;
|
||||
}
|
||||
|
||||
public static class GPXExtensions {
|
||||
|
@ -1965,7 +1965,7 @@ public class GPXUtilities {
|
|||
}
|
||||
}
|
||||
|
||||
private static void writeNotNullText(XmlSerializer serializer, String tag, String value) throws IOException {
|
||||
public static void writeNotNullText(XmlSerializer serializer, String tag, String value) throws IOException {
|
||||
if (value != null) {
|
||||
serializer.startTag(null, tag);
|
||||
serializer.text(value);
|
||||
|
@ -2085,7 +2085,7 @@ public class GPXUtilities {
|
|||
}
|
||||
}
|
||||
|
||||
private static String readText(XmlPullParser parser, String key) throws XmlPullParserException, IOException {
|
||||
public static String readText(XmlPullParser parser, String key) throws XmlPullParserException, IOException {
|
||||
int tok;
|
||||
StringBuilder text = null;
|
||||
while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) {
|
||||
|
@ -2146,18 +2146,19 @@ public class GPXUtilities {
|
|||
return time;
|
||||
}
|
||||
|
||||
public static GPXFile loadGPXFile(File f) {
|
||||
public static GPXFile loadGPXFile(File file) {
|
||||
return loadGPXFile(file, null);
|
||||
}
|
||||
|
||||
public static GPXFile loadGPXFile(File f, GPXExtensionsReader extensionsReader) {
|
||||
FileInputStream fis = null;
|
||||
try {
|
||||
fis = new FileInputStream(f);
|
||||
GPXFile file = loadGPXFile(fis);
|
||||
GPXFile file = loadGPXFile(fis, extensionsReader);
|
||||
file.path = f.getAbsolutePath();
|
||||
file.modifiedTime = f.lastModified();
|
||||
|
||||
try {
|
||||
fis.close();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
Algorithms.closeStream(fis);
|
||||
return file;
|
||||
} catch (IOException e) {
|
||||
GPXFile res = new GPXFile(null);
|
||||
|
@ -2166,16 +2167,15 @@ public class GPXUtilities {
|
|||
res.error = e;
|
||||
return res;
|
||||
} finally {
|
||||
try {
|
||||
if (fis != null)
|
||||
fis.close();
|
||||
} catch (IOException ignore) {
|
||||
// ignore
|
||||
}
|
||||
Algorithms.closeStream(fis);
|
||||
}
|
||||
}
|
||||
|
||||
public static GPXFile loadGPXFile(InputStream f) {
|
||||
public static GPXFile loadGPXFile(InputStream stream) {
|
||||
return loadGPXFile(stream, null);
|
||||
}
|
||||
|
||||
public static GPXFile loadGPXFile(InputStream stream, GPXExtensionsReader extensionsReader) {
|
||||
GPXFile gpxFile = new GPXFile(null);
|
||||
SimpleDateFormat format = new SimpleDateFormat(GPX_TIME_FORMAT, Locale.US);
|
||||
format.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
|
@ -2183,7 +2183,7 @@ public class GPXUtilities {
|
|||
formatMillis.setTimeZone(TimeZone.getTimeZone("UTC"));
|
||||
try {
|
||||
XmlPullParser parser = PlatformUtil.newXMLPullParser();
|
||||
parser.setInput(getUTF8Reader(f));
|
||||
parser.setInput(getUTF8Reader(stream));
|
||||
Track routeTrack = new Track();
|
||||
TrkSegment routeTrackSegment = new TrkSegment();
|
||||
routeTrack.segments.add(routeTrackSegment);
|
||||
|
@ -2231,6 +2231,7 @@ public class GPXUtilities {
|
|||
break;
|
||||
|
||||
default:
|
||||
if (extensionsReader == null || !extensionsReader.readExtensions(gpxFile, parser)) {
|
||||
Map<String, String> values = readTextMap(parser, tag);
|
||||
if (values.size() > 0) {
|
||||
for (Entry<String, String> entry : values.entrySet()) {
|
||||
|
@ -2246,6 +2247,7 @@ public class GPXUtilities {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if (parse != null && tag.equals("extensions")) {
|
||||
|
|
|
@ -2,8 +2,8 @@ package net.osmand.util;
|
|||
|
||||
import net.osmand.IProgress;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.router.RouteColorize;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.router.RouteColorize;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
@ -26,8 +26,8 @@ import java.util.Collection;
|
|||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
@ -298,17 +298,25 @@ public class Algorithms {
|
|||
}
|
||||
|
||||
public static Set<String> decodeStringSet(String s) {
|
||||
return decodeStringSet(s, String.valueOf(CHAR_TOSPLIT));
|
||||
}
|
||||
|
||||
public static Set<String> decodeStringSet(String s, String split) {
|
||||
if (isEmpty(s)) {
|
||||
return Collections.emptySet();
|
||||
}
|
||||
return new HashSet<>(Arrays.asList(s.split(CHAR_TOSPLIT + "")));
|
||||
return new LinkedHashSet<>(Arrays.asList(s.split(split)));
|
||||
}
|
||||
|
||||
public static String encodeStringSet(Set<String> set) {
|
||||
return encodeStringSet(set, String.valueOf(CHAR_TOSPLIT));
|
||||
}
|
||||
|
||||
public static String encodeStringSet(Set<String> set, String split) {
|
||||
if (set != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s : set) {
|
||||
sb.append(s).append(CHAR_TOSPLIT);
|
||||
sb.append(s).append(split);
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
|
|
@ -16,10 +16,10 @@ 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;
|
||||
|
@ -28,6 +28,7 @@ import java.io.Serializable;
|
|||
public class FavouritePoint implements Serializable, LocationPoint {
|
||||
private static final long serialVersionUID = 729654300829771466L;
|
||||
|
||||
private static final String PASSED_TIMESTAMP = "passed_timestamp";
|
||||
private static final String HIDDEN = "hidden";
|
||||
private static final String ADDRESS_EXTENSION = "address";
|
||||
public static final BackgroundType DEFAULT_BACKGROUND_TYPE = BackgroundType.CIRCLE;
|
||||
|
@ -47,6 +48,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 +92,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 +240,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 +333,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
|
||||
|
@ -333,7 +347,8 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
|||
result = prime * result + (int) Math.floor(latitude * 10000);
|
||||
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) (timestamp ^ (timestamp >>> 32));
|
||||
result = prime * result + (int) (passedTimestamp ^ (passedTimestamp >>> 32));
|
||||
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 +482,10 @@ 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 +503,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));
|
||||
}
|
||||
|
|
|
@ -685,7 +685,7 @@ public class AppInitializer implements IProgress {
|
|||
// restore backuped favorites to normal file
|
||||
restoreBackupForFavoritesFiles();
|
||||
notifyEvent(InitEvents.RESTORE_BACKUPS);
|
||||
app.itineraryHelper.syncAllGroupsAsync();
|
||||
app.itineraryHelper.syncAllGroups();
|
||||
app.searchUICore.initSearchUICore();
|
||||
|
||||
checkLiveUpdatesAlerts();
|
||||
|
|
|
@ -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.mapmarkers.MapMarkersHelper;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||
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;
|
||||
|
@ -271,16 +272,13 @@ public class FavouritesDbHelper {
|
|||
return changed;
|
||||
}
|
||||
|
||||
private void runSyncWithMarkers(FavoriteGroup favGroup) {
|
||||
ItineraryGroup group = context.getItineraryHelper().getMarkersGroup(favGroup);
|
||||
if (group != null) {
|
||||
context.getItineraryHelper().runSynchronization(group);
|
||||
}
|
||||
private void syncGroupWithItinerary(FavoriteGroup favGroup) {
|
||||
context.getItineraryHelper().runSynchronizationAsync(favGroup);
|
||||
}
|
||||
|
||||
private boolean removeFromMarkers(FavoriteGroup favGroup) {
|
||||
MapMarkersHelper helper = context.getMapMarkersHelper();
|
||||
ItineraryGroup group = context.getItineraryHelper().getMarkersGroup(favGroup);
|
||||
ItineraryHelper helper = context.getItineraryHelper();
|
||||
MapMarkersGroup group = helper.getMarkersGroup(favGroup);
|
||||
if (group != null) {
|
||||
helper.removeMarkersGroup(group);
|
||||
return true;
|
||||
|
@ -308,7 +306,7 @@ public class FavouritesDbHelper {
|
|||
cachedFavoritePoints.remove(p);
|
||||
}
|
||||
for (FavoriteGroup gr : groupsToSync) {
|
||||
runSyncWithMarkers(gr);
|
||||
syncGroupWithItinerary(gr);
|
||||
}
|
||||
}
|
||||
if (groupsToDelete != null) {
|
||||
|
@ -331,7 +329,7 @@ public class FavouritesDbHelper {
|
|||
FavoriteGroup group = flatGroups.get(p.getCategory());
|
||||
if (group != null) {
|
||||
group.points.remove(p);
|
||||
runSyncWithMarkers(group);
|
||||
syncGroupWithItinerary(group);
|
||||
}
|
||||
cachedFavoritePoints.remove(p);
|
||||
}
|
||||
|
@ -387,7 +385,7 @@ public class FavouritesDbHelper {
|
|||
sortAll();
|
||||
saveCurrentPointsIntoFile();
|
||||
}
|
||||
runSyncWithMarkers(group);
|
||||
syncGroupWithItinerary(group);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -528,14 +526,14 @@ public class FavouritesDbHelper {
|
|||
}
|
||||
sortAll();
|
||||
saveCurrentPointsIntoFile();
|
||||
runSyncWithMarkers(getOrCreateGroup(p, 0));
|
||||
syncGroupWithItinerary(getOrCreateGroup(p, 0));
|
||||
return true;
|
||||
}
|
||||
|
||||
private void editAddressDescription(@NonNull FavouritePoint p, @Nullable String address) {
|
||||
p.setAddress(address);
|
||||
saveCurrentPointsIntoFile();
|
||||
runSyncWithMarkers(getOrCreateGroup(p, 0));
|
||||
syncGroupWithItinerary(getOrCreateGroup(p, 0));
|
||||
}
|
||||
|
||||
public boolean editFavourite(@NonNull FavouritePoint p, double lat, double lon) {
|
||||
|
@ -551,7 +549,7 @@ public class FavouritesDbHelper {
|
|||
p.setDescription(description);
|
||||
}
|
||||
saveCurrentPointsIntoFile();
|
||||
runSyncWithMarkers(getOrCreateGroup(p, 0));
|
||||
syncGroupWithItinerary(getOrCreateGroup(p, 0));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -570,7 +568,7 @@ public class FavouritesDbHelper {
|
|||
}
|
||||
}
|
||||
|
||||
private void backup(File backupFile, File externalFile) {
|
||||
public static void backup(File backupFile, File externalFile) {
|
||||
try {
|
||||
File f = new File(backupFile.getParentFile(), backupFile.getName());
|
||||
BZip2CompressorOutputStream out = new BZip2CompressorOutputStream(new FileOutputStream(f));
|
||||
|
@ -625,7 +623,11 @@ public class FavouritesDbHelper {
|
|||
}
|
||||
|
||||
public File getBackupFile() {
|
||||
File fld = new File(context.getAppPath(null), BACKUP_FOLDER);
|
||||
return getBackupFile(context, "favourites_bak_");
|
||||
}
|
||||
|
||||
public static File getBackupFile(OsmandApplication app, String fileName) {
|
||||
File fld = new File(app.getAppPath(null), BACKUP_FOLDER);
|
||||
if (!fld.exists()) {
|
||||
fld.mkdirs();
|
||||
}
|
||||
|
@ -638,7 +640,7 @@ public class FavouritesDbHelper {
|
|||
if (back < 10) {
|
||||
backPrefix = "0" + backPrefix;
|
||||
}
|
||||
File bak = new File(fld, "favourites_bak_" + backPrefix + ".gpx.bz2");
|
||||
File bak = new File(fld, fileName + backPrefix + ".gpx.bz2");
|
||||
if (!bak.exists()) {
|
||||
return bak;
|
||||
} else if (bak.lastModified() < firstModifiedMin) {
|
||||
|
@ -835,10 +837,8 @@ public class FavouritesDbHelper {
|
|||
}
|
||||
for (WptPt p : res.getPoints()) {
|
||||
FavouritePoint fp = FavouritePoint.fromWpt(p, context);
|
||||
if (fp != null) {
|
||||
points.put(getKey(fp), fp);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -851,7 +851,7 @@ public class FavouritesDbHelper {
|
|||
}
|
||||
}
|
||||
group.color = color;
|
||||
runSyncWithMarkers(gr);
|
||||
syncGroupWithItinerary(gr);
|
||||
}
|
||||
if (group.visible != visible) {
|
||||
FavoriteGroup gr = flatGroups.get(group.name);
|
||||
|
@ -859,7 +859,7 @@ public class FavouritesDbHelper {
|
|||
for (FavouritePoint p : gr.points) {
|
||||
p.setVisible(visible);
|
||||
}
|
||||
runSyncWithMarkers(gr);
|
||||
syncGroupWithItinerary(gr);
|
||||
}
|
||||
if (!group.name.equals(newName)) {
|
||||
FavoriteGroup gr = flatGroups.remove(group.name);
|
||||
|
@ -886,13 +886,6 @@ public class FavouritesDbHelper {
|
|||
saveCurrentPointsIntoFile();
|
||||
}
|
||||
|
||||
protected void createDefaultCategories() {
|
||||
addEmptyCategory(context.getString(R.string.favorite_home_category));
|
||||
addEmptyCategory(context.getString(R.string.favorite_friends_category));
|
||||
addEmptyCategory(context.getString(R.string.favorite_places_category));
|
||||
addEmptyCategory(context.getString(R.string.shared_string_others));
|
||||
}
|
||||
|
||||
private FavoriteGroup getOrCreateGroup(FavouritePoint p, int defColor) {
|
||||
if (flatGroups.containsKey(p.getCategory())) {
|
||||
return flatGroups.get(p.getCategory());
|
||||
|
@ -990,108 +983,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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -30,7 +30,6 @@ import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
|
|||
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||
import net.osmand.plus.helpers.enums.MetricsConstants;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
|
||||
import net.osmand.plus.track.GpxSplitType;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -582,7 +581,7 @@ public class GpxSelectionHelper {
|
|||
} else if (obj.has(BACKUP)) {
|
||||
selectedGpxFilesBackUp.put(gpx, gpx.modifiedTime);
|
||||
} else {
|
||||
SelectedGpxFile file = selectGpxFile(gpx, true, false, true, selectedByUser, false, false);
|
||||
SelectedGpxFile file = selectGpxFile(gpx, true, false, false, selectedByUser, false, false);
|
||||
if (obj.has(HIDDEN_GROUPS)) {
|
||||
readHiddenGroups(file, obj.getString(HIDDEN_GROUPS));
|
||||
}
|
||||
|
@ -726,7 +725,7 @@ public class GpxSelectionHelper {
|
|||
}
|
||||
}
|
||||
if (syncGroup) {
|
||||
syncGpxWithMarkers(gpx);
|
||||
syncGpxWithItinerary(gpx);
|
||||
}
|
||||
if (sf != null) {
|
||||
sf.splitProcessed = false;
|
||||
|
@ -802,30 +801,27 @@ public class GpxSelectionHelper {
|
|||
|
||||
public void clearPoints(GPXFile gpxFile) {
|
||||
gpxFile.clearPoints();
|
||||
syncGpxWithMarkers(gpxFile);
|
||||
syncGpxWithItinerary(gpxFile);
|
||||
}
|
||||
|
||||
public void addPoint(WptPt point, GPXFile gpxFile) {
|
||||
gpxFile.addPoint(point);
|
||||
syncGpxWithMarkers(gpxFile);
|
||||
syncGpxWithItinerary(gpxFile);
|
||||
}
|
||||
|
||||
public void addPoints(Collection<? extends WptPt> collection, GPXFile gpxFile) {
|
||||
gpxFile.addPoints(collection);
|
||||
syncGpxWithMarkers(gpxFile);
|
||||
syncGpxWithItinerary(gpxFile);
|
||||
}
|
||||
|
||||
public boolean removePoint(WptPt point, GPXFile gpxFile) {
|
||||
boolean res = gpxFile.deleteWptPt(point);
|
||||
syncGpxWithMarkers(gpxFile);
|
||||
syncGpxWithItinerary(gpxFile);
|
||||
return res;
|
||||
}
|
||||
|
||||
private void syncGpxWithMarkers(GPXFile gpxFile) {
|
||||
ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile);
|
||||
if (group != null) {
|
||||
app.getItineraryHelper().runSynchronization(group);
|
||||
}
|
||||
private void syncGpxWithItinerary(GPXFile gpxFile) {
|
||||
app.getItineraryHelper().runSynchronizationAsync(gpxFile);
|
||||
}
|
||||
|
||||
public static class SelectedGpxFile {
|
||||
|
|
|
@ -27,8 +27,6 @@ import androidx.fragment.app.FragmentManager;
|
|||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
|
@ -40,6 +38,8 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerHalfItem;
|
|||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.ColorDialogs;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||
import net.osmand.plus.itinerary.ItineraryHelper;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragment {
|
||||
|
@ -177,9 +177,9 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme
|
|||
if (group.getPoints().size() > 0) {
|
||||
items.add(new DividerHalfItem(getContext()));
|
||||
|
||||
final MapMarkersHelper markersHelper = app.getMapMarkersHelper();
|
||||
final ItineraryHelper itineraryHelper = app.getItineraryHelper();
|
||||
final FavoriteGroup favGroup = this.group;
|
||||
final ItineraryGroup markersGr = app.getItineraryHelper().getMarkersGroup(this.group);
|
||||
final MapMarkersGroup markersGr = app.getItineraryHelper().getMarkersGroup(this.group);
|
||||
final boolean synced = markersGr != null;
|
||||
|
||||
BaseBottomSheetItem markersGroupItem = new SimpleBottomSheetItem.Builder()
|
||||
|
@ -190,7 +190,7 @@ public class EditFavoriteGroupDialogFragment extends MenuBottomSheetDialogFragme
|
|||
@Override
|
||||
public void onClick(View view) {
|
||||
if (synced) {
|
||||
markersHelper.removeMarkersGroup(markersGr);
|
||||
itineraryHelper.removeMarkersGroup(markersGr);
|
||||
} else {
|
||||
app.getItineraryHelper().addOrEnableGroup(favGroup);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.PluginsFragment;
|
||||
import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
|
||||
import net.osmand.plus.mapsource.EditMapSourceDialogFragment;
|
||||
import net.osmand.plus.openplacereviews.OPRConstants;
|
||||
|
@ -219,7 +219,7 @@ public class IntentHelper {
|
|||
if (intent.hasExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS)) {
|
||||
Bundle openMapMarkersGroupsExtra = intent.getBundleExtra(MapMarkersDialogFragment.OPEN_MAP_MARKERS_GROUPS);
|
||||
if (openMapMarkersGroupsExtra != null) {
|
||||
MapMarkersDialogFragment.showInstance(mapActivity, openMapMarkersGroupsExtra.getString(ItineraryGroup.MARKERS_SYNC_GROUP_ID));
|
||||
MapMarkersDialogFragment.showInstance(mapActivity, openMapMarkersGroupsExtra.getString(MapMarkersGroup.MARKERS_SYNC_GROUP_ID));
|
||||
}
|
||||
mapActivity.setIntent(null);
|
||||
}
|
||||
|
|
|
@ -1,187 +1,69 @@
|
|||
package net.osmand.plus.itinerary;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import net.osmand.plus.mapmarkers.CategoriesSubHeader;
|
||||
import net.osmand.plus.mapmarkers.GroupHeader;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
import net.osmand.plus.mapmarkers.ShowHideHistoryButton;
|
||||
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static net.osmand.plus.itinerary.ItineraryHelper.CATEGORIES_SPLIT;
|
||||
|
||||
public class ItineraryGroup {
|
||||
|
||||
public static final int ANY_TYPE = -1;
|
||||
public static final int FAVORITES_TYPE = 0;
|
||||
public static final int GPX_TYPE = 1;
|
||||
|
||||
public static final String MARKERS_SYNC_GROUP_ID = "markers_sync_group_id";
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private int type = ANY_TYPE;
|
||||
private Set<String> wptCategories;
|
||||
private long creationDate;
|
||||
private boolean disabled;
|
||||
private boolean visible = true;
|
||||
private boolean wasShown = false;
|
||||
private boolean visibleUntilRestart;
|
||||
private List<MapMarker> markers = new ArrayList<>();
|
||||
private TravelArticle wikivoyageArticle;
|
||||
// TODO should be removed from this class:
|
||||
private GroupHeader header;
|
||||
private CategoriesSubHeader categoriesSubHeader;
|
||||
private ShowHideHistoryButton showHideHistoryButton;
|
||||
public String id;
|
||||
public String name;
|
||||
public ItineraryType type = ItineraryType.MARKERS;
|
||||
public Set<String> wptCategories;
|
||||
public List<ItineraryItem> itineraryItems = new ArrayList<>();
|
||||
|
||||
public ItineraryGroup() {
|
||||
|
||||
}
|
||||
|
||||
public ItineraryGroup(@NonNull String id, @NonNull String name, int type) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
public ItineraryGroup(ItineraryGroup group) {
|
||||
this.id = group.id;
|
||||
this.name = group.name;
|
||||
this.type = group.type;
|
||||
this.wptCategories = group.wptCategories;
|
||||
this.itineraryItems.addAll(group.itineraryItems);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
public static ItineraryGroup createGroup(MapMarkersGroup markersGroup) {
|
||||
ItineraryGroup group = new ItineraryGroup();
|
||||
group.id = markersGroup.getId();
|
||||
group.name = markersGroup.getName();
|
||||
group.type = markersGroup.getType();
|
||||
group.wptCategories = markersGroup.getWptCategories();
|
||||
return group;
|
||||
}
|
||||
|
||||
public String getGpxPath() {
|
||||
return id;
|
||||
public static ItineraryGroup createGroup(ItineraryGroupInfo groupInfo) {
|
||||
ItineraryGroup group = new ItineraryGroup();
|
||||
group.name = groupInfo.name;
|
||||
group.type = ItineraryType.findTypeForName(groupInfo.type);
|
||||
group.id = group.type == ItineraryType.TRACK ? groupInfo.path : groupInfo.name;
|
||||
group.wptCategories = Algorithms.decodeStringSet(groupInfo.categories, CATEGORIES_SPLIT);
|
||||
return group;
|
||||
}
|
||||
|
||||
public TravelArticle getWikivoyageArticle() {
|
||||
return wikivoyageArticle;
|
||||
public ItineraryGroupInfo convertToGroupInfo() {
|
||||
ItineraryGroupInfo groupInfo = new ItineraryGroupInfo();
|
||||
groupInfo.name = name;
|
||||
groupInfo.type = type.name().toLowerCase();
|
||||
groupInfo.path = type == ItineraryType.TRACK ? id : null;
|
||||
groupInfo.alias = groupInfo.type + ":" + (name != null ? name : "");
|
||||
if (!Algorithms.isEmpty(wptCategories)) {
|
||||
groupInfo.categories = Algorithms.encodeStringSet(wptCategories, CATEGORIES_SPLIT);
|
||||
}
|
||||
return groupInfo;
|
||||
}
|
||||
|
||||
public long getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
public void setCreationDate(long creationDate) {
|
||||
this.creationDate = creationDate;
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
public void setMarkers(List<MapMarker> markers) {
|
||||
this.markers = markers;
|
||||
}
|
||||
|
||||
public void setHeader(GroupHeader header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
public void setCategoriesSubHeader(CategoriesSubHeader categoriesSubHeader) {
|
||||
this.categoriesSubHeader = categoriesSubHeader;
|
||||
}
|
||||
|
||||
public void setShowHideHistoryButton(ShowHideHistoryButton showHideHistoryButton) {
|
||||
this.showHideHistoryButton = showHideHistoryButton;
|
||||
}
|
||||
|
||||
public boolean isWasShown() {
|
||||
return wasShown;
|
||||
}
|
||||
|
||||
public boolean isVisibleUntilRestart() {
|
||||
return visibleUntilRestart;
|
||||
}
|
||||
|
||||
public void setWikivoyageArticle(TravelArticle wikivoyageArticle) {
|
||||
this.wikivoyageArticle = wikivoyageArticle;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setWptCategories(Set<String> wptCategories) {
|
||||
this.wptCategories = wptCategories;
|
||||
}
|
||||
|
||||
public Set<String> getWptCategories() {
|
||||
return wptCategories;
|
||||
}
|
||||
|
||||
public boolean isDisabled() {
|
||||
return disabled;
|
||||
}
|
||||
|
||||
public void setDisabled(boolean disabled) {
|
||||
this.disabled = disabled;
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
public boolean wasShown() {
|
||||
return wasShown;
|
||||
}
|
||||
|
||||
public void setWasShown(boolean wasShown) {
|
||||
this.wasShown = wasShown;
|
||||
}
|
||||
|
||||
public void setVisibleUntilRestart(boolean visibleUntilRestart) {
|
||||
this.visibleUntilRestart = visibleUntilRestart;
|
||||
}
|
||||
|
||||
public List<MapMarker> getMarkers() {
|
||||
return markers;
|
||||
}
|
||||
|
||||
public GroupHeader getGroupHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
public CategoriesSubHeader getCategoriesSubHeader() {
|
||||
return categoriesSubHeader;
|
||||
}
|
||||
|
||||
public ShowHideHistoryButton getShowHideHistoryButton() {
|
||||
return showHideHistoryButton;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getWptCategoriesString() {
|
||||
if (wptCategories != null) {
|
||||
return Algorithms.encodeStringSet(wptCategories);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<MapMarker> getActiveMarkers() {
|
||||
List<MapMarker> markers = new ArrayList<>(this.markers);
|
||||
List<MapMarker> activeMarkers = new ArrayList<>(markers.size());
|
||||
for (MapMarker marker : markers) {
|
||||
if (!marker.history) {
|
||||
activeMarkers.add(marker);
|
||||
}
|
||||
}
|
||||
return activeMarkers;
|
||||
}
|
||||
|
||||
public List<MapMarker> getHistoryMarkers() {
|
||||
List<MapMarker> historyMarkers = new ArrayList<>();
|
||||
for (MapMarker marker : markers) {
|
||||
if (marker.history) {
|
||||
historyMarkers.add(marker);
|
||||
}
|
||||
}
|
||||
return historyMarkers;
|
||||
public static class ItineraryGroupInfo {
|
||||
public String name;
|
||||
public String type;
|
||||
public String path;
|
||||
public String alias;
|
||||
public String categories;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,33 +5,50 @@ import android.os.AsyncTask;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.GPXExtensionsReader;
|
||||
import net.osmand.GPXUtilities.GPXExtensionsWriter;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
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;
|
||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||
import net.osmand.plus.GPXDatabase;
|
||||
import net.osmand.plus.GPXDatabase.GpxDataItem;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup.ItineraryGroupInfo;
|
||||
import net.osmand.plus.mapmarkers.CategoriesSubHeader;
|
||||
import net.osmand.plus.mapmarkers.GroupHeader;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersHelper.OnGroupSyncedListener;
|
||||
import net.osmand.plus.mapmarkers.ShowHideHistoryButton;
|
||||
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
||||
import net.osmand.plus.wikivoyage.data.TravelHelper;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.xmlpull.v1.XmlSerializer;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
@ -39,11 +56,22 @@ import java.util.Set;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import static net.osmand.GPXUtilities.readText;
|
||||
import static net.osmand.GPXUtilities.writeNotNullText;
|
||||
import static net.osmand.plus.FavouritesDbHelper.backup;
|
||||
import static net.osmand.plus.mapmarkers.MapMarkersDbHelper.DB_NAME;
|
||||
import static net.osmand.plus.mapmarkers.MapMarkersHelper.BY_DATE_ADDED_DESC;
|
||||
import static net.osmand.util.Algorithms.getFileNameWithoutExtension;
|
||||
|
||||
public class ItineraryHelper {
|
||||
|
||||
private static final Log LOG = PlatformUtil.getLog(ItineraryHelper.class);
|
||||
private static final Log log = PlatformUtil.getLog(ItineraryHelper.class);
|
||||
|
||||
protected static final String CATEGORIES_SPLIT = ",";
|
||||
private static final String FILE_TO_SAVE = "itinerary.gpx";
|
||||
private static final String FILE_TO_BACKUP = "itinerary_bak.gpx";
|
||||
private static final String ITINERARY_ID = "itinerary_id";
|
||||
private static final String ITINERARY_GROUP = "itinerary_group";
|
||||
|
||||
private OsmandApplication app;
|
||||
|
||||
|
@ -53,28 +81,329 @@ public class ItineraryHelper {
|
|||
private ExecutorService executorService = Executors.newSingleThreadExecutor();
|
||||
|
||||
private List<ItineraryGroup> itineraryGroups = new ArrayList<>();
|
||||
private List<MapMarkersGroup> mapMarkersGroups = new ArrayList<>();
|
||||
private Set<OnGroupSyncedListener> syncListeners = new HashSet<>();
|
||||
|
||||
public ItineraryHelper(@NonNull OsmandApplication app) {
|
||||
this.app = app;
|
||||
markersHelper = app.getMapMarkersHelper();
|
||||
markersDbHelper = app.getMapMarkersDbHelper();
|
||||
loadGroups();
|
||||
loadMarkersGroups();
|
||||
}
|
||||
|
||||
public List<ItineraryGroup> getItineraryGroups() {
|
||||
return itineraryGroups;
|
||||
}
|
||||
|
||||
public void syncAllGroupsAsync() {
|
||||
for (ItineraryGroup group : itineraryGroups) {
|
||||
if (group.getId() != null && group.getName() != null) {
|
||||
runSynchronization(group);
|
||||
public List<MapMarkersGroup> getMapMarkersGroups() {
|
||||
return mapMarkersGroups;
|
||||
}
|
||||
|
||||
public void syncAllGroups() {
|
||||
File internalFile = getInternalFile();
|
||||
if (!internalFile.exists()) {
|
||||
File dbPath = app.getDatabasePath(DB_NAME);
|
||||
if (dbPath.exists()) {
|
||||
loadMarkersGroups();
|
||||
syncMarkersGroups();
|
||||
syncMarkersGroupsToItinerary();
|
||||
saveGroupsIntoFile();
|
||||
}
|
||||
}
|
||||
Map<Object, ItineraryGroup> groups = new LinkedHashMap<>();
|
||||
Map<Object, ItineraryGroup> extGroups = new LinkedHashMap<>();
|
||||
loadGPXFile(internalFile, groups);
|
||||
loadGPXFile(getExternalFile(), extGroups);
|
||||
|
||||
boolean changed = merge(extGroups, groups);
|
||||
itineraryGroups = new ArrayList<>(groups.values());
|
||||
|
||||
if (changed || !getExternalFile().exists()) {
|
||||
saveGroupsIntoFile();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean merge(Map<Object, ItineraryGroup> source, Map<Object, ItineraryGroup> destination) {
|
||||
boolean changed = false;
|
||||
for (Map.Entry<Object, ItineraryGroup> entry : source.entrySet()) {
|
||||
Object ks = entry.getKey();
|
||||
if (!destination.containsKey(ks)) {
|
||||
changed = true;
|
||||
destination.put(ks, entry.getValue());
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
private boolean loadGPXFile(File file, Map<Object, ItineraryGroup> groups) {
|
||||
if (!file.exists()) {
|
||||
return false;
|
||||
}
|
||||
List<ItineraryGroupInfo> groupInfos = new ArrayList<>();
|
||||
GPXFile gpxFile = loadGPXFile(file, groupInfos);
|
||||
if (gpxFile.error != null) {
|
||||
return false;
|
||||
}
|
||||
List<ItineraryGroup> secondaryGroups = new ArrayList<>();
|
||||
for (ItineraryGroupInfo groupInfo : groupInfos) {
|
||||
ItineraryGroup group = ItineraryGroup.createGroup(groupInfo);
|
||||
if (group.name != null) {
|
||||
secondaryGroups.add(group);
|
||||
}
|
||||
Object key = group.name != null ? group.name : group.type;
|
||||
groups.put(key, group);
|
||||
}
|
||||
for (WptPt point : gpxFile.getPoints()) {
|
||||
String itineraryId = point.getExtensionsToRead().get(ITINERARY_ID);
|
||||
if (!Algorithms.isEmpty(itineraryId)) {
|
||||
List<String> list = new ArrayList<>(Algorithms.decodeStringSet(itineraryId, ":"));
|
||||
if (list.size() == 3) {
|
||||
String type = list.get(0);
|
||||
String group = list.get(1);
|
||||
|
||||
ItineraryType itineraryType = ItineraryType.findTypeForName(type);
|
||||
Object key = Algorithms.isEmpty(group) ? itineraryType : group;
|
||||
|
||||
ItineraryGroup itineraryGroup = groups.get(key);
|
||||
if (itineraryGroup != null && itineraryGroup.id == null && itineraryGroup.name == null) {
|
||||
addPointToGroup(itineraryGroup, point, list.get(2));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
syncItineraryGroups(secondaryGroups);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void addPointToGroup(ItineraryGroup group, WptPt point, String pointId) {
|
||||
if (group.type == ItineraryType.FAVOURITES) {
|
||||
FavouritePoint favouritePoint = app.getFavorites().getVisibleFavByLatLon(new LatLon(point.lat, point.lon));
|
||||
if (favouritePoint != null && favouritePoint.getPassedTimestamp() == 0) {
|
||||
ItineraryItem item = new ItineraryItem(group, favouritePoint, ItineraryType.FAVOURITES);
|
||||
group.itineraryItems.add(item);
|
||||
}
|
||||
} else if (group.type == ItineraryType.TRACK) {
|
||||
if (shouldAddWpt(point, group.wptCategories)) {
|
||||
ItineraryItem item = new ItineraryItem(group, point, ItineraryType.TRACK);
|
||||
group.itineraryItems.add(item);
|
||||
}
|
||||
} else {
|
||||
MapMarker marker = markersHelper.getMapMarker(pointId);
|
||||
if (marker != null && !marker.history) {
|
||||
ItineraryItem item = new ItineraryItem(group, marker, ItineraryType.MARKERS);
|
||||
group.itineraryItems.add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateGroupWptCategories(@NonNull ItineraryGroup group, Set<String> wptCategories) {
|
||||
private GPXFile loadGPXFile(File file, final List<ItineraryGroupInfo> groupInfos) {
|
||||
return GPXUtilities.loadGPXFile(file, new GPXExtensionsReader() {
|
||||
@Override
|
||||
public boolean readExtensions(GPXFile res, XmlPullParser parser) throws IOException, XmlPullParserException {
|
||||
if (ITINERARY_GROUP.equalsIgnoreCase(parser.getName())) {
|
||||
ItineraryGroupInfo groupInfo = new ItineraryGroupInfo();
|
||||
|
||||
int tok;
|
||||
while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) {
|
||||
if (tok == XmlPullParser.START_TAG) {
|
||||
String tagName = parser.getName().toLowerCase();
|
||||
if ("name".equalsIgnoreCase(tagName)) {
|
||||
groupInfo.name = readText(parser, tagName);
|
||||
} else if ("type".equalsIgnoreCase(tagName)) {
|
||||
groupInfo.type = readText(parser, tagName);
|
||||
} else if ("path".equalsIgnoreCase(tagName)) {
|
||||
groupInfo.path = readText(parser, tagName);
|
||||
} else if ("alias".equalsIgnoreCase(tagName)) {
|
||||
groupInfo.alias = readText(parser, tagName);
|
||||
} else if ("categories".equalsIgnoreCase(tagName)) {
|
||||
groupInfo.categories = readText(parser, tagName);
|
||||
}
|
||||
} else if (tok == XmlPullParser.END_TAG) {
|
||||
if (ITINERARY_GROUP.equalsIgnoreCase(parser.getName())) {
|
||||
groupInfos.add(groupInfo);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void saveGroupsIntoFile() {
|
||||
try {
|
||||
saveFile(getInternalFile());
|
||||
saveFile(getExternalFile());
|
||||
backup(getBackupFile(), getExternalFile());
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public Exception saveFile(File file) {
|
||||
GPXFile gpxFile = asGpxFile();
|
||||
return GPXUtilities.writeGpxFile(file, gpxFile);
|
||||
}
|
||||
|
||||
public GPXFile asGpxFile() {
|
||||
GPXFile gpxFile = new GPXFile(Version.getFullVersion(app));
|
||||
List<ItineraryGroupInfo> groups = new ArrayList<>();
|
||||
for (ItineraryGroup group : itineraryGroups) {
|
||||
ItineraryGroupInfo groupInfo = group.convertToGroupInfo();
|
||||
|
||||
for (ItineraryItem item : group.itineraryItems) {
|
||||
WptPt wptPt = new WptPt();
|
||||
wptPt.lat = item.latLon.getLatitude();
|
||||
wptPt.lon = item.latLon.getLongitude();
|
||||
wptPt.getExtensionsToWrite().put(ITINERARY_ID, groupInfo.alias + ":" + item.id);
|
||||
gpxFile.addPoint(wptPt);
|
||||
}
|
||||
groups.add(groupInfo);
|
||||
}
|
||||
assignRouteExtensionWriter(gpxFile, groups);
|
||||
return gpxFile;
|
||||
}
|
||||
|
||||
private void assignRouteExtensionWriter(GPXFile gpxFile, final List<ItineraryGroupInfo> groups) {
|
||||
if (gpxFile.getExtensionsWriter() == null) {
|
||||
gpxFile.setExtensionsWriter(new GPXExtensionsWriter() {
|
||||
@Override
|
||||
public void writeExtensions(XmlSerializer serializer) {
|
||||
for (ItineraryGroupInfo group : groups) {
|
||||
try {
|
||||
serializer.startTag(null, "osmand:itinerary_group");
|
||||
|
||||
writeNotNullText(serializer, "osmand:name", group.name);
|
||||
writeNotNullText(serializer, "osmand:type", group.type);
|
||||
writeNotNullText(serializer, "osmand:path", group.path);
|
||||
writeNotNullText(serializer, "osmand:alias", group.alias);
|
||||
writeNotNullText(serializer, "osmand:categories", group.categories);
|
||||
|
||||
serializer.endTag(null, "osmand:itinerary_group");
|
||||
} catch (IOException e) {
|
||||
log.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void syncMarkersGroups() {
|
||||
for (MapMarkersGroup group : mapMarkersGroups) {
|
||||
if (group.getId() != null && group.getName() != null) {
|
||||
runGroupSynchronization(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<ItineraryGroup> convertToItineraryGroups() {
|
||||
List<ItineraryGroup> groups = new ArrayList<>();
|
||||
for (MapMarkersGroup markersGroup : mapMarkersGroups) {
|
||||
groups.add(ItineraryGroup.createGroup(markersGroup));
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
public void syncMarkersGroupsToItinerary() {
|
||||
List<ItineraryGroup> markersGroups = convertToItineraryGroups();
|
||||
itineraryGroups.addAll(syncItineraryGroups(markersGroups));
|
||||
}
|
||||
|
||||
public List<ItineraryGroup> syncItineraryGroups(List<ItineraryGroup> itineraryGroups) {
|
||||
List<ItineraryGroup> processedGroups = new ArrayList<>();
|
||||
for (ItineraryGroup group : itineraryGroups) {
|
||||
if (group.type == ItineraryType.FAVOURITES) {
|
||||
syncFavoriteGroup(processedGroups, group);
|
||||
} else if (group.type == ItineraryType.TRACK) {
|
||||
syncTrackGroup(processedGroups, group);
|
||||
} else {
|
||||
syncMarkersGroup(processedGroups, group);
|
||||
}
|
||||
}
|
||||
return processedGroups;
|
||||
}
|
||||
|
||||
private void syncFavoriteGroup(List<ItineraryGroup> processedGroups, ItineraryGroup group) {
|
||||
FavoriteGroup favoriteGroup = app.getFavorites().getGroup(group.id);
|
||||
if (favoriteGroup != null && favoriteGroup.isVisible()) {
|
||||
for (FavouritePoint point : favoriteGroup.getPoints()) {
|
||||
if (point.getPassedTimestamp() == 0) {
|
||||
ItineraryItem item = new ItineraryItem(group, point, ItineraryType.FAVOURITES);
|
||||
group.itineraryItems.add(item);
|
||||
}
|
||||
}
|
||||
processedGroups.add(group);
|
||||
}
|
||||
}
|
||||
|
||||
private void syncTrackGroup(List<ItineraryGroup> processedGroups, ItineraryGroup group) {
|
||||
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(group.id);
|
||||
if (selectedGpxFile != null) {
|
||||
for (WptPt wptPt : selectedGpxFile.getGpxFile().getPoints()) {
|
||||
if (shouldAddWpt(wptPt, group.wptCategories)) {
|
||||
ItineraryItem item = new ItineraryItem(group, wptPt, ItineraryType.TRACK);
|
||||
group.itineraryItems.add(item);
|
||||
}
|
||||
}
|
||||
processedGroups.add(group);
|
||||
}
|
||||
}
|
||||
|
||||
private void syncMarkersGroup(List<ItineraryGroup> processedGroups, ItineraryGroup group) {
|
||||
ItineraryGroup trackGroup = new ItineraryGroup(group);
|
||||
ItineraryGroup markersGroup = new ItineraryGroup(group);
|
||||
ItineraryGroup favouritesGroup = new ItineraryGroup(group);
|
||||
|
||||
trackGroup.type = ItineraryType.TRACK;
|
||||
markersGroup.type = ItineraryType.MARKERS;
|
||||
favouritesGroup.type = ItineraryType.FAVOURITES;
|
||||
|
||||
List<MapMarker> allMarkers = new ArrayList<>(markersHelper.getMapMarkers());
|
||||
for (MapMarker marker : allMarkers) {
|
||||
PointDescription description = marker.getOriginalPointDescription();
|
||||
if (description.isFavorite()) {
|
||||
FavouritePoint point = app.getFavorites().getVisibleFavByLatLon(marker.point);
|
||||
if (point != null && point.getPassedTimestamp() == 0) {
|
||||
ItineraryItem item = new ItineraryItem(favouritesGroup, point, ItineraryType.FAVOURITES);
|
||||
favouritesGroup.itineraryItems.add(item);
|
||||
}
|
||||
} else if (description.isWpt()) {
|
||||
WptPt wptPt = app.getSelectedGpxHelper().getVisibleWayPointByLatLon(marker.point);
|
||||
if (wptPt != null && shouldAddWpt(wptPt, null)) {
|
||||
ItineraryItem item = new ItineraryItem(trackGroup, wptPt, ItineraryType.TRACK);
|
||||
trackGroup.itineraryItems.add(item);
|
||||
}
|
||||
} else if (!marker.history) {
|
||||
ItineraryItem item = new ItineraryItem(markersGroup, marker, ItineraryType.MARKERS);
|
||||
markersGroup.itineraryItems.add(item);
|
||||
}
|
||||
}
|
||||
if (!Algorithms.isEmpty(trackGroup.itineraryItems)) {
|
||||
processedGroups.add(trackGroup);
|
||||
}
|
||||
if (!Algorithms.isEmpty(markersGroup.itineraryItems)) {
|
||||
processedGroups.add(markersGroup);
|
||||
}
|
||||
if (!Algorithms.isEmpty(favouritesGroup.itineraryItems)) {
|
||||
processedGroups.add(favouritesGroup);
|
||||
}
|
||||
}
|
||||
|
||||
public File getExternalFile() {
|
||||
return new File(app.getAppPath(null), FILE_TO_SAVE);
|
||||
}
|
||||
|
||||
private File getInternalFile() {
|
||||
return app.getFileStreamPath(FILE_TO_BACKUP);
|
||||
}
|
||||
|
||||
public File getBackupFile() {
|
||||
return FavouritesDbHelper.getBackupFile(app, "itinerary_bak_");
|
||||
}
|
||||
|
||||
public void updateGroupWptCategories(@NonNull MapMarkersGroup group, Set<String> wptCategories) {
|
||||
String id = group.getId();
|
||||
if (id != null) {
|
||||
group.setWptCategories(wptCategories);
|
||||
|
@ -84,24 +413,24 @@ public class ItineraryHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void enableGroup(@NonNull ItineraryGroup gr) {
|
||||
public void enableGroup(@NonNull MapMarkersGroup gr) {
|
||||
// check if group doesn't exist internally
|
||||
if (!itineraryGroups.contains(gr)) {
|
||||
if (!mapMarkersGroups.contains(gr)) {
|
||||
addGroupInternally(gr);
|
||||
}
|
||||
if (gr.isDisabled()) {
|
||||
updateGroupDisabled(gr, false);
|
||||
}
|
||||
runSynchronization(gr);
|
||||
runSynchronizationAsync(gr);
|
||||
}
|
||||
|
||||
public void updateGroups() {
|
||||
for (ItineraryGroup group : itineraryGroups) {
|
||||
markersHelper.updateGroup(group);
|
||||
for (MapMarkersGroup group : mapMarkersGroups) {
|
||||
updateGroup(group);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateGroupDisabled(@NonNull ItineraryGroup group, boolean disabled) {
|
||||
public void updateGroupDisabled(@NonNull MapMarkersGroup group, boolean disabled) {
|
||||
String id = group.getId();
|
||||
if (id != null) {
|
||||
markersDbHelper.updateGroupDisabled(id, disabled);
|
||||
|
@ -111,8 +440,8 @@ public class ItineraryHelper {
|
|||
|
||||
public List<MapMarker> getMapMarkersFromDefaultGroups(boolean history) {
|
||||
List<MapMarker> mapMarkers = new ArrayList<>();
|
||||
for (ItineraryGroup group : itineraryGroups) {
|
||||
if (group.getType() == ItineraryGroup.ANY_TYPE) {
|
||||
for (MapMarkersGroup group : mapMarkersGroups) {
|
||||
if (group.getType() == ItineraryType.MARKERS) {
|
||||
for (MapMarker marker : group.getMarkers()) {
|
||||
if (history && marker.history || !history && !marker.history) {
|
||||
mapMarkers.add(marker);
|
||||
|
@ -123,27 +452,26 @@ public class ItineraryHelper {
|
|||
return mapMarkers;
|
||||
}
|
||||
|
||||
private void loadGroups() {
|
||||
Map<String, ItineraryGroup> groupsMap = markersDbHelper.getAllGroupsMap();
|
||||
private void loadMarkersGroups() {
|
||||
Map<String, MapMarkersGroup> groupsMap = markersDbHelper.getAllGroupsMap();
|
||||
List<MapMarker> allMarkers = new ArrayList<>(markersHelper.getMapMarkers());
|
||||
allMarkers.addAll(markersHelper.getMapMarkersHistory());
|
||||
|
||||
Iterator<Entry<String, ItineraryGroup>> iterator = groupsMap.entrySet().iterator();
|
||||
Iterator<Entry<String, MapMarkersGroup>> iterator = groupsMap.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
ItineraryGroup group = iterator.next().getValue();
|
||||
if (group.getType() == ItineraryGroup.GPX_TYPE && !new File(group.getId()).exists()) {
|
||||
MapMarkersGroup group = iterator.next().getValue();
|
||||
if (group.getType() == ItineraryType.TRACK && !new File(group.getId()).exists()) {
|
||||
markersDbHelper.removeMarkersGroup(group.getId());
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
ItineraryGroup noGroup = null;
|
||||
|
||||
MapMarkersGroup noGroup = null;
|
||||
for (MapMarker marker : allMarkers) {
|
||||
ItineraryGroup group = groupsMap.get(marker.groupKey);
|
||||
MapMarkersGroup group = groupsMap.get(marker.groupKey);
|
||||
if (group == null) {
|
||||
if (noGroup == null) {
|
||||
noGroup = new ItineraryGroup();
|
||||
noGroup = new MapMarkersGroup();
|
||||
noGroup.setCreationDate(Long.MAX_VALUE);
|
||||
}
|
||||
noGroup.getMarkers().add(marker);
|
||||
|
@ -155,7 +483,7 @@ public class ItineraryHelper {
|
|||
}
|
||||
}
|
||||
|
||||
itineraryGroups = new ArrayList<>(groupsMap.values());
|
||||
mapMarkersGroups = new ArrayList<>(groupsMap.values());
|
||||
if (noGroup != null) {
|
||||
markersHelper.sortMarkers(noGroup.getMarkers(), false, BY_DATE_ADDED_DESC);
|
||||
addToGroupsList(noGroup);
|
||||
|
@ -163,35 +491,35 @@ public class ItineraryHelper {
|
|||
|
||||
sortGroups();
|
||||
|
||||
for (ItineraryGroup group : itineraryGroups) {
|
||||
markersHelper.updateGroup(group);
|
||||
for (MapMarkersGroup group : mapMarkersGroups) {
|
||||
updateGroup(group);
|
||||
}
|
||||
}
|
||||
|
||||
public void addGroupInternally(ItineraryGroup gr) {
|
||||
markersDbHelper.addGroup(gr);
|
||||
markersHelper.addHistoryMarkersToGroup(gr);
|
||||
addToGroupsList(gr);
|
||||
public void addGroupInternally(MapMarkersGroup group) {
|
||||
markersDbHelper.addGroup(group);
|
||||
markersHelper.addHistoryMarkersToGroup(group);
|
||||
addToGroupsList(group);
|
||||
}
|
||||
|
||||
public void updateGpxShowAsMarkers(File file) {
|
||||
GPXDatabase.GpxDataItem dataItem = app.getGpxDbHelper().getItem(file);
|
||||
GpxDataItem dataItem = app.getGpxDbHelper().getItem(file);
|
||||
if (dataItem != null) {
|
||||
app.getGpxDbHelper().updateShowAsMarkers(dataItem, true);
|
||||
dataItem.setShowAsMarkers(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void addToGroupsList(ItineraryGroup group) {
|
||||
List<ItineraryGroup> copyList = new ArrayList<>(itineraryGroups);
|
||||
public void addToGroupsList(MapMarkersGroup group) {
|
||||
List<MapMarkersGroup> copyList = new ArrayList<>(mapMarkersGroups);
|
||||
copyList.add(group);
|
||||
itineraryGroups = copyList;
|
||||
mapMarkersGroups = copyList;
|
||||
}
|
||||
|
||||
public void removeFromGroupsList(ItineraryGroup group) {
|
||||
List<ItineraryGroup> copyList = new ArrayList<>(itineraryGroups);
|
||||
public void removeFromGroupsList(MapMarkersGroup group) {
|
||||
List<MapMarkersGroup> copyList = new ArrayList<>(mapMarkersGroups);
|
||||
copyList.remove(group);
|
||||
itineraryGroups = copyList;
|
||||
mapMarkersGroups = copyList;
|
||||
}
|
||||
|
||||
public void addSyncListener(OnGroupSyncedListener listener) {
|
||||
|
@ -202,7 +530,7 @@ public class ItineraryHelper {
|
|||
syncListeners.remove(listener);
|
||||
}
|
||||
|
||||
public void runSynchronization(final @NonNull ItineraryGroup group) {
|
||||
public void runSynchronizationAsync(final @NonNull MapMarkersGroup group) {
|
||||
app.runInUIThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -211,20 +539,86 @@ public class ItineraryHelper {
|
|||
});
|
||||
}
|
||||
|
||||
public ItineraryGroup getMarkersGroup(GPXFile gpx) {
|
||||
public void runSynchronizationAsync(@NonNull FavoriteGroup favoriteGroup) {
|
||||
MapMarkersGroup group = getMarkersGroup(favoriteGroup);
|
||||
if (group != null) {
|
||||
runSynchronizationAsync(group);
|
||||
}
|
||||
}
|
||||
|
||||
public void runSynchronizationAsync(@NonNull GPXFile gpxFile) {
|
||||
MapMarkersGroup group = getMarkersGroup(gpxFile);
|
||||
if (group != null) {
|
||||
runSynchronizationAsync(group);
|
||||
}
|
||||
}
|
||||
|
||||
public void addMarkerToGroup(MapMarker marker) {
|
||||
MapMarkersGroup mapMarkersGroup = app.getItineraryHelper().getMapMarkerGroupById(marker.groupKey, marker.getType());
|
||||
if (mapMarkersGroup != null) {
|
||||
mapMarkersGroup.getMarkers().add(marker);
|
||||
updateGroup(mapMarkersGroup);
|
||||
if (mapMarkersGroup.getName() == null) {
|
||||
markersHelper.sortMarkers(mapMarkersGroup.getMarkers(), false, BY_DATE_ADDED_DESC);
|
||||
}
|
||||
} else {
|
||||
mapMarkersGroup = new MapMarkersGroup(marker.groupKey, marker.groupName, ItineraryType.MARKERS);
|
||||
mapMarkersGroup.setCreationDate(Long.MAX_VALUE);
|
||||
mapMarkersGroup.getMarkers().add(marker);
|
||||
addToGroupsList(mapMarkersGroup);
|
||||
sortGroups();
|
||||
updateGroup(mapMarkersGroup);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateGroup(MapMarkersGroup mapMarkersGroup) {
|
||||
if (mapMarkersGroup.getId() == null || mapMarkersGroup.getName() == null) {
|
||||
return;
|
||||
}
|
||||
createHeadersInGroup(mapMarkersGroup);
|
||||
int historyMarkersCount = mapMarkersGroup.getHistoryMarkers().size();
|
||||
ShowHideHistoryButton showHideHistoryButton = mapMarkersGroup.getShowHideHistoryButton();
|
||||
if (showHideHistoryButton != null) {
|
||||
if (historyMarkersCount == 0) {
|
||||
mapMarkersGroup.setShowHideHistoryButton(null);
|
||||
}
|
||||
} else if (historyMarkersCount > 0) {
|
||||
showHideHistoryButton = new ShowHideHistoryButton();
|
||||
showHideHistoryButton.showHistory = false;
|
||||
mapMarkersGroup.setShowHideHistoryButton(showHideHistoryButton);
|
||||
}
|
||||
}
|
||||
|
||||
public void createHeadersInGroup(@NonNull MapMarkersGroup group) {
|
||||
ItineraryType type = group.getType();
|
||||
int headerIconId = 0;
|
||||
int subHeaderIconId = 0;
|
||||
if (type != ItineraryType.MARKERS) {
|
||||
headerIconId = type == ItineraryType.FAVOURITES
|
||||
? R.drawable.ic_action_favorite : R.drawable.ic_action_polygom_dark;
|
||||
subHeaderIconId = R.drawable.ic_action_filter;
|
||||
}
|
||||
GroupHeader header = new GroupHeader(headerIconId, group);
|
||||
CategoriesSubHeader categoriesSubHeader = new CategoriesSubHeader(subHeaderIconId, group);
|
||||
|
||||
group.setHeader(header);
|
||||
group.setCategoriesSubHeader(categoriesSubHeader);
|
||||
}
|
||||
|
||||
public MapMarkersGroup getMarkersGroup(GPXFile gpx) {
|
||||
if (gpx == null || gpx.path == null) {
|
||||
return null;
|
||||
}
|
||||
return getMapMarkerGroupById(getMarkerGroupId(new File(gpx.path)), ItineraryGroup.GPX_TYPE);
|
||||
return getMapMarkerGroupById(getMarkerGroupId(new File(gpx.path)), ItineraryType.TRACK);
|
||||
}
|
||||
|
||||
public ItineraryGroup getMarkersGroup(FavoriteGroup favGroup) {
|
||||
return getMapMarkerGroupById(getMarkerGroupId(favGroup), ItineraryGroup.FAVORITES_TYPE);
|
||||
public MapMarkersGroup getMarkersGroup(FavoriteGroup favGroup) {
|
||||
return getMapMarkerGroupById(getMarkerGroupId(favGroup), ItineraryType.FAVOURITES);
|
||||
}
|
||||
|
||||
public ItineraryGroup addOrEnableGpxGroup(@NonNull File file) {
|
||||
public MapMarkersGroup addOrEnableGpxGroup(@NonNull File file) {
|
||||
updateGpxShowAsMarkers(file);
|
||||
ItineraryGroup gr = getMapMarkerGroupById(getMarkerGroupId(file), ItineraryGroup.GPX_TYPE);
|
||||
MapMarkersGroup gr = getMapMarkerGroupById(getMarkerGroupId(file), ItineraryType.TRACK);
|
||||
if (gr == null) {
|
||||
gr = createGPXMarkerGroup(file);
|
||||
addGroupInternally(gr);
|
||||
|
@ -233,9 +627,9 @@ public class ItineraryHelper {
|
|||
return gr;
|
||||
}
|
||||
|
||||
public ItineraryGroup addOrEnableGroup(@NonNull GPXFile file) {
|
||||
public MapMarkersGroup addOrEnableGroup(@NonNull GPXFile file) {
|
||||
updateGpxShowAsMarkers(new File(file.path));
|
||||
ItineraryGroup gr = getMarkersGroup(file);
|
||||
MapMarkersGroup gr = getMarkersGroup(file);
|
||||
if (gr == null) {
|
||||
gr = createGPXMarkerGroup(new File(file.path));
|
||||
addGroupInternally(gr);
|
||||
|
@ -244,8 +638,8 @@ public class ItineraryHelper {
|
|||
return gr;
|
||||
}
|
||||
|
||||
public ItineraryGroup addOrEnableGroup(@NonNull FavoriteGroup group) {
|
||||
ItineraryGroup gr = getMarkersGroup(group);
|
||||
public MapMarkersGroup addOrEnableGroup(@NonNull FavoriteGroup group) {
|
||||
MapMarkersGroup gr = getMarkersGroup(group);
|
||||
if (gr == null) {
|
||||
gr = createFavMarkerGroup(group);
|
||||
addGroupInternally(gr);
|
||||
|
@ -254,14 +648,12 @@ public class ItineraryHelper {
|
|||
return gr;
|
||||
}
|
||||
|
||||
private ItineraryGroup createGPXMarkerGroup(File fl) {
|
||||
return new ItineraryGroup(getMarkerGroupId(fl),
|
||||
Algorithms.getFileNameWithoutExtension(fl.getName()),
|
||||
ItineraryGroup.GPX_TYPE);
|
||||
private MapMarkersGroup createGPXMarkerGroup(File fl) {
|
||||
return new MapMarkersGroup(getMarkerGroupId(fl), getFileNameWithoutExtension(fl), ItineraryType.TRACK);
|
||||
}
|
||||
|
||||
private ItineraryGroup createFavMarkerGroup(FavoriteGroup favGroup) {
|
||||
return new ItineraryGroup(favGroup.getName(), favGroup.getName(), ItineraryGroup.FAVORITES_TYPE);
|
||||
private MapMarkersGroup createFavMarkerGroup(FavoriteGroup favGroup) {
|
||||
return new MapMarkersGroup(favGroup.getName(), favGroup.getName(), ItineraryType.FAVOURITES);
|
||||
}
|
||||
|
||||
private String getMarkerGroupId(File gpx) {
|
||||
|
@ -272,22 +664,21 @@ public class ItineraryHelper {
|
|||
return group.getName();
|
||||
}
|
||||
|
||||
|
||||
public void removeMarkerFromGroup(MapMarker marker) {
|
||||
if (marker != null) {
|
||||
ItineraryGroup itineraryGroup = getMapMarkerGroupById(marker.groupKey, marker.getType());
|
||||
if (itineraryGroup != null) {
|
||||
itineraryGroup.getMarkers().remove(marker);
|
||||
markersHelper.updateGroup(itineraryGroup);
|
||||
MapMarkersGroup mapMarkersGroup = getMapMarkerGroupById(marker.groupKey, marker.getType());
|
||||
if (mapMarkersGroup != null) {
|
||||
mapMarkersGroup.getMarkers().remove(marker);
|
||||
updateGroup(mapMarkersGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void sortGroups() {
|
||||
if (itineraryGroups.size() > 0) {
|
||||
Collections.sort(itineraryGroups, new Comparator<ItineraryGroup>() {
|
||||
if (mapMarkersGroups.size() > 0) {
|
||||
Collections.sort(mapMarkersGroups, new Comparator<MapMarkersGroup>() {
|
||||
@Override
|
||||
public int compare(ItineraryGroup group1, ItineraryGroup group2) {
|
||||
public int compare(MapMarkersGroup group1, MapMarkersGroup group2) {
|
||||
long t1 = group1.getCreationDate();
|
||||
long t2 = group2.getCreationDate();
|
||||
return (t1 > t2) ? -1 : ((t1 == t2) ? 0 : 1);
|
||||
|
@ -297,11 +688,36 @@ public class ItineraryHelper {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
public ItineraryGroup getMapMarkerGroupById(String id, int type) {
|
||||
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.MARKERS || type == group.type) {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MapMarkersGroup getMapMarkerGroupById(String id, ItineraryType type) {
|
||||
for (MapMarkersGroup group : mapMarkersGroups) {
|
||||
if ((id == null && group.getId() == null)
|
||||
|| (group.getId() != null && group.getId().equals(id))) {
|
||||
if (type == ItineraryGroup.ANY_TYPE || type == group.getType()) {
|
||||
if (type == ItineraryType.MARKERS || type == group.getType()) {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
@ -310,15 +726,15 @@ public class ItineraryHelper {
|
|||
}
|
||||
|
||||
@NonNull
|
||||
public List<ItineraryGroup> getGroupsForDisplayedGpx() {
|
||||
List<ItineraryGroup> res = new ArrayList<>();
|
||||
public List<MapMarkersGroup> getGroupsForDisplayedGpx() {
|
||||
List<MapMarkersGroup> res = new ArrayList<>();
|
||||
List<SelectedGpxFile> selectedGpxFiles = app.getSelectedGpxHelper().getSelectedGPXFiles();
|
||||
for (SelectedGpxFile selected : selectedGpxFiles) {
|
||||
ItineraryGroup search = getMarkersGroup(selected.getGpxFile());
|
||||
MapMarkersGroup search = getMarkersGroup(selected.getGpxFile());
|
||||
if (search == null && selected.getGpxFile() != null && selected.getGpxFile().path != null) {
|
||||
ItineraryGroup group = createGPXMarkerGroup(new File(selected.getGpxFile().path));
|
||||
MapMarkersGroup group = createGPXMarkerGroup(new File(selected.getGpxFile().path));
|
||||
group.setDisabled(true);
|
||||
markersHelper.createHeadersInGroup(group);
|
||||
createHeadersInGroup(group);
|
||||
res.add(group);
|
||||
}
|
||||
}
|
||||
|
@ -326,19 +742,19 @@ public class ItineraryHelper {
|
|||
}
|
||||
|
||||
@NonNull
|
||||
public List<ItineraryGroup> getGroupsForSavedArticlesTravelBook() {
|
||||
List<ItineraryGroup> res = new ArrayList<>();
|
||||
public List<MapMarkersGroup> getGroupsForSavedArticlesTravelBook() {
|
||||
List<MapMarkersGroup> res = new ArrayList<>();
|
||||
TravelHelper travelHelper = app.getTravelHelper();
|
||||
if (travelHelper.isAnyTravelBookPresent()) {
|
||||
List<TravelArticle> savedArticles = travelHelper.getBookmarksHelper().getSavedArticles();
|
||||
for (TravelArticle art : savedArticles) {
|
||||
String gpxName = travelHelper.getGPXName(art);
|
||||
File path = app.getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName);
|
||||
ItineraryGroup search = getMapMarkerGroupById(getMarkerGroupId(path), ItineraryGroup.GPX_TYPE);
|
||||
MapMarkersGroup search = getMapMarkerGroupById(getMarkerGroupId(path), ItineraryType.TRACK);
|
||||
if (search == null) {
|
||||
ItineraryGroup group = createGPXMarkerGroup(path);
|
||||
MapMarkersGroup group = createGPXMarkerGroup(path);
|
||||
group.setDisabled(true);
|
||||
markersHelper.createHeadersInGroup(group);
|
||||
createHeadersInGroup(group);
|
||||
res.add(group);
|
||||
}
|
||||
}
|
||||
|
@ -346,11 +762,67 @@ public class ItineraryHelper {
|
|||
return res;
|
||||
}
|
||||
|
||||
public void removeMarkersGroup(MapMarkersGroup group) {
|
||||
if (group != null) {
|
||||
markersDbHelper.removeMarkersGroup(group.getId());
|
||||
markersHelper.removeGroupActiveMarkers(group, false);
|
||||
removeFromGroupsList(group);
|
||||
}
|
||||
}
|
||||
|
||||
private void runGroupSynchronization(MapMarkersGroup group) {
|
||||
List<MapMarker> groupMarkers = new ArrayList<>(group.getMarkers());
|
||||
if (group.getType() == ItineraryType.FAVOURITES) {
|
||||
FavoriteGroup favGroup = app.getFavorites().getGroup(group.getName());
|
||||
if (favGroup == null) {
|
||||
return;
|
||||
}
|
||||
group.setVisible(favGroup.isVisible());
|
||||
if (!group.isVisible() || group.isDisabled()) {
|
||||
markersHelper.removeGroupActiveMarkers(group, true);
|
||||
return;
|
||||
}
|
||||
List<FavouritePoint> points = new ArrayList<>(favGroup.getPoints());
|
||||
for (FavouritePoint fp : points) {
|
||||
markersHelper.addNewMarkerIfNeeded(group, groupMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName(), fp, null);
|
||||
}
|
||||
} else if (group.getType() == ItineraryType.TRACK) {
|
||||
GpxSelectionHelper gpxHelper = app.getSelectedGpxHelper();
|
||||
File file = new File(group.getId());
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String gpxPath = group.getId();
|
||||
SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(gpxPath);
|
||||
GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile();
|
||||
group.setVisible(gpx != null || group.isVisibleUntilRestart());
|
||||
if (gpx == null || group.isDisabled()) {
|
||||
markersHelper.removeGroupActiveMarkers(group, true);
|
||||
return;
|
||||
}
|
||||
|
||||
List<WptPt> gpxPoints = new ArrayList<>(gpx.getPoints());
|
||||
for (WptPt pt : gpxPoints) {
|
||||
if (shouldAddWpt(pt, group.getWptCategories())) {
|
||||
markersHelper.addNewMarkerIfNeeded(group, groupMarkers, new LatLon(pt.lat, pt.lon), pt.name, null, pt);
|
||||
}
|
||||
}
|
||||
}
|
||||
markersHelper.removeOldMarkersIfPresent(groupMarkers);
|
||||
}
|
||||
|
||||
private boolean shouldAddWpt(WptPt wptPt, Set<String> wptCategories) {
|
||||
boolean addAll = wptCategories == null || wptCategories.isEmpty();
|
||||
return addAll || wptCategories.contains(wptPt.category)
|
||||
|| wptPt.category == null && wptCategories.contains("");
|
||||
}
|
||||
|
||||
private class SyncGroupTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private ItineraryGroup group;
|
||||
private MapMarkersGroup group;
|
||||
|
||||
SyncGroupTask(ItineraryGroup group) {
|
||||
SyncGroupTask(MapMarkersGroup group) {
|
||||
this.group = group;
|
||||
}
|
||||
|
||||
|
@ -370,55 +842,10 @@ public class ItineraryHelper {
|
|||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
runGroupSynchronization();
|
||||
runGroupSynchronization(group);
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO extract method from Asynctask to Helper directly
|
||||
private void runGroupSynchronization() {
|
||||
List<MapMarker> groupMarkers = new ArrayList<>(group.getMarkers());
|
||||
if (group.getType() == ItineraryGroup.FAVORITES_TYPE) {
|
||||
FavoriteGroup favGroup = app.getFavorites().getGroup(group.getName());
|
||||
if (favGroup == null) {
|
||||
return;
|
||||
}
|
||||
group.setVisible(favGroup.isVisible());
|
||||
if (!group.isVisible() || group.isDisabled()) {
|
||||
markersHelper.removeGroupActiveMarkers(group, true);
|
||||
return;
|
||||
}
|
||||
List<FavouritePoint> points = new ArrayList<>(favGroup.getPoints());
|
||||
for (FavouritePoint fp : points) {
|
||||
markersHelper.addNewMarkerIfNeeded(group, groupMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName(), fp, null);
|
||||
}
|
||||
} else if (group.getType() == ItineraryGroup.GPX_TYPE) {
|
||||
GpxSelectionHelper gpxHelper = app.getSelectedGpxHelper();
|
||||
File file = new File(group.getId());
|
||||
if (!file.exists()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String gpxPath = group.getId();
|
||||
SelectedGpxFile selectedGpxFile = gpxHelper.getSelectedFileByPath(gpxPath);
|
||||
GPXFile gpx = selectedGpxFile == null ? null : selectedGpxFile.getGpxFile();
|
||||
group.setVisible(gpx != null || group.isVisibleUntilRestart());
|
||||
if (gpx == null || group.isDisabled()) {
|
||||
markersHelper.removeGroupActiveMarkers(group, true);
|
||||
return;
|
||||
}
|
||||
|
||||
boolean addAll = group.getWptCategories() == null || group.getWptCategories().isEmpty();
|
||||
List<WptPt> gpxPoints = new ArrayList<>(gpx.getPoints());
|
||||
for (WptPt pt : gpxPoints) {
|
||||
if (addAll || group.getWptCategories().contains(pt.category)
|
||||
|| (pt.category == null && group.getWptCategories().contains(""))) {
|
||||
markersHelper.addNewMarkerIfNeeded(group, groupMarkers, new LatLon(pt.lat, pt.lon), pt.name, null, pt);
|
||||
}
|
||||
}
|
||||
}
|
||||
markersHelper.removeOldMarkersIfPresent(groupMarkers);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
if (!syncListeners.isEmpty()) {
|
||||
|
|
46
OsmAnd/src/net/osmand/plus/itinerary/ItineraryItem.java
Normal file
46
OsmAnd/src/net/osmand/plus/itinerary/ItineraryItem.java
Normal file
|
@ -0,0 +1,46 @@
|
|||
package net.osmand.plus.itinerary;
|
||||
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
|
||||
public class ItineraryItem {
|
||||
|
||||
public final String id;
|
||||
public final Object object;
|
||||
public final LatLon latLon;
|
||||
public final ItineraryType type;
|
||||
public final ItineraryGroup group;
|
||||
|
||||
public ItineraryItem(ItineraryGroup group, Object object, ItineraryType type) {
|
||||
this.type = type;
|
||||
this.group = group;
|
||||
this.object = object;
|
||||
this.id = acquireItemId(object);
|
||||
|
||||
if (object instanceof MapMarker) {
|
||||
MapMarker marker = (MapMarker) object;
|
||||
latLon = marker.point;
|
||||
} else if (object instanceof WptPt) {
|
||||
WptPt point = (WptPt) object;
|
||||
latLon = new LatLon(point.lat, point.lon);
|
||||
} else if (object instanceof FavouritePoint) {
|
||||
FavouritePoint point = (FavouritePoint) object;
|
||||
latLon = new LatLon(point.getLatitude(), point.getLongitude());
|
||||
} else {
|
||||
latLon = null;
|
||||
}
|
||||
}
|
||||
|
||||
private String acquireItemId(Object object) {
|
||||
if (object instanceof MapMarker) {
|
||||
return (((MapMarker) object)).id;
|
||||
} else if (object instanceof WptPt) {
|
||||
return (((WptPt) object)).name;
|
||||
} else if (object instanceof FavouritePoint) {
|
||||
return (((FavouritePoint) object)).getName();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
35
OsmAnd/src/net/osmand/plus/itinerary/ItineraryType.java
Normal file
35
OsmAnd/src/net/osmand/plus/itinerary/ItineraryType.java
Normal file
|
@ -0,0 +1,35 @@
|
|||
package net.osmand.plus.itinerary;
|
||||
|
||||
public enum ItineraryType {
|
||||
MARKERS(-1),
|
||||
FAVOURITES(0),
|
||||
TRACK(1);
|
||||
|
||||
private int typeId;
|
||||
|
||||
ItineraryType(int typeId) {
|
||||
this.typeId = typeId;
|
||||
}
|
||||
|
||||
public int getTypeId() {
|
||||
return typeId;
|
||||
}
|
||||
|
||||
public static ItineraryType findTypeForId(int typeId) {
|
||||
for (ItineraryType type : values()) {
|
||||
if (type.getTypeId() == typeId) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return ItineraryType.MARKERS;
|
||||
}
|
||||
|
||||
public static ItineraryType findTypeForName(String typeName) {
|
||||
for (ItineraryType type : values()) {
|
||||
if (type.name().equalsIgnoreCase(typeName)) {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
return ItineraryType.MARKERS;
|
||||
}
|
||||
}
|
|
@ -14,8 +14,6 @@ import net.osmand.data.LatLon;
|
|||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.TransportStop;
|
||||
import net.osmand.plus.FavouritesDbHelper;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -25,6 +23,8 @@ import net.osmand.plus.mapcontextmenu.MenuController;
|
|||
import net.osmand.plus.mapcontextmenu.builders.FavouritePointMenuBuilder;
|
||||
import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor;
|
||||
import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditorFragmentNew;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
||||
import net.osmand.plus.transport.TransportStopRoute;
|
||||
import net.osmand.plus.widgets.style.CustomTypefaceSpan;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
|
|
@ -4,21 +4,20 @@ import android.graphics.drawable.Drawable;
|
|||
import android.graphics.drawable.LayerDrawable;
|
||||
import android.graphics.drawable.ShapeDrawable;
|
||||
import android.graphics.drawable.shapes.OvalShape;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
import net.osmand.plus.settings.backend.OsmandPreference;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.helpers.MapMarkerDialogHelper;
|
||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||
import net.osmand.plus.mapcontextmenu.MenuController;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
||||
import net.osmand.plus.settings.backend.OsmandPreference;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
public class MapMarkerMenuController extends MenuController {
|
||||
|
@ -27,7 +26,6 @@ public class MapMarkerMenuController extends MenuController {
|
|||
|
||||
public MapMarkerMenuController(@NonNull MapActivity mapActivity, @NonNull PointDescription pointDescription, @NonNull MapMarker mapMarker) {
|
||||
super(new MenuBuilder(mapActivity), pointDescription, mapActivity);
|
||||
final boolean useStateList = Build.VERSION.SDK_INT >= 21;
|
||||
this.mapMarker = mapMarker;
|
||||
builder.setShowNearestWiki(true);
|
||||
|
||||
|
|
|
@ -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,14 +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.itinerary.ItineraryGroup;
|
||||
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
|
||||
|
@ -219,10 +216,7 @@ public class WptPtEditorFragment extends PointEditorFragment {
|
|||
private void syncGpx(GPXFile gpxFile) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app != null) {
|
||||
ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile);
|
||||
if (group != null) {
|
||||
app.getItineraryHelper().runSynchronization(group);
|
||||
}
|
||||
app.getItineraryHelper().runSynchronizationAsync(gpxFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -376,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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,6 @@ import net.osmand.plus.UiUtilities;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.SavingTrackHelper;
|
||||
import net.osmand.plus.base.PointImageDrawable;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||
import net.osmand.plus.mapcontextmenu.editors.WptPtEditor.OnDismissListener;
|
||||
import net.osmand.plus.track.SaveGpxAsyncTask;
|
||||
|
@ -237,10 +236,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew {
|
|||
private void syncGpx(GPXFile gpxFile) {
|
||||
OsmandApplication app = getMyApplication();
|
||||
if (app != null) {
|
||||
ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile);
|
||||
if (group != null) {
|
||||
app.getItineraryHelper().runSynchronization(group);
|
||||
}
|
||||
app.getItineraryHelper().runSynchronizationAsync(gpxFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -503,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() {
|
||||
|
|
|
@ -2,15 +2,13 @@ package net.osmand.plus.mapmarkers;
|
|||
|
||||
import androidx.annotation.DrawableRes;
|
||||
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
|
||||
public class CategoriesSubHeader {
|
||||
|
||||
@DrawableRes
|
||||
private int iconRes;
|
||||
private ItineraryGroup group;
|
||||
private MapMarkersGroup group;
|
||||
|
||||
public CategoriesSubHeader(int iconRes, ItineraryGroup group) {
|
||||
public CategoriesSubHeader(int iconRes, MapMarkersGroup group) {
|
||||
this.iconRes = iconRes;
|
||||
this.group = group;
|
||||
}
|
||||
|
@ -20,7 +18,7 @@ public class CategoriesSubHeader {
|
|||
return iconRes;
|
||||
}
|
||||
|
||||
public ItineraryGroup getGroup() {
|
||||
public MapMarkersGroup getGroup() {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,6 @@ import net.osmand.plus.Version;
|
|||
import net.osmand.plus.activities.SavingTrackHelper;
|
||||
import net.osmand.plus.activities.TrackActivity;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.itinerary.ItineraryHelper;
|
||||
import net.osmand.plus.mapmarkers.CoordinateInputBottomSheetDialogFragment.CoordinateInputFormatChangeListener;
|
||||
import net.osmand.plus.mapmarkers.CoordinateInputFormats.DDM;
|
||||
|
@ -171,10 +170,7 @@ public class CoordinateInputDialogFragment extends DialogFragment implements Osm
|
|||
|
||||
private void syncGpx(GPXFile gpxFile) {
|
||||
ItineraryHelper helper = getMyApplication().getItineraryHelper();
|
||||
ItineraryGroup group = helper.getMarkersGroup(gpxFile);
|
||||
if (group != null) {
|
||||
helper.runSynchronization(group);
|
||||
}
|
||||
helper.runSynchronizationAsync(gpxFile);
|
||||
}
|
||||
|
||||
protected void addWpt(GPXFile gpx, String description, String name, String category, int color, double lat, double lon) {
|
||||
|
|
|
@ -2,15 +2,13 @@ package net.osmand.plus.mapmarkers;
|
|||
|
||||
import androidx.annotation.DrawableRes;
|
||||
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
|
||||
public class GroupHeader {
|
||||
|
||||
@DrawableRes
|
||||
private int iconRes;
|
||||
private ItineraryGroup group;
|
||||
private MapMarkersGroup group;
|
||||
|
||||
public GroupHeader(int iconRes, ItineraryGroup group) {
|
||||
public GroupHeader(int iconRes, MapMarkersGroup group) {
|
||||
this.iconRes = iconRes;
|
||||
this.group = group;
|
||||
}
|
||||
|
@ -20,7 +18,7 @@ public class GroupHeader {
|
|||
return iconRes;
|
||||
}
|
||||
|
||||
public ItineraryGroup getGroup() {
|
||||
public MapMarkersGroup getGroup() {
|
||||
return group;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.mapmarkers;
|
|||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
|
@ -11,7 +12,7 @@ import net.osmand.data.LatLon;
|
|||
import net.osmand.data.LocationPoint;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.itinerary.ItineraryType;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER;
|
||||
|
@ -37,7 +38,7 @@ public class MapMarker implements LocationPoint {
|
|||
public FavouritePoint favouritePoint;
|
||||
public String mapObjectName;
|
||||
|
||||
public MapMarker(LatLon point, PointDescription name, int colorIndex, boolean selected, int index) {
|
||||
public MapMarker(@NonNull LatLon point, @NonNull PointDescription name, int colorIndex, boolean selected, int index) {
|
||||
this.point = point;
|
||||
this.pointDescription = name;
|
||||
this.colorIndex = colorIndex;
|
||||
|
@ -45,10 +46,10 @@ public class MapMarker implements LocationPoint {
|
|||
this.index = index;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
public ItineraryType getType() {
|
||||
return favouritePoint == null ?
|
||||
(wptPt == null ? ItineraryGroup.ANY_TYPE : ItineraryGroup.GPX_TYPE) :
|
||||
ItineraryGroup.FAVORITES_TYPE;
|
||||
(wptPt == null ? ItineraryType.MARKERS : ItineraryType.TRACK) :
|
||||
ItineraryType.FAVOURITES;
|
||||
}
|
||||
|
||||
public PointDescription getPointDescription(Context ctx) {
|
||||
|
@ -66,11 +67,12 @@ public class MapMarker implements LocationPoint {
|
|||
return name;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public PointDescription getOriginalPointDescription() {
|
||||
return pointDescription;
|
||||
}
|
||||
|
||||
public void setOriginalPointDescription(PointDescription pointDescription) {
|
||||
public void setOriginalPointDescription(@NonNull PointDescription pointDescription) {
|
||||
this.pointDescription = pointDescription;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
|
||||
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.itinerary.ItineraryType;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -162,27 +162,27 @@ public class MapMarkersDbHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void addGroup(ItineraryGroup group) {
|
||||
public void addGroup(MapMarkersGroup group) {
|
||||
SQLiteConnection db = openConnection(false);
|
||||
if (db != null) {
|
||||
try {
|
||||
db.execSQL("INSERT INTO " + GROUPS_TABLE_NAME + " VALUES (?, ?, ?, ?, ?)",
|
||||
new Object[]{group.getId(), group.getName(), group.getType(), group.isDisabled(), group.getWptCategoriesString()});
|
||||
new Object[]{group.getId(), group.getName(), group.getType().getTypeId(), group.isDisabled(), group.getWptCategoriesString()});
|
||||
} finally {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, ItineraryGroup> getAllGroupsMap() {
|
||||
Map<String, ItineraryGroup> res = new LinkedHashMap<>();
|
||||
public Map<String, MapMarkersGroup> getAllGroupsMap() {
|
||||
Map<String, MapMarkersGroup> res = new LinkedHashMap<>();
|
||||
SQLiteConnection db = openConnection(true);
|
||||
if (db != null) {
|
||||
try {
|
||||
SQLiteCursor query = db.rawQuery(GROUPS_TABLE_SELECT, null);
|
||||
if (query != null && query.moveToFirst()) {
|
||||
do {
|
||||
ItineraryGroup group = readGroup(query);
|
||||
MapMarkersGroup group = readGroup(query);
|
||||
res.put(group.getId(), group);
|
||||
} while (query.moveToNext());
|
||||
}
|
||||
|
@ -196,14 +196,14 @@ public class MapMarkersDbHelper {
|
|||
return res;
|
||||
}
|
||||
|
||||
private ItineraryGroup readGroup(SQLiteCursor query) {
|
||||
private MapMarkersGroup readGroup(SQLiteCursor query) {
|
||||
String id = query.getString(0);
|
||||
String name = query.getString(1);
|
||||
int type = query.getInt(2);
|
||||
boolean disabled = query.getInt(3) == 1;
|
||||
String categories = query.getString(4);
|
||||
|
||||
ItineraryGroup res = new ItineraryGroup(id, name, type);
|
||||
MapMarkersGroup res = new MapMarkersGroup(id, name, ItineraryType.findTypeForId(type));
|
||||
res.setDisabled(disabled);
|
||||
res.setWptCategories(categories == null ? null : Algorithms.decodeStringSet(categories));
|
||||
|
||||
|
|
181
OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroup.java
Normal file
181
OsmAnd/src/net/osmand/plus/mapmarkers/MapMarkersGroup.java
Normal file
|
@ -0,0 +1,181 @@
|
|||
package net.osmand.plus.mapmarkers;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import net.osmand.plus.itinerary.ItineraryType;
|
||||
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class MapMarkersGroup {
|
||||
|
||||
public static final String MARKERS_SYNC_GROUP_ID = "markers_sync_group_id";
|
||||
|
||||
private String id;
|
||||
private String name;
|
||||
private ItineraryType type = ItineraryType.MARKERS;
|
||||
private Set<String> wptCategories;
|
||||
private boolean disabled;
|
||||
|
||||
private long creationDate;
|
||||
private boolean visible = true;
|
||||
private boolean wasShown = false;
|
||||
private boolean visibleUntilRestart;
|
||||
private List<MapMarker> markers = new ArrayList<>();
|
||||
private TravelArticle wikivoyageArticle;
|
||||
// TODO should be removed from this class:
|
||||
private GroupHeader header;
|
||||
private CategoriesSubHeader categoriesSubHeader;
|
||||
private ShowHideHistoryButton showHideHistoryButton;
|
||||
|
||||
public MapMarkersGroup() {
|
||||
|
||||
}
|
||||
|
||||
public MapMarkersGroup(@NonNull String id, @NonNull String name, @NonNull ItineraryType type) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getGpxPath() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public TravelArticle getWikivoyageArticle() {
|
||||
return wikivoyageArticle;
|
||||
}
|
||||
|
||||
public long getCreationDate() {
|
||||
return creationDate;
|
||||
}
|
||||
|
||||
public void setCreationDate(long creationDate) {
|
||||
this.creationDate = creationDate;
|
||||
}
|
||||
|
||||
public void setVisible(boolean visible) {
|
||||
this.visible = visible;
|
||||
}
|
||||
|
||||
public void setMarkers(List<MapMarker> markers) {
|
||||
this.markers = markers;
|
||||
}
|
||||
|
||||
public void setHeader(GroupHeader header) {
|
||||
this.header = header;
|
||||
}
|
||||
|
||||
public void setCategoriesSubHeader(CategoriesSubHeader categoriesSubHeader) {
|
||||
this.categoriesSubHeader = categoriesSubHeader;
|
||||
}
|
||||
|
||||
public void setShowHideHistoryButton(ShowHideHistoryButton showHideHistoryButton) {
|
||||
this.showHideHistoryButton = showHideHistoryButton;
|
||||
}
|
||||
|
||||
public boolean isWasShown() {
|
||||
return wasShown;
|
||||
}
|
||||
|
||||
public boolean isVisibleUntilRestart() {
|
||||
return visibleUntilRestart;
|
||||
}
|
||||
|
||||
public void setWikivoyageArticle(TravelArticle wikivoyageArticle) {
|
||||
this.wikivoyageArticle = wikivoyageArticle;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public ItineraryType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setWptCategories(Set<String> wptCategories) {
|
||||
this.wptCategories = wptCategories;
|
||||
}
|
||||
|
||||
public Set<String> getWptCategories() {
|
||||
return wptCategories;
|
||||
}
|
||||
|
||||
public boolean isDisabled() {
|
||||
return disabled;
|
||||
}
|
||||
|
||||
public void setDisabled(boolean disabled) {
|
||||
this.disabled = disabled;
|
||||
}
|
||||
|
||||
public boolean isVisible() {
|
||||
return visible;
|
||||
}
|
||||
|
||||
public boolean wasShown() {
|
||||
return wasShown;
|
||||
}
|
||||
|
||||
public void setWasShown(boolean wasShown) {
|
||||
this.wasShown = wasShown;
|
||||
}
|
||||
|
||||
public void setVisibleUntilRestart(boolean visibleUntilRestart) {
|
||||
this.visibleUntilRestart = visibleUntilRestart;
|
||||
}
|
||||
|
||||
public List<MapMarker> getMarkers() {
|
||||
return markers;
|
||||
}
|
||||
|
||||
public GroupHeader getGroupHeader() {
|
||||
return header;
|
||||
}
|
||||
|
||||
public CategoriesSubHeader getCategoriesSubHeader() {
|
||||
return categoriesSubHeader;
|
||||
}
|
||||
|
||||
public ShowHideHistoryButton getShowHideHistoryButton() {
|
||||
return showHideHistoryButton;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getWptCategoriesString() {
|
||||
if (wptCategories != null) {
|
||||
return Algorithms.encodeStringSet(wptCategories);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<MapMarker> getActiveMarkers() {
|
||||
List<MapMarker> markers = new ArrayList<>(this.markers);
|
||||
List<MapMarker> activeMarkers = new ArrayList<>(markers.size());
|
||||
for (MapMarker marker : markers) {
|
||||
if (!marker.history) {
|
||||
activeMarkers.add(marker);
|
||||
}
|
||||
}
|
||||
return activeMarkers;
|
||||
}
|
||||
|
||||
public List<MapMarker> getHistoryMarkers() {
|
||||
List<MapMarker> historyMarkers = new ArrayList<>();
|
||||
for (MapMarker marker : markers) {
|
||||
if (marker.history) {
|
||||
historyMarkers.add(marker);
|
||||
}
|
||||
}
|
||||
return historyMarkers;
|
||||
}
|
||||
}
|
|
@ -17,9 +17,7 @@ import net.osmand.data.PointDescription;
|
|||
import net.osmand.plus.GeocodingLookupService;
|
||||
import net.osmand.plus.GeocodingLookupService.AddressLookupRequest;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
|
@ -117,7 +115,6 @@ public class MapMarkersHelper {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public void lookupAddressAll() {
|
||||
for (MapMarker mapMarker : mapMarkers) {
|
||||
lookupAddress(mapMarker);
|
||||
|
@ -230,7 +227,7 @@ public class MapMarkersHelper {
|
|||
});
|
||||
}
|
||||
|
||||
public void addHistoryMarkersToGroup(@NonNull ItineraryGroup group) {
|
||||
public void addHistoryMarkersToGroup(@NonNull MapMarkersGroup group) {
|
||||
List<MapMarker> historyMarkers = new ArrayList<>(mapMarkersHistory);
|
||||
for (MapMarker m : historyMarkers) {
|
||||
if (m.groupKey != null && group.getId() != null && m.groupKey.equals(group.getId())) {
|
||||
|
@ -239,87 +236,29 @@ public class MapMarkersHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public void removeMarkersGroup(ItineraryGroup group) {
|
||||
if (group != null) {
|
||||
markersDbHelper.removeMarkersGroup(group.getId());
|
||||
removeGroupActiveMarkers(group, false);
|
||||
app.getItineraryHelper().removeFromGroupsList(group);
|
||||
}
|
||||
private void syncMarkerWithItinerary(@NonNull MapMarker marker) {
|
||||
app.getItineraryHelper().addMarkerToGroup(marker);
|
||||
}
|
||||
|
||||
public void removeGroupActiveMarkers(ItineraryGroup group, boolean updateGroup) {
|
||||
public void removeGroupActiveMarkers(MapMarkersGroup group, boolean updateGroup) {
|
||||
if (group != null) {
|
||||
markersDbHelper.removeActiveMarkersFromGroup(group.getId());
|
||||
removeFromMapMarkersList(group.getActiveMarkers());
|
||||
if (updateGroup) {
|
||||
group.setMarkers(group.getHistoryMarkers());
|
||||
updateGroup(group);
|
||||
app.getItineraryHelper().updateGroup(group);
|
||||
}
|
||||
reorderActiveMarkersIfNeeded();
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateGroup(ItineraryGroup itineraryGroup) {
|
||||
if (itineraryGroup.getId() == null || itineraryGroup.getName() == null) {
|
||||
return;
|
||||
}
|
||||
createHeadersInGroup(itineraryGroup);
|
||||
int historyMarkersCount = itineraryGroup.getHistoryMarkers().size();
|
||||
ShowHideHistoryButton showHideHistoryButton = itineraryGroup.getShowHideHistoryButton();
|
||||
if (showHideHistoryButton != null) {
|
||||
if (historyMarkersCount == 0) {
|
||||
itineraryGroup.setShowHideHistoryButton(null);
|
||||
}
|
||||
} else if (historyMarkersCount > 0) {
|
||||
showHideHistoryButton = new ShowHideHistoryButton();
|
||||
showHideHistoryButton.showHistory = false;
|
||||
itineraryGroup.setShowHideHistoryButton(showHideHistoryButton);
|
||||
}
|
||||
}
|
||||
|
||||
private void addMarkersToGroups(@NonNull List<MapMarker> markers) {
|
||||
for (MapMarker marker : markers) {
|
||||
addMarkerToGroup(marker);
|
||||
syncMarkerWithItinerary(marker);
|
||||
}
|
||||
}
|
||||
|
||||
private void addMarkerToGroup(MapMarker marker) {
|
||||
if (marker != null) {
|
||||
ItineraryGroup itineraryGroup = app.getItineraryHelper().getMapMarkerGroupById(marker.groupKey, marker.getType());
|
||||
if (itineraryGroup != null) {
|
||||
itineraryGroup.getMarkers().add(marker);
|
||||
updateGroup(itineraryGroup);
|
||||
if (itineraryGroup.getName() == null) {
|
||||
sortMarkers(itineraryGroup.getMarkers(), false, BY_DATE_ADDED_DESC);
|
||||
}
|
||||
} else {
|
||||
itineraryGroup = new ItineraryGroup(marker.groupKey, marker.groupName, ItineraryGroup.ANY_TYPE);
|
||||
itineraryGroup.setCreationDate(Long.MAX_VALUE);
|
||||
itineraryGroup.getMarkers().add(marker);
|
||||
app.getItineraryHelper().addToGroupsList(itineraryGroup);
|
||||
app.getItineraryHelper().sortGroups();
|
||||
updateGroup(itineraryGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void createHeadersInGroup(@NonNull ItineraryGroup group) {
|
||||
int type = group.getType();
|
||||
int headerIconId = 0;
|
||||
int subHeaderIconId = 0;
|
||||
if (type != -1) {
|
||||
headerIconId = type == ItineraryGroup.FAVORITES_TYPE
|
||||
? R.drawable.ic_action_favorite : R.drawable.ic_action_polygom_dark;
|
||||
subHeaderIconId = R.drawable.ic_action_filter;
|
||||
}
|
||||
GroupHeader header = new GroupHeader(headerIconId, group);
|
||||
CategoriesSubHeader categoriesSubHeader = new CategoriesSubHeader(subHeaderIconId, group);
|
||||
|
||||
group.setHeader(header);
|
||||
group.setCategoriesSubHeader(categoriesSubHeader);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MapMarker getMapMarker(WptPt wptPt) {
|
||||
for (MapMarker marker : getMarkers()) {
|
||||
|
@ -350,6 +289,16 @@ public class MapMarkersHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MapMarker getMapMarker(@NonNull String id) {
|
||||
for (MapMarker marker : getMarkers()) {
|
||||
if (Algorithms.stringsEqual(marker.id, id)) {
|
||||
return marker;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<MapMarker> getMarkers() {
|
||||
List<MapMarker> res = new ArrayList<>(mapMarkers);
|
||||
if (app.getSettings().KEEP_PASSED_MARKERS_ON_MAP.get()) {
|
||||
|
@ -371,7 +320,7 @@ public class MapMarkersHelper {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void addNewMarkerIfNeeded(@NonNull ItineraryGroup group,
|
||||
public void addNewMarkerIfNeeded(@NonNull MapMarkersGroup group,
|
||||
@NonNull List<MapMarker> groupMarkers,
|
||||
@NonNull LatLon latLon,
|
||||
@NonNull String name,
|
||||
|
@ -446,7 +395,7 @@ public class MapMarkersHelper {
|
|||
addToMapMarkersList(marker);
|
||||
reorderActiveMarkersIfNeeded();
|
||||
}
|
||||
addMarkerToGroup(marker);
|
||||
syncMarkerWithItinerary(marker);
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
@ -608,13 +557,13 @@ public class MapMarkersHelper {
|
|||
|
||||
public void addMapMarkers(@NonNull List<LatLon> points,
|
||||
@NonNull List<PointDescription> historyNames,
|
||||
@Nullable ItineraryGroup group) {
|
||||
@Nullable MapMarkersGroup group) {
|
||||
addMarkers(points, historyNames, group, null, null, null);
|
||||
}
|
||||
|
||||
private void addMarkers(@NonNull List<LatLon> points,
|
||||
@NonNull List<PointDescription> historyNames,
|
||||
@Nullable ItineraryGroup group,
|
||||
@Nullable MapMarkersGroup group,
|
||||
@Nullable List<FavouritePoint> favouritePoints,
|
||||
@Nullable List<WptPt> wptPts,
|
||||
@Nullable List<String> mapObjNames) {
|
||||
|
|
|
@ -20,7 +20,6 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
|
|||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.ShortDescriptionItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.itinerary.ItineraryHelper;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -144,12 +143,12 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee
|
|||
if (selectedGpxFile == null) {
|
||||
gpxSelectionHelper.selectGpxFile(gpxFile, true, false, false, false, false);
|
||||
}
|
||||
ItineraryGroup group = helper.getMarkersGroup(gpxFile);
|
||||
MapMarkersGroup group = helper.getMarkersGroup(gpxFile);
|
||||
if (group == null) {
|
||||
group = helper.addOrEnableGroup(gpxFile);
|
||||
}
|
||||
helper.updateGroupWptCategories(group, selectedCategories);
|
||||
helper.runSynchronization(group);
|
||||
helper.runSynchronizationAsync(group);
|
||||
}
|
||||
|
||||
private boolean isAllChecked() {
|
||||
|
|
|
@ -13,13 +13,14 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.UiUtilities.UpdateLocationViewCache;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||
import net.osmand.plus.itinerary.ItineraryType;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.Collections;
|
||||
|
@ -214,10 +215,10 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
|
|||
final int pos = holder.getAdapterPosition();
|
||||
final MapMarker marker = getItem(pos);
|
||||
mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker);
|
||||
ItineraryGroup group = mapActivity.getMyApplication().getItineraryHelper().getMapMarkerGroupById(marker.groupKey,
|
||||
ItineraryGroup.ANY_TYPE);
|
||||
MapMarkersGroup group = mapActivity.getMyApplication().getItineraryHelper().getMapMarkerGroupById(marker.groupKey,
|
||||
ItineraryType.MARKERS);
|
||||
if (group != null) {
|
||||
mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group);
|
||||
mapActivity.getMyApplication().getItineraryHelper().updateGroup(group);
|
||||
}
|
||||
changeMarkers();
|
||||
notifyDataSetChanged();
|
||||
|
|
|
@ -21,20 +21,21 @@ import net.osmand.IndexConstants;
|
|||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.itinerary.ItineraryHelper;
|
||||
import net.osmand.plus.mapmarkers.CategoriesSubHeader;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
||||
import net.osmand.plus.mapmarkers.GroupHeader;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.mapmarkers.ShowHideHistoryButton;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.UiUtilities.UpdateLocationViewCache;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||
import net.osmand.plus.itinerary.ItineraryType;
|
||||
import net.osmand.plus.itinerary.ItineraryHelper;
|
||||
import net.osmand.plus.mapmarkers.CategoriesSubHeader;
|
||||
import net.osmand.plus.mapmarkers.GroupHeader;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
||||
import net.osmand.plus.mapmarkers.SelectWptCategoriesBottomSheetDialogFragment;
|
||||
import net.osmand.plus.mapmarkers.ShowHideHistoryButton;
|
||||
import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
|
||||
import net.osmand.plus.wikivoyage.data.TravelArticle;
|
||||
import net.osmand.plus.wikivoyage.data.TravelHelper;
|
||||
|
@ -106,11 +107,11 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
items = new ArrayList<>();
|
||||
ItineraryHelper helper = app.getItineraryHelper();
|
||||
helper.updateGroups();
|
||||
List<ItineraryGroup> groups = new ArrayList<>(helper.getItineraryGroups());
|
||||
List<MapMarkersGroup> groups = new ArrayList<>(helper.getMapMarkersGroups());
|
||||
groups.addAll(helper.getGroupsForDisplayedGpx());
|
||||
groups.addAll(helper.getGroupsForSavedArticlesTravelBook());
|
||||
for (int i = 0; i < groups.size(); i++) {
|
||||
ItineraryGroup group = groups.get(i);
|
||||
MapMarkersGroup group = groups.get(i);
|
||||
if (!group.isVisible()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -196,7 +197,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
return null;
|
||||
}
|
||||
|
||||
private void populateAdapterWithGroupMarkers(ItineraryGroup group, int position) {
|
||||
private void populateAdapterWithGroupMarkers(MapMarkersGroup group, int position) {
|
||||
if (position != RecyclerView.NO_POSITION) {
|
||||
ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton();
|
||||
if (!group.isDisabled()) {
|
||||
|
@ -221,7 +222,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
|
||||
public int getGroupHeaderPosition(String groupId) {
|
||||
int pos = -1;
|
||||
ItineraryGroup group = app.getItineraryHelper().getMapMarkerGroupById(groupId, ItineraryGroup.ANY_TYPE);
|
||||
MapMarkersGroup group = app.getItineraryHelper().getMapMarkerGroupById(groupId, ItineraryType.MARKERS);
|
||||
if (group != null) {
|
||||
pos = items.indexOf(group.getGroupHeader());
|
||||
}
|
||||
|
@ -402,11 +403,11 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
headerViewHolder.articleDescription.setVisibility(View.GONE);
|
||||
} else if (header instanceof GroupHeader) {
|
||||
final GroupHeader groupHeader = (GroupHeader) header;
|
||||
final ItineraryGroup group = groupHeader.getGroup();
|
||||
final MapMarkersGroup group = groupHeader.getGroup();
|
||||
String groupName = group.getName();
|
||||
if (groupName.isEmpty()) {
|
||||
groupName = app.getString(R.string.shared_string_favorites);
|
||||
} else if (group.getType() == ItineraryGroup.GPX_TYPE) {
|
||||
} else if (group.getType() == ItineraryType.TRACK) {
|
||||
groupName = groupName.replace(IndexConstants.GPX_FILE_EXT, "").replace("/", " ").replace("_", " ");
|
||||
}
|
||||
if (group.isDisabled()) {
|
||||
|
@ -464,7 +465,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
fragment.show(mapActivity.getSupportFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG);
|
||||
}
|
||||
app.getItineraryHelper().updateGroupDisabled(group, disabled);
|
||||
if (group.getType() == ItineraryGroup.GPX_TYPE) {
|
||||
if (group.getType() == ItineraryType.TRACK) {
|
||||
group.setVisibleUntilRestart(disabled);
|
||||
String gpxPath = group.getGpxPath();
|
||||
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxPath);
|
||||
|
@ -479,7 +480,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
if(!disabled) {
|
||||
app.getItineraryHelper().enableGroup(group);
|
||||
} else {
|
||||
app.getItineraryHelper().runSynchronization(group);
|
||||
app.getItineraryHelper().runSynchronizationAsync(group);
|
||||
}
|
||||
|
||||
if (disabled) {
|
||||
|
@ -487,7 +488,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
.setAction(R.string.shared_string_undo, new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (group.getType() == ItineraryGroup.GPX_TYPE && gpxFile[0] != null) {
|
||||
if (group.getType() == ItineraryType.TRACK && gpxFile[0] != null) {
|
||||
switchGpxVisibility(gpxFile[0], null, true);
|
||||
}
|
||||
app.getItineraryHelper().enableGroup(group);
|
||||
|
@ -530,7 +531,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
final Object header = getItem(position);
|
||||
if (header instanceof CategoriesSubHeader) {
|
||||
final CategoriesSubHeader categoriesSubHeader = (CategoriesSubHeader) header;
|
||||
final ItineraryGroup group = categoriesSubHeader.getGroup();
|
||||
final MapMarkersGroup group = categoriesSubHeader.getGroup();
|
||||
View.OnClickListener openChooseCategoriesDialog = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
@ -573,7 +574,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
|
|||
}
|
||||
}
|
||||
|
||||
private String getGroupWptCategoriesString(ItineraryGroup group) {
|
||||
private String getGroupWptCategoriesString(MapMarkersGroup group) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
Set<String> categories = group.getWptCategories();
|
||||
if (categories != null && !categories.isEmpty()) {
|
||||
|
|
|
@ -8,7 +8,6 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
|
|||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.activities.SavingTrackHelper;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
@ -58,18 +57,11 @@ public class DeletePointsTask extends AsyncTask<Void, Void, Void> {
|
|||
app.getSelectedGpxHelper().setGpxFileToDisplay(gpx);
|
||||
}
|
||||
}
|
||||
syncGpx(gpx);
|
||||
app.getItineraryHelper().runSynchronizationAsync(gpx);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void syncGpx(GPXFile gpxFile) {
|
||||
ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile);
|
||||
if (group != null) {
|
||||
app.getItineraryHelper().runSynchronization(group);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
OnPointsDeleteListener listener = listenerRef.get();
|
||||
|
|
|
@ -49,7 +49,7 @@ import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
|||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.FontCache;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
||||
import net.osmand.plus.measurementtool.OptionsDividerItem;
|
||||
import net.osmand.plus.myplaces.DeletePointsTask.OnPointsDeleteListener;
|
||||
|
@ -192,7 +192,7 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
|
|||
}
|
||||
|
||||
private BaseBottomSheetItem createCopyToMarkersItem(final GPXFile gpxFile) {
|
||||
ItineraryGroup markersGroup = app.getItineraryHelper().getMarkersGroup(gpxFile);
|
||||
MapMarkersGroup markersGroup = app.getItineraryHelper().getMarkersGroup(gpxFile);
|
||||
final boolean synced = markersGroup != null && (Algorithms.isEmpty(markersGroup.getWptCategories())
|
||||
|| markersGroup.getWptCategories().contains(group.getName()));
|
||||
|
||||
|
@ -216,7 +216,7 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
|
|||
selectedGpxHelper.selectGpxFile(gpxFile, true, false, false, false, false);
|
||||
}
|
||||
boolean groupCreated = false;
|
||||
ItineraryGroup markersGroup = app.getItineraryHelper().getMarkersGroup(gpxFile);
|
||||
MapMarkersGroup markersGroup = app.getItineraryHelper().getMarkersGroup(gpxFile);
|
||||
if (markersGroup == null) {
|
||||
groupCreated = true;
|
||||
markersGroup = app.getItineraryHelper().addOrEnableGroup(gpxFile);
|
||||
|
@ -232,11 +232,11 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
|
|||
selectedCategories.add(group.getName());
|
||||
}
|
||||
if (Algorithms.isEmpty(selectedCategories)) {
|
||||
mapMarkersHelper.removeMarkersGroup(markersGroup);
|
||||
app.getItineraryHelper().removeMarkersGroup(markersGroup);
|
||||
} else {
|
||||
app.getItineraryHelper().updateGroupWptCategories(markersGroup, selectedCategories);
|
||||
if (!groupCreated) {
|
||||
app.getItineraryHelper().runSynchronization(markersGroup);
|
||||
app.getItineraryHelper().runSynchronizationAsync(markersGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -504,7 +504,7 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
|
|||
protected void onPostExecute(Void aVoid) {
|
||||
GPXFile gpxFile = group.getGpx();
|
||||
if (gpxFile != null && wasUpdated) {
|
||||
syncGpx(gpxFile);
|
||||
app.getItineraryHelper().runSynchronizationAsync(gpxFile);
|
||||
}
|
||||
|
||||
if (progressDialog != null && progressDialog.isShowing()) {
|
||||
|
@ -522,12 +522,5 @@ public class EditTrackGroupDialogFragment extends MenuBottomSheetDialogFragment
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void syncGpx(GPXFile gpxFile) {
|
||||
ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile);
|
||||
if (group != null) {
|
||||
app.getItineraryHelper().runSynchronization(group);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ import net.osmand.plus.base.OsmandExpandableListFragment;
|
|||
import net.osmand.plus.base.PointImageDrawable;
|
||||
import net.osmand.plus.helpers.GpxUiHelper;
|
||||
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
||||
import net.osmand.plus.myplaces.DeletePointsTask.OnPointsDeleteListener;
|
||||
import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener;
|
||||
|
@ -500,12 +500,12 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
|
|||
return;
|
||||
}
|
||||
final GPXFile gpxFile = getGpx();
|
||||
ItineraryGroup markersSearch = app.getItineraryHelper().getMarkersGroup(gpxFile);
|
||||
final ItineraryGroup markersGr;
|
||||
MapMarkersGroup markersSearch = app.getItineraryHelper().getMarkersGroup(gpxFile);
|
||||
final MapMarkersGroup markersGr;
|
||||
final boolean markersRemoved;
|
||||
if (markersSearch != null) {
|
||||
markersGr = markersSearch;
|
||||
markersHelper.removeMarkersGroup(markersGr);
|
||||
app.getItineraryHelper().removeMarkersGroup(markersGr);
|
||||
markersRemoved = true;
|
||||
} else if (gpxFile != null) {
|
||||
markersGr = app.getItineraryHelper().addOrEnableGroup(gpxFile);
|
||||
|
@ -537,9 +537,9 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
|
|||
app.getItineraryHelper().addOrEnableGroup(gpxFile);
|
||||
}
|
||||
} else {
|
||||
ItineraryGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile);
|
||||
MapMarkersGroup group = app.getItineraryHelper().getMarkersGroup(gpxFile);
|
||||
if (group != null) {
|
||||
markersHelper.removeMarkersGroup(group);
|
||||
app.getItineraryHelper().removeMarkersGroup(group);
|
||||
}
|
||||
}
|
||||
trackActivity.invalidateOptionsMenu();
|
||||
|
|
|
@ -10,9 +10,10 @@ import net.osmand.GPXUtilities.GPXFile;
|
|||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||
import net.osmand.plus.itinerary.ItineraryType;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
||||
import net.osmand.plus.settings.backend.ExportSettingsType;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -122,10 +123,10 @@ public class HistoryMarkersSettingsItem extends CollectionSettingsItem<MapMarker
|
|||
}
|
||||
}
|
||||
|
||||
public ItineraryGroup getMarkersGroup() {
|
||||
public MapMarkersGroup getMarkersGroup() {
|
||||
String name = app.getString(R.string.markers_history);
|
||||
String groupId = ExportSettingsType.HISTORY_MARKERS.name();
|
||||
ItineraryGroup markersGroup = new ItineraryGroup(groupId, name, ItineraryGroup.ANY_TYPE);
|
||||
MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
|
||||
markersGroup.setMarkers(items);
|
||||
return markersGroup;
|
||||
}
|
||||
|
|
|
@ -10,9 +10,10 @@ import net.osmand.GPXUtilities.GPXFile;
|
|||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||
import net.osmand.plus.itinerary.ItineraryType;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
||||
import net.osmand.plus.settings.backend.ExportSettingsType;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -122,10 +123,10 @@ public class MarkersSettingsItem extends CollectionSettingsItem<MapMarker> {
|
|||
}
|
||||
}
|
||||
|
||||
public ItineraryGroup getMarkersGroup() {
|
||||
public MapMarkersGroup getMarkersGroup() {
|
||||
String name = app.getString(R.string.map_markers);
|
||||
String groupId = ExportSettingsType.ACTIVE_MARKERS.name();
|
||||
ItineraryGroup markersGroup = new ItineraryGroup(groupId, name, ItineraryGroup.ANY_TYPE);
|
||||
MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
|
||||
markersGroup.setMarkers(items);
|
||||
return markersGroup;
|
||||
}
|
||||
|
|
|
@ -32,8 +32,9 @@ import net.osmand.plus.helpers.GpxUiHelper;
|
|||
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||
import net.osmand.plus.itinerary.ItineraryType;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine;
|
||||
import net.osmand.plus.osmedit.OpenstreetmapPoint;
|
||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||
|
@ -609,7 +610,7 @@ public class SettingsHelper {
|
|||
if (!mapMarkers.isEmpty()) {
|
||||
String name = app.getString(R.string.map_markers);
|
||||
String groupId = ExportSettingsType.ACTIVE_MARKERS.name();
|
||||
ItineraryGroup markersGroup = new ItineraryGroup(groupId, name, ItineraryGroup.ANY_TYPE);
|
||||
MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
|
||||
markersGroup.setMarkers(mapMarkers);
|
||||
myPlacesItems.put(ExportSettingsType.ACTIVE_MARKERS, Collections.singletonList(markersGroup));
|
||||
}
|
||||
|
@ -617,7 +618,7 @@ public class SettingsHelper {
|
|||
if (!markersHistory.isEmpty()) {
|
||||
String name = app.getString(R.string.shared_string_history);
|
||||
String groupId = ExportSettingsType.HISTORY_MARKERS.name();
|
||||
ItineraryGroup markersGroup = new ItineraryGroup(groupId, name, ItineraryGroup.ANY_TYPE);
|
||||
MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
|
||||
markersGroup.setMarkers(markersHistory);
|
||||
myPlacesItems.put(ExportSettingsType.HISTORY_MARKERS, Collections.singletonList(markersGroup));
|
||||
}
|
||||
|
@ -720,8 +721,8 @@ public class SettingsHelper {
|
|||
List<FavoriteGroup> favoriteGroups = new ArrayList<>();
|
||||
List<OsmNotesPoint> osmNotesPointList = new ArrayList<>();
|
||||
List<OpenstreetmapPoint> osmEditsPointList = new ArrayList<>();
|
||||
List<ItineraryGroup> markersGroups = new ArrayList<>();
|
||||
List<ItineraryGroup> markersHistoryGroups = new ArrayList<>();
|
||||
List<MapMarkersGroup> markersGroups = new ArrayList<>();
|
||||
List<MapMarkersGroup> markersHistoryGroups = new ArrayList<>();
|
||||
List<HistoryEntry> historyEntries = new ArrayList<>();
|
||||
List<OnlineRoutingEngine> onlineRoutingEngines = new ArrayList<>();
|
||||
|
||||
|
@ -755,12 +756,12 @@ public class SettingsHelper {
|
|||
osmEditsPointList.add((OpenstreetmapPoint) object);
|
||||
} else if (object instanceof FavoriteGroup) {
|
||||
favoriteGroups.add((FavoriteGroup) object);
|
||||
} else if (object instanceof ItineraryGroup) {
|
||||
ItineraryGroup markersGroup = (ItineraryGroup) object;
|
||||
} else if (object instanceof MapMarkersGroup) {
|
||||
MapMarkersGroup markersGroup = (MapMarkersGroup) object;
|
||||
if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) {
|
||||
markersGroups.add((ItineraryGroup) object);
|
||||
markersGroups.add((MapMarkersGroup) object);
|
||||
} else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) {
|
||||
markersHistoryGroups.add((ItineraryGroup) object);
|
||||
markersHistoryGroups.add((MapMarkersGroup) object);
|
||||
}
|
||||
} else if (object instanceof HistoryEntry) {
|
||||
historyEntries.add((HistoryEntry) object);
|
||||
|
@ -812,7 +813,7 @@ public class SettingsHelper {
|
|||
}
|
||||
if (!markersGroups.isEmpty()) {
|
||||
List<MapMarker> mapMarkers = new ArrayList<>();
|
||||
for (ItineraryGroup group : markersGroups) {
|
||||
for (MapMarkersGroup group : markersGroups) {
|
||||
mapMarkers.addAll(group.getMarkers());
|
||||
}
|
||||
MarkersSettingsItem baseItem = getBaseItem(SettingsItemType.ACTIVE_MARKERS, MarkersSettingsItem.class, settingsItems);
|
||||
|
@ -820,7 +821,7 @@ public class SettingsHelper {
|
|||
}
|
||||
if (!markersHistoryGroups.isEmpty()) {
|
||||
List<MapMarker> mapMarkers = new ArrayList<>();
|
||||
for (ItineraryGroup group : markersHistoryGroups) {
|
||||
for (MapMarkersGroup group : markersHistoryGroups) {
|
||||
mapMarkers.addAll(group.getMarkers());
|
||||
}
|
||||
HistoryMarkersSettingsItem baseItem = getBaseItem(SettingsItemType.HISTORY_MARKERS, HistoryMarkersSettingsItem.class, settingsItems);
|
||||
|
@ -910,8 +911,8 @@ public class SettingsHelper {
|
|||
List<OsmNotesPoint> notesPointList = new ArrayList<>();
|
||||
List<OpenstreetmapPoint> editsPointList = new ArrayList<>();
|
||||
List<FavoriteGroup> favoriteGroups = new ArrayList<>();
|
||||
List<ItineraryGroup> markersGroups = new ArrayList<>();
|
||||
List<ItineraryGroup> markersHistoryGroups = new ArrayList<>();
|
||||
List<MapMarkersGroup> markersGroups = new ArrayList<>();
|
||||
List<MapMarkersGroup> markersHistoryGroups = new ArrayList<>();
|
||||
List<HistoryEntry> historyEntries = new ArrayList<>();
|
||||
List<OnlineRoutingEngine> onlineRoutingEngines = new ArrayList<>();
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
|
|||
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||
import net.osmand.plus.helpers.GpxUiHelper;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||
import net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine;
|
||||
import net.osmand.plus.osmedit.OpenstreetmapPoint;
|
||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||
|
@ -376,8 +376,8 @@ public class ExportItemsBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
GlobalSettingsItem globalSettingsItem = (GlobalSettingsItem) object;
|
||||
item.setTitle(globalSettingsItem.getPublicName(app));
|
||||
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_settings, getItemIconColor(object)));
|
||||
} else if (object instanceof ItineraryGroup) {
|
||||
ItineraryGroup markersGroup = (ItineraryGroup) object;
|
||||
} else if (object instanceof MapMarkersGroup) {
|
||||
MapMarkersGroup markersGroup = (MapMarkersGroup) object;
|
||||
if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) {
|
||||
item.setTitle(getString(R.string.map_markers));
|
||||
item.setIcon(uiUtilities.getIcon(R.drawable.ic_action_flag, getItemIconColor(object)));
|
||||
|
|
|
@ -18,7 +18,7 @@ import net.osmand.plus.UiUtilities;
|
|||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.helpers.FontCache;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||
import net.osmand.plus.settings.backend.ExportSettingsCategory;
|
||||
import net.osmand.plus.settings.backend.ExportSettingsType;
|
||||
import net.osmand.plus.settings.backend.backup.FileSettingsItem;
|
||||
|
@ -311,8 +311,8 @@ public class ExportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
|||
itemsSize += ((FileSettingsItem) object).getSize();
|
||||
} else if (object instanceof File) {
|
||||
itemsSize += ((File) object).length();
|
||||
} else if (object instanceof ItineraryGroup) {
|
||||
int selectedMarkers = ((ItineraryGroup) object).getMarkers().size();
|
||||
} else if (object instanceof MapMarkersGroup) {
|
||||
int selectedMarkers = ((MapMarkersGroup) object).getMarkers().size();
|
||||
String itemsDescr = app.getString(R.string.shared_string_items);
|
||||
return app.getString(R.string.ltr_or_rtl_combine_via_colon, itemsDescr, selectedMarkers);
|
||||
}
|
||||
|
|
|
@ -44,7 +44,6 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.base.PointImageDrawable;
|
||||
import net.osmand.plus.itinerary.ItineraryGroup;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint;
|
||||
import net.osmand.plus.mapcontextmenu.other.TrackChartPoints;
|
||||
import net.osmand.plus.mapmarkers.MapMarker;
|
||||
|
@ -1225,10 +1224,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
|
|||
}
|
||||
|
||||
private void syncGpx(GPXFile gpxFile) {
|
||||
ItineraryGroup group = view.getApplication().getItineraryHelper().getMarkersGroup(gpxFile);
|
||||
if (group != null) {
|
||||
view.getApplication().getItineraryHelper().runSynchronization(group);
|
||||
}
|
||||
view.getApplication().getItineraryHelper().runSynchronizationAsync(gpxFile);
|
||||
}
|
||||
|
||||
private static class CachedTrack {
|
||||
|
|
Loading…
Reference in a new issue