Compare commits

...

8 commits

Author SHA1 Message Date
Vitaliy
a259064d29 Add MarkersDbHelperLegacy 2021-04-22 19:16:23 +03:00
Vitaliy
0256796d23 Fix saving id with alias 2021-04-22 17:58:27 +03:00
Vitaliy
c1e6654319 Merge branch 'master' into markers_refactor 2021-04-22 17:54:17 +03:00
Vitaliy
a2b6faf94a Revert renaming 2021-04-22 12:47:26 +03:00
Vitaliy
ec03c40c1b Remove group alias 2021-04-22 11:27:26 +03:00
Vitaliy
311771f03c Save itinerary.gpx 2021-04-22 05:09:03 +03:00
Vitaliy
4cc970c0d2 Add itineraryType 2021-04-22 05:06:45 +03:00
Vitaliy
256d634cdb Rename markersHelper and move fragments to separate packages 2021-04-22 05:01:58 +03:00
47 changed files with 815 additions and 464 deletions

View file

@ -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,36 +2146,36 @@ 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 file, GPXExtensionsReader extensionsReader) {
FileInputStream fis = null;
try {
fis = new FileInputStream(f);
GPXFile file = loadGPXFile(fis);
file.path = f.getAbsolutePath();
file.modifiedTime = f.lastModified();
fis = new FileInputStream(file);
GPXFile gpxFile = loadGPXFile(fis, extensionsReader);
gpxFile.path = file.getAbsolutePath();
gpxFile.modifiedTime = file.lastModified();
try {
fis.close();
} catch (IOException e) {
}
return file;
Algorithms.closeStream(fis);
return gpxFile;
} catch (IOException e) {
GPXFile res = new GPXFile(null);
res.path = f.getAbsolutePath();
log.error("Error reading gpx " + res.path, e); //$NON-NLS-1$
res.error = e;
return res;
GPXFile gpxFile = new GPXFile(null);
gpxFile.path = file.getAbsolutePath();
log.error("Error reading gpx " + gpxFile.path, e); //$NON-NLS-1$
gpxFile.error = e;
return gpxFile;
} 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,17 +2231,19 @@ public class GPXUtilities {
break;
default:
Map<String, String> values = readTextMap(parser, tag);
if (values.size() > 0) {
for (Entry<String, String> entry : values.entrySet()) {
String t = entry.getKey().toLowerCase();
String value = entry.getValue();
parse.getExtensionsToWrite().put(t, value);
if (tag.equals("speed") && parse instanceof WptPt) {
try {
((WptPt) parse).speed = Float.parseFloat(value);
} catch (NumberFormatException e) {
log.debug(e.getMessage(), e);
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()) {
String t = entry.getKey().toLowerCase();
String value = entry.getValue();
parse.getExtensionsToWrite().put(t, value);
if (tag.equals("speed") && parse instanceof WptPt) {
try {
((WptPt) parse).speed = Float.parseFloat(value);
} catch (NumberFormatException e) {
log.debug(e.getMessage(), e);
}
}
}
}

View file

@ -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) {
if (isEmpty(s)) {
return Collections.emptySet();
}
return new HashSet<>(Arrays.asList(s.split(CHAR_TOSPLIT + "")));
return decodeStringSet(s, String.valueOf(CHAR_TOSPLIT));
}
public static String encodeStringSet(Set<String> set) {
return encodeStringSet(set, String.valueOf(CHAR_TOSPLIT));
}
public static Set<String> decodeStringSet(String s, String split) {
if (isEmpty(s)) {
return Collections.emptySet();
}
return new LinkedHashSet<>(Arrays.asList(s.split(split)));
}
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();
}

View file

@ -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;
@ -333,7 +333,7 @@ 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 + ((name == null) ? 0 : name.hashCode());
result = prime * result + ((category == null) ? 0 : category.hashCode());
result = prime * result + ((description == null) ? 0 : description.hashCode());
@ -454,8 +454,7 @@ public class FavouritePoint implements Serializable, LocationPoint {
if (name == null) {
name = "";
}
FavouritePoint fp;
fp = new FavouritePoint(pt.lat, pt.lon, name, categoryName, pt.ele, pt.time);
FavouritePoint fp = new FavouritePoint(pt.lat, pt.lon, name, categoryName, pt.ele, pt.time);
fp.setDescription(pt.desc);
if (pt.comment != null) {
fp.setOriginObjectName(pt.comment);

View file

@ -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.mapmarkers.MapMarkersGroup;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.util.Algorithms;
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
@ -246,7 +247,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;
@ -580,7 +581,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));
@ -635,7 +636,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();
}
@ -648,7 +653,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) {
@ -845,9 +850,7 @@ public class FavouritesDbHelper {
}
for (WptPt p : res.getPoints()) {
FavouritePoint fp = FavouritePoint.fromWpt(p, context);
if (fp != null) {
points.put(getKey(fp), fp);
}
points.put(getKey(fp), fp);
}
return true;
}
@ -959,7 +962,7 @@ public class FavouritesDbHelper {
public void onUpgrade(SQLiteConnection db, int oldVersion, int newVersion) {
if (oldVersion == 1) {
db.execSQL("ALTER TABLE " + FAVOURITE_TABLE_NAME + " ADD " + FAVOURITE_COL_CATEGORY + " text");
db.execSQL("UPDATE " + FAVOURITE_TABLE_NAME + " SET category = ?", new Object[]{""}); //$NON-NLS-1$ //$NON-NLS-2$
db.execSQL("UPDATE " + FAVOURITE_TABLE_NAME + " SET category = ?", new Object[] {""}); //$NON-NLS-1$ //$NON-NLS-2$
}
}

View file

@ -112,7 +112,7 @@ import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu;
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkersHelper.MapMarkerChangedListener;
import net.osmand.plus.mapmarkers.PlanRouteFragment;
import net.osmand.plus.mapmarkers.fragments.PlanRouteFragment;
import net.osmand.plus.measurementtool.GpxApproximationFragment;
import net.osmand.plus.measurementtool.GpxData;
import net.osmand.plus.measurementtool.LoginBottomSheetFragment;

View file

@ -46,17 +46,15 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.Version;
import net.osmand.plus.activities.actions.OsmAndDialogs;
import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
import net.osmand.plus.dialogs.FavoriteDialogs;
import net.osmand.plus.dialogs.SpeedCamerasBottomSheet;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.liveupdates.OsmLiveActivity;
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment;
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
import net.osmand.plus.mapmarkers.fragments.MapMarkersDialogFragment;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.mapmarkers.MarkersPlanRouteContext;
import net.osmand.plus.measurementtool.MeasurementToolFragment;
@ -107,7 +105,6 @@ import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_HELP_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_MAP_MARKERS_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_MEASURE_DISTANCE_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_MY_PLACES_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_OSMAND_LIVE_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_PLUGINS_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SEARCH_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;

View file

@ -34,7 +34,7 @@ import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.LockableViewPager;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment;
import net.osmand.plus.mapmarkers.fragments.CoordinateInputDialogFragment;
import net.osmand.plus.measurementtool.GpxData;
import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.myplaces.SplitSegmentDialogFragment;

View file

@ -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.mapmarkers.MapMarkersDialogFragment;
import net.osmand.plus.mapmarkers.fragments.MapMarkersDialogFragment;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapsource.EditMapSourceDialogFragment;
import net.osmand.plus.openplacereviews.OPRConstants;

View file

@ -1,4 +0,0 @@
package net.osmand.plus.mapmarkers;
import androidx.annotation.DrawableRes;

View file

@ -0,0 +1,266 @@
package net.osmand.plus.mapmarkers;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import net.osmand.FileUtils;
import net.osmand.GPXUtilities;
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.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.Version;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlSerializer;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import static net.osmand.GPXUtilities.writeNotNullText;
import static net.osmand.plus.FavouritesDbHelper.backup;
import static net.osmand.util.MapUtils.createShortLinkString;
public class ItineraryDataHelper {
private static final Log log = PlatformUtil.getLog(ItineraryDataHelper.class);
private static final String VISITED_DATE = "visited_date";
private static final String CREATION_DATE = "creation_date";
private static final String CATEGORIES_SPLIT = ",";
private static final String FILE_TO_SAVE = "itinerary.gpx";
private static final String FILE_TO_BACKUP = "itinerary_bak.gpx";
private static final String ITINERARY_ID = "itinerary_id";
private static final String ITINERARY_GROUP = "itinerary_group";
private static final String GPX_KEY = "gpx";
private static final String FAVOURITES_KEY = "favourites_group";
private static final SimpleDateFormat GPX_TIME_FORMAT = new SimpleDateFormat(GPXUtilities.GPX_TIME_FORMAT, Locale.US);
static {
GPX_TIME_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
}
private OsmandApplication app;
private MapMarkersHelper mapMarkersHelper;
public ItineraryDataHelper(OsmandApplication app, MapMarkersHelper mapMarkersHelper) {
this.app = app;
this.mapMarkersHelper = mapMarkersHelper;
}
private File getInternalFile() {
return app.getFileStreamPath(FILE_TO_BACKUP);
}
public File getExternalFile() {
return new File(app.getAppPath(null), FILE_TO_SAVE);
}
public File getBackupFile() {
return FavouritesDbHelper.getBackupFile(app, "itinerary_bak_");
}
public void saveGroups() {
try {
saveFile(getInternalFile());
saveFile(getExternalFile());
backup(getBackupFile(), getExternalFile());
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
public Exception saveFile(File file) {
List<MapMarkersGroup> groups = mapMarkersHelper.getMapMarkersGroups();
GPXFile gpxFile = generateGpx(groups);
return GPXUtilities.writeGpxFile(file, 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 String saveMarkersToFile(String fileName) {
GPXFile gpxFile = generateGpx();
String dirName = IndexConstants.GPX_INDEX_DIR + IndexConstants.MAP_MARKERS_INDEX_DIR;
File dir = app.getAppPath(dirName);
if (!dir.exists()) {
dir.mkdirs();
}
String uniqueFileName = FileUtils.createUniqueFileName(app, fileName, dirName, IndexConstants.GPX_FILE_EXT);
File fout = new File(dir, uniqueFileName + IndexConstants.GPX_FILE_EXT);
GPXUtilities.writeGpxFile(fout, gpxFile);
return fout.getAbsolutePath();
}
public GPXFile generateGpx() {
return generateGpx(mapMarkersHelper.getMapMarkers(), false);
}
public GPXFile generateGpx(List<MapMarker> markers, boolean completeBackup) {
GPXFile gpxFile = new GPXFile(Version.getFullVersion(app));
for (MapMarker marker : markers) {
WptPt wpt = toWpt(marker);
wpt.setColor(ContextCompat.getColor(app, MapMarker.getColorId(marker.colorIndex)));
if (completeBackup) {
if (marker.creationDate != 0) {
wpt.getExtensionsToWrite().put(CREATION_DATE, GPX_TIME_FORMAT.format(new Date(marker.creationDate)));
}
if (marker.visitedDate != 0) {
wpt.getExtensionsToWrite().put(VISITED_DATE, GPX_TIME_FORMAT.format(new Date(marker.visitedDate)));
}
}
gpxFile.addPoint(wpt);
}
return gpxFile;
}
public GPXFile generateGpx(List<MapMarkersGroup> mapMarkersGroups) {
GPXFile gpxFile = new GPXFile(Version.getFullVersion(app));
List<ItineraryGroupInfo> groups = new ArrayList<>();
for (MapMarkersGroup group : mapMarkersGroups) {
ItineraryGroupInfo groupInfo = ItineraryGroupInfo.createGroupInfo(app, group);
for (MapMarker marker : group.getMarkers()) {
WptPt wptPt = toWpt(marker);
Map<String, String> extensions = wptPt.getExtensionsToWrite();
if (group.getType() != ItineraryType.FAVOURITES) {
String itineraryId = createShortLinkString(wptPt.lat, wptPt.lon, 15);
extensions.put(ITINERARY_ID, groupInfo.alias + ":" + itineraryId);
} else {
extensions.put(ITINERARY_ID, groupInfo.alias + ":" + marker.getName(app));
}
if (group.getType() == ItineraryType.TRACK) {
extensions.put(GPX_KEY, groupInfo.path);
} else if (group.getType() == ItineraryType.FAVOURITES && !Algorithms.isEmpty(groupInfo.name)) {
extensions.put(FAVOURITES_KEY, groupInfo.name);
}
gpxFile.addPoint(wptPt);
}
groups.add(groupInfo);
}
assignRouteExtensionWriter(gpxFile, groups);
return gpxFile;
}
public List<MapMarker> readMarkersFromGpx(GPXFile gpxFile, boolean history) {
List<MapMarker> mapMarkers = new ArrayList<>();
for (WptPt point : gpxFile.getPoints()) {
MapMarker marker = fromWpt(point, app, history);
mapMarkers.add(marker);
}
return mapMarkers;
}
public static MapMarker fromWpt(@NonNull WptPt point, @NonNull Context ctx, boolean history) {
LatLon latLon = new LatLon(point.lat, point.lon);
int colorIndex = MapMarker.getColorIndex(ctx, point.getColor());
PointDescription name = new PointDescription(PointDescription.POINT_TYPE_LOCATION, point.name);
MapMarker marker = new MapMarker(latLon, name, colorIndex, false, 0);
String visitedDateStr = point.getExtensionsToRead().get(VISITED_DATE);
String creationDateStr = point.getExtensionsToRead().get(CREATION_DATE);
marker.visitedDate = parseTime(visitedDateStr);
marker.creationDate = parseTime(creationDateStr);
marker.history = history;
marker.nextKey = history ? MapMarkersDbHelper.HISTORY_NEXT_VALUE : MapMarkersDbHelper.TAIL_NEXT_VALUE;
return marker;
}
public static WptPt toWpt(@NonNull MapMarker marker) {
WptPt wpt = new WptPt();
wpt.lat = marker.getLatitude();
wpt.lon = marker.getLongitude();
wpt.name = marker.getOnlyName();
return wpt;
}
private static long parseTime(String text) {
long time = 0;
if (text != null) {
try {
time = GPX_TIME_FORMAT.parse(text).getTime();
} catch (ParseException e) {
log.error(e);
}
}
return time;
}
public static class ItineraryGroupInfo {
public String name;
public String type;
public String path;
public String alias;
public String categories;
public static ItineraryGroupInfo createGroupInfo(OsmandApplication app, MapMarkersGroup group) {
ItineraryGroupInfo groupInfo = new ItineraryGroupInfo();
groupInfo.name = group.getName();
groupInfo.type = group.getType().getTypeName();
Set<String> wptCategories = group.getWptCategories();
if (!Algorithms.isEmpty(wptCategories)) {
groupInfo.categories = Algorithms.encodeStringSet(wptCategories, CATEGORIES_SPLIT);
}
if (group.getType() == ItineraryType.TRACK) {
String path = group.getId();
String gpxDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR).getAbsolutePath();
int index = path.indexOf(gpxDir);
if (index != -1) {
path = path.substring(gpxDir.length() + 1);
}
groupInfo.path = path;
groupInfo.alias = groupInfo.type + ":" + path.replace(IndexConstants.GPX_FILE_EXT, "");
} else {
groupInfo.alias = groupInfo.type + (groupInfo.name == null ? "" : ":" + groupInfo.name);
}
return groupInfo;
}
}
}

View file

@ -0,0 +1,43 @@
package net.osmand.plus.mapmarkers;
import androidx.annotation.NonNull;
public enum ItineraryType {
MARKERS("markers", -1),
FAVOURITES("favourites", 0),
TRACK("track", 1);
private int typeId;
private String typeName;
ItineraryType(@NonNull String typeName, int typeId) {
this.typeName = typeName;
this.typeId = typeId;
}
public int getTypeId() {
return typeId;
}
public String getTypeName() {
return typeName;
}
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.getTypeName().equalsIgnoreCase(typeName)) {
return type;
}
}
return ItineraryType.MARKERS;
}
}

View file

@ -44,10 +44,10 @@ public class MapMarker implements LocationPoint {
this.index = index;
}
public int getType() {
public ItineraryType getType() {
return favouritePoint == null ?
(wptPt == null ? MapMarkersGroup.ANY_TYPE : MapMarkersGroup.GPX_TYPE) :
MapMarkersGroup.FAVORITES_TYPE;
(wptPt == null ? ItineraryType.MARKERS : ItineraryType.TRACK) :
ItineraryType.FAVOURITES;
}
public PointDescription getPointDescription(Context ctx) {

View file

@ -8,7 +8,6 @@ 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.util.Algorithms;
import java.util.ArrayList;
import java.util.HashSet;
@ -21,22 +20,22 @@ import java.util.Set;
public class MapMarkersDbHelper {
private static final int DB_VERSION = 13;
static final int DB_VERSION = 13;
public static final String DB_NAME = "map_markers_db";
private static final String MARKERS_TABLE_NAME = "map_markers";
protected static final String MARKERS_TABLE_NAME = "map_markers";
private static final String MARKERS_COL_ID = "marker_id";
private static final String MARKERS_COL_LAT = "marker_lat";
private static final String MARKERS_COL_LON = "marker_lon";
private static final String MARKERS_COL_DESCRIPTION = "marker_description";
private static final String MARKERS_COL_ACTIVE = "marker_active";
protected static final String MARKERS_COL_ACTIVE = "marker_active";
private static final String MARKERS_COL_ADDED = "marker_added";
private static final String MARKERS_COL_VISITED = "marker_visited";
private static final String MARKERS_COL_GROUP_NAME = "group_name";
private static final String MARKERS_COL_GROUP_KEY = "group_key";
protected static final String MARKERS_COL_GROUP_KEY = "group_key";
private static final String MARKERS_COL_COLOR = "marker_color";
private static final String MARKERS_COL_NEXT_KEY = "marker_next_key";
private static final String MARKERS_COL_DISABLED = "marker_disabled";
protected static final String MARKERS_COL_DISABLED = "marker_disabled";
private static final String MARKERS_COL_SELECTED = "marker_selected";
private static final String MARKERS_COL_MAP_OBJECT_NAME = "marker_map_object_name";
@ -74,54 +73,40 @@ public class MapMarkersDbHelper {
MARKERS_COL_MAP_OBJECT_NAME +
" FROM " + MARKERS_TABLE_NAME;
private static final String GROUPS_TABLE_NAME = "map_markers_groups";
private static final String GROUPS_COL_ID = "group_id";
private static final String GROUPS_COL_NAME = "group_name";
private static final String GROUPS_COL_TYPE = "group_type";
private static final String GROUPS_COL_DISABLED = "group_disabled";
private static final String GROUPS_COL_CATEGORIES = "group_categories";
private static final String GROUPS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " +
GROUPS_TABLE_NAME + " (" +
GROUPS_COL_ID + " TEXT PRIMARY KEY, " +
GROUPS_COL_NAME + " TEXT, " +
GROUPS_COL_TYPE + " int, " +
GROUPS_COL_DISABLED + " int, " + // 1 = true, 0 = false
GROUPS_COL_CATEGORIES + " TEXT);";
private static final String GROUPS_TABLE_SELECT = "SELECT " +
GROUPS_COL_ID + ", " +
GROUPS_COL_NAME + ", " +
GROUPS_COL_TYPE + ", " +
GROUPS_COL_DISABLED + ", " +
GROUPS_COL_CATEGORIES +
" FROM " + GROUPS_TABLE_NAME;
public static final String TAIL_NEXT_VALUE = "tail_next";
public static final String HISTORY_NEXT_VALUE = "history_next";
private final OsmandApplication context;
private final OsmandApplication app;
private final MarkersDbHelperLegacy helperLegacy;
public MapMarkersDbHelper(OsmandApplication context) {
this.context = context;
public MapMarkersDbHelper(OsmandApplication app) {
this.app = app;
this.helperLegacy = new MarkersDbHelperLegacy(app, this);
}
private SQLiteConnection openConnection(boolean readonly) {
SQLiteConnection conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, readonly);
public MarkersDbHelperLegacy getHelperLegacy() {
return helperLegacy;
}
protected SQLiteConnection openConnection(boolean readonly) {
SQLiteConnection conn = app.getSQLiteAPI().getOrCreateDatabase(DB_NAME, readonly);
if (conn == null) {
return null;
}
if (conn.getVersion() < DB_VERSION) {
if (readonly) {
conn.close();
conn = context.getSQLiteAPI().getOrCreateDatabase(DB_NAME, false);
conn = app.getSQLiteAPI().getOrCreateDatabase(DB_NAME, false);
}
int version = conn.getVersion();
conn.setVersion(DB_VERSION);
if (version == 0) {
onCreate(conn);
} else {
onUpgrade(conn, version, DB_VERSION);
if (conn != null) {
int version = conn.getVersion();
conn.setVersion(DB_VERSION);
if (version == 0) {
onCreate(conn);
} else {
onUpgrade(conn, version, DB_VERSION);
}
}
}
return conn;
@ -129,18 +114,15 @@ public class MapMarkersDbHelper {
private void onCreate(SQLiteConnection db) {
db.execSQL(MARKERS_TABLE_CREATE);
db.execSQL(GROUPS_TABLE_CREATE);
helperLegacy.onCreate(db);
}
private void onUpgrade(SQLiteConnection db, int oldVersion, int newVersion) {
helperLegacy.onUpgrade(db, oldVersion, newVersion);
if (oldVersion < 8) {
db.execSQL("ALTER TABLE " + MARKERS_TABLE_NAME + " ADD " + MARKERS_COL_DISABLED + " int");
db.execSQL("ALTER TABLE " + GROUPS_TABLE_NAME + " ADD " + GROUPS_COL_DISABLED + " int");
}
if (oldVersion < 9) {
db.execSQL("UPDATE " + GROUPS_TABLE_NAME +
" SET " + GROUPS_COL_DISABLED + " = ? " +
"WHERE " + GROUPS_COL_DISABLED + " IS NULL", new Object[]{0});
db.execSQL("UPDATE " + MARKERS_TABLE_NAME +
" SET " + MARKERS_COL_DISABLED + " = ? " +
"WHERE " + MARKERS_COL_DISABLED + " IS NULL", new Object[]{0});
@ -156,68 +138,6 @@ public class MapMarkersDbHelper {
if (oldVersion < 12) {
db.execSQL("ALTER TABLE " + MARKERS_TABLE_NAME + " ADD " + MARKERS_COL_MAP_OBJECT_NAME + " TEXT");
}
if (oldVersion < 13) {
db.execSQL("ALTER TABLE " + GROUPS_TABLE_NAME + " ADD " + GROUPS_COL_CATEGORIES + " TEXT");
}
}
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()});
} finally {
db.close();
}
}
}
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 {
MapMarkersGroup group = readGroup(query);
res.put(group.getId(), group);
} while (query.moveToNext());
}
if(query != null) {
query.close();
}
} finally {
db.close();
}
}
return res;
}
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);
MapMarkersGroup res = new MapMarkersGroup(id, name, type);
res.setDisabled(disabled);
res.setWptCategories(categories == null ? null : Algorithms.decodeStringSet(categories));
return res;
}
public void removeMarkersGroup(String id) {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
db.execSQL("DELETE FROM " + GROUPS_TABLE_NAME + " WHERE " + GROUPS_COL_ID + " = ?", new Object[]{id});
} finally {
db.close();
}
}
}
public void removeActiveMarkersFromGroup(String groupId) {
@ -227,49 +147,7 @@ public class MapMarkersDbHelper {
db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME +
" WHERE " + MARKERS_COL_GROUP_KEY + " = ?" +
" AND " + MARKERS_COL_ACTIVE + " = ?",
new Object[]{groupId, 1});
} finally {
db.close();
}
}
}
public void updateGroupDisabled(String id, boolean disabled) {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
db.execSQL("UPDATE " + GROUPS_TABLE_NAME +
" SET " + GROUPS_COL_DISABLED + " = ? " +
"WHERE " + GROUPS_COL_ID + " = ?", new Object[]{disabled ? 1 : 0, id});
db.execSQL("UPDATE " + MARKERS_TABLE_NAME +
" SET " + MARKERS_COL_DISABLED + " = ? " +
"WHERE " + MARKERS_COL_GROUP_KEY + " = ?", new Object[]{disabled ? 1 : 0, id});
} finally {
db.close();
}
}
}
public void updateGroupCategories(String id, String categories) {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
db.execSQL("UPDATE " + GROUPS_TABLE_NAME +
" SET " + GROUPS_COL_CATEGORIES + " = ? " +
"WHERE " + GROUPS_COL_ID + " = ?", new Object[]{categories, id});
} finally {
db.close();
}
}
}
public void removeDisabledGroups() {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
db.execSQL("DELETE FROM " + GROUPS_TABLE_NAME + " WHERE " + GROUPS_COL_DISABLED + " = ? ", new Object[]{1});
db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME
+ " WHERE " + MARKERS_COL_DISABLED + " = ? AND " + MARKERS_COL_ACTIVE + " = ?", new Object[]{1, 1});
new Object[] {groupId, 1});
} finally {
db.close();
}
@ -281,7 +159,9 @@ public class MapMarkersDbHelper {
if (db != null) {
try {
for (MapMarker marker : markers) {
insertLast(db, marker);
if (marker.groupKey == null) {
insertLast(db, marker);
}
}
} finally {
db.close();
@ -310,8 +190,8 @@ public class MapMarkersDbHelper {
int active = marker.history ? 0 : 1;
PointDescription pointDescription = marker.getOriginalPointDescription();
if (pointDescription != null && !pointDescription.isSearchingAddress(context)) {
SearchHistoryHelper.getInstance(context)
if (pointDescription != null && !pointDescription.isSearchingAddress(app)) {
SearchHistoryHelper.getInstance(app)
.addNewItemToHistory(marker.getLatitude(), marker.getLongitude(), pointDescription);
}
@ -343,13 +223,18 @@ public class MapMarkersDbHelper {
@Nullable
public MapMarker getMarker(String id) {
return getMarker(id, false);
}
@Nullable
public MapMarker getMarker(String id, boolean legacy) {
MapMarker res = null;
SQLiteConnection db = openConnection(true);
if (db != null) {
try {
SQLiteCursor query = db.rawQuery(MARKERS_TABLE_SELECT + " WHERE " + MARKERS_COL_ID + " = ?", new String[]{id});
if (query != null && query.moveToFirst()) {
res = readItem(query);
res = readItem(query, legacy);
}
if(query != null) {
query.close();
@ -362,6 +247,10 @@ public class MapMarkersDbHelper {
}
public List<MapMarker> getActiveMarkers() {
return getActiveMarkers(false);
}
public List<MapMarker> getActiveMarkers(boolean legacy) {
Map<String, MapMarker> markers = new LinkedHashMap<>();
Set<String> nextKeys = new HashSet<>();
SQLiteConnection db = openConnection(true);
@ -371,9 +260,11 @@ public class MapMarkersDbHelper {
new String[]{String.valueOf(1)});
if (query != null && query.moveToFirst()) {
do {
MapMarker marker = readItem(query);
markers.put(marker.id, marker);
nextKeys.add(marker.nextKey);
MapMarker marker = readItem(query, legacy);
if (marker != null) {
markers.put(marker.id, marker);
nextKeys.add(marker.nextKey);
}
} while (query.moveToNext());
}
if(query != null) {
@ -386,7 +277,13 @@ public class MapMarkersDbHelper {
return buildLinkedList(markers, nextKeys);
}
private MapMarker readItem(SQLiteCursor query) {
@Nullable
private MapMarker readItem(SQLiteCursor query, boolean legacy) {
String groupKey = query.getString(8);
if (groupKey != null && !legacy) {
return null;
}
String id = query.getString(0);
double lat = query.getDouble(1);
double lon = query.getDouble(2);
@ -395,7 +292,6 @@ public class MapMarkersDbHelper {
long added = query.getLong(5);
long visited = query.getLong(6);
String groupName = query.getString(7);
String groupKey = query.getString(8);
int colorIndex = query.getInt(9);
String nextKey = query.getString(10);
boolean selected = query.getInt(12) == 1;
@ -524,6 +420,10 @@ public class MapMarkersDbHelper {
}
public List<MapMarker> getMarkersHistory() {
return getMarkersHistory(false);
}
public List<MapMarker> getMarkersHistory(boolean legacy) {
List<MapMarker> markers = new ArrayList<>();
SQLiteConnection db = openConnection(true);
if (db != null) {
@ -532,7 +432,10 @@ public class MapMarkersDbHelper {
new String[]{String.valueOf(0)});
if (query != null && query.moveToFirst()) {
do {
markers.add(readItem(query));
MapMarker marker = readItem(query, legacy);
if (marker != null) {
markers.add(marker);
}
} while (query.moveToNext());
}
if(query != null) {

View file

@ -12,18 +12,15 @@ import java.util.Set;
public class MapMarkersGroup {
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 ItineraryType type = ItineraryType.MARKERS;
private Set<String> wptCategories;
private long creationDate;
private boolean disabled;
private long creationDate;
private boolean visible = true;
private boolean wasShown = false;
private boolean visibleUntilRestart;
@ -37,7 +34,7 @@ public class MapMarkersGroup {
}
public MapMarkersGroup(@NonNull String id, @NonNull String name, int type) {
public MapMarkersGroup(@NonNull String id, @NonNull String name, @NonNull ItineraryType type) {
this.id = id;
this.name = name;
this.type = type;
@ -95,7 +92,7 @@ public class MapMarkersGroup {
return name;
}
public int getType() {
public ItineraryType getType() {
return type;
}

View file

@ -5,10 +5,7 @@ import android.os.AsyncTask;
import androidx.annotation.IntDef;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import net.osmand.FileUtils;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.IndexConstants;
@ -17,14 +14,13 @@ import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.GPXDatabase;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GeocodingLookupService;
import net.osmand.plus.GeocodingLookupService.AddressLookupRequest;
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.wikivoyage.data.TravelArticle;
import net.osmand.plus.wikivoyage.data.TravelHelper;
import net.osmand.util.Algorithms;
@ -35,24 +31,19 @@ import org.apache.commons.logging.Log;
import java.io.File;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import static net.osmand.GPXUtilities.GPX_TIME_FORMAT;
import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER;
import static net.osmand.util.MapUtils.createShortLinkString;
public class MapMarkersHelper {
@ -65,9 +56,6 @@ public class MapMarkersHelper {
public static final int BY_DATE_ADDED_ASC = 4;
public static final String VISITED_DATE = "visited_date";
public static final String CREATION_DATE = "creation_date";
private static final Log LOG = PlatformUtil.getLog(MapMarkersHelper.class);
@Retention(RetentionPolicy.SOURCE)
@ -75,8 +63,9 @@ public class MapMarkersHelper {
public @interface MapMarkersSortByDef {
}
private OsmandApplication ctx;
private OsmandApplication app;
private MapMarkersDbHelper markersDbHelper;
private ItineraryDataHelper saveHelper;
private ExecutorService executorService = Executors.newSingleThreadExecutor();
@ -102,22 +91,27 @@ public class MapMarkersHelper {
}
public boolean isStartFromMyLocation() {
return ctx.getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.get();
return app.getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.get();
}
public void setStartFromMyLocation(boolean startFromMyLocation) {
ctx.getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.set(startFromMyLocation);
app.getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.set(startFromMyLocation);
}
public MarkersPlanRouteContext getPlanRouteContext() {
return planRouteContext;
}
public MapMarkersHelper(OsmandApplication ctx) {
this.ctx = ctx;
markersDbHelper = ctx.getMapMarkersDbHelper();
planRouteContext = new MarkersPlanRouteContext(ctx);
markersDbHelper.removeDisabledGroups();
public ItineraryDataHelper getSaveHelper() {
return saveHelper;
}
public MapMarkersHelper(OsmandApplication app) {
this.app = app;
saveHelper = new ItineraryDataHelper(app, this);
markersDbHelper = app.getMapMarkersDbHelper();
planRouteContext = new MarkersPlanRouteContext(app);
markersDbHelper.getHelperLegacy().removeDisabledGroups();
loadMarkers();
loadGroups();
}
@ -133,21 +127,21 @@ public class MapMarkersHelper {
sortMarkers(markersHistory, true, BY_DATE_ADDED_DESC);
addToMapMarkersHistoryList(markersHistory);
if (!ctx.isApplicationInitializing()) {
if (!app.isApplicationInitializing()) {
lookupAddressAll();
}
}
private void loadGroups() {
Map<String, MapMarkersGroup> groupsMap = markersDbHelper.getAllGroupsMap();
Map<String, MapMarkersGroup> groupsMap = markersDbHelper.getHelperLegacy().getAllGroupsMap();
List<MapMarker> allMarkers = new ArrayList<>(mapMarkers);
allMarkers.addAll(mapMarkersHistory);
Iterator<Map.Entry<String, MapMarkersGroup>> iterator = groupsMap.entrySet().iterator();
while (iterator.hasNext()) {
MapMarkersGroup group = iterator.next().getValue();
if (group.getType() == MapMarkersGroup.GPX_TYPE && !new File(group.getId()).exists()) {
markersDbHelper.removeMarkersGroup(group.getId());
if (group.getType() == ItineraryType.TRACK && !new File(group.getId()).exists()) {
markersDbHelper.getHelperLegacy().removeMarkersGroup(group.getId());
iterator.remove();
}
}
@ -183,12 +177,17 @@ public class MapMarkersHelper {
}
}
private void saveGroups() {
saveHelper.saveGroups();
}
public void syncAllGroupsAsync() {
for (MapMarkersGroup gr : mapMarkersGroups) {
if (gr.getId() != null && gr.getName() != null) {
runSynchronization(gr);
}
}
saveGroups();
}
public void lookupAddressAll() {
@ -201,7 +200,7 @@ public class MapMarkersHelper {
}
private void lookupAddress(final MapMarker mapMarker) {
if (mapMarker != null && mapMarker.getOriginalPointDescription().isSearchingAddress(ctx)) {
if (mapMarker != null && mapMarker.getOriginalPointDescription().isSearchingAddress(app)) {
cancelPointAddressRequests(mapMarker.point);
AddressLookupRequest lookupRequest = new AddressLookupRequest(mapMarker.point,
new GeocodingLookupService.OnAddressLookupResult() {
@ -209,7 +208,7 @@ public class MapMarkersHelper {
public void geocodingDone(String address) {
PointDescription pointDescription = mapMarker.getOriginalPointDescription();
if (Algorithms.isEmpty(address)) {
pointDescription.setName(PointDescription.getAddressNotFoundStr(ctx));
pointDescription.setName(PointDescription.getAddressNotFoundStr(app));
} else {
pointDescription.setName(address);
}
@ -217,7 +216,7 @@ public class MapMarkersHelper {
refreshMarker(mapMarker);
}
}, null);
ctx.getGeocodingLookupService().lookupAddress(lookupRequest);
app.getGeocodingLookupService().lookupAddress(lookupRequest);
}
}
@ -234,7 +233,7 @@ public class MapMarkersHelper {
private void cancelPointAddressRequests(LatLon latLon) {
if (latLon != null) {
ctx.getGeocodingLookupService().cancel(latLon);
app.getGeocodingLookupService().cancel(latLon);
}
}
@ -295,8 +294,8 @@ public class MapMarkersHelper {
return sortByMode == BY_DISTANCE_DESC ? 1 : -1;
}
} else {
String n1 = mapMarker1.getName(ctx);
String n2 = mapMarker2.getName(ctx);
String n1 = mapMarker1.getName(app);
String n2 = mapMarker2.getName(app);
return n1.compareToIgnoreCase(n2);
}
}
@ -304,7 +303,7 @@ public class MapMarkersHelper {
}
public void runSynchronization(final @NonNull MapMarkersGroup group) {
ctx.runInUIThread(new Runnable() {
app.runInUIThread(new Runnable() {
@Override
public void run() {
new SyncGroupTask(group).executeOnExecutor(executorService);
@ -316,16 +315,16 @@ public class MapMarkersHelper {
if (gpx == null || gpx.path == null) {
return null;
}
return getMapMarkerGroupById(getMarkerGroupId(new File(gpx.path)), MapMarkersGroup.GPX_TYPE);
return getMapMarkerGroupById(getMarkerGroupId(new File(gpx.path)), ItineraryType.TRACK);
}
public MapMarkersGroup getMarkersGroup(FavoriteGroup favGroup) {
return getMapMarkerGroupById(getMarkerGroupId(favGroup), MapMarkersGroup.FAVORITES_TYPE);
return getMapMarkerGroupById(getMarkerGroupId(favGroup), ItineraryType.FAVOURITES);
}
public MapMarkersGroup addOrEnableGpxGroup(@NonNull File file) {
updateGpxShowAsMarkers(file);
MapMarkersGroup gr = getMapMarkerGroupById(getMarkerGroupId(file), MapMarkersGroup.GPX_TYPE);
MapMarkersGroup gr = getMapMarkerGroupById(getMarkerGroupId(file), ItineraryType.TRACK);
if (gr == null) {
gr = createGPXMarkerGroup(file);
addGroupInternally(gr);
@ -367,15 +366,15 @@ public class MapMarkersHelper {
}
private void addGroupInternally(MapMarkersGroup gr) {
markersDbHelper.addGroup(gr);
markersDbHelper.getHelperLegacy().addGroup(gr);
addHistoryMarkersToGroup(gr);
addToGroupsList(gr);
}
private void updateGpxShowAsMarkers(File file) {
GPXDatabase.GpxDataItem dataItem = ctx.getGpxDbHelper().getItem(file);
GpxDataItem dataItem = app.getGpxDbHelper().getItem(file);
if (dataItem != null) {
ctx.getGpxDbHelper().updateShowAsMarkers(dataItem, true);
app.getGpxDbHelper().updateShowAsMarkers(dataItem, true);
dataItem.setShowAsMarkers(true);
}
}
@ -391,7 +390,7 @@ public class MapMarkersHelper {
public void removeMarkersGroup(MapMarkersGroup group) {
if (group != null) {
markersDbHelper.removeMarkersGroup(group.getId());
markersDbHelper.getHelperLegacy().removeMarkersGroup(group.getId());
removeGroupActiveMarkers(group, false);
removeFromGroupsList(group);
}
@ -400,7 +399,7 @@ public class MapMarkersHelper {
public void updateGroupDisabled(@NonNull MapMarkersGroup group, boolean disabled) {
String id = group.getId();
if (id != null) {
markersDbHelper.updateGroupDisabled(id, disabled);
markersDbHelper.getHelperLegacy().updateGroupDisabled(id, disabled);
group.setDisabled(disabled);
}
}
@ -410,7 +409,7 @@ public class MapMarkersHelper {
if (id != null) {
group.setWptCategories(wptCategories);
if (wptCategories != null) {
markersDbHelper.updateGroupCategories(id, group.getWptCategoriesString());
markersDbHelper.getHelperLegacy().updateGroupCategories(id, group.getWptCategoriesString());
}
}
}
@ -456,6 +455,7 @@ public class MapMarkersHelper {
for (MapMarker marker : markers) {
addMarkerToGroup(marker);
}
saveGroups();
}
private void addMarkerToGroup(MapMarker marker) {
@ -468,7 +468,7 @@ public class MapMarkersHelper {
sortMarkers(mapMarkersGroup.getMarkers(), false, BY_DATE_ADDED_DESC);
}
} else {
mapMarkersGroup = new MapMarkersGroup(marker.groupKey, marker.groupName, MapMarkersGroup.ANY_TYPE);
mapMarkersGroup = new MapMarkersGroup(marker.groupKey, marker.groupName, ItineraryType.MARKERS);
mapMarkersGroup.setCreationDate(Long.MAX_VALUE);
mapMarkersGroup.getMarkers().add(marker);
addToGroupsList(mapMarkersGroup);
@ -479,10 +479,10 @@ public class MapMarkersHelper {
}
private void createHeadersInGroup(@NonNull MapMarkersGroup group) {
int type = group.getType();
ItineraryType type = group.getType();
int headerIconId = 0;
if (type != -1) {
headerIconId = type == MapMarkersGroup.FAVORITES_TYPE
if (type != ItineraryType.MARKERS) {
headerIconId = type == ItineraryType.FAVOURITES
? R.drawable.ic_action_favorite : R.drawable.ic_action_polygom_dark;
}
GroupHeader header = new GroupHeader(headerIconId, group);
@ -513,11 +513,11 @@ public class MapMarkersHelper {
}
@Nullable
public MapMarkersGroup getMapMarkerGroupById(String id, int type) {
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 == MapMarkersGroup.ANY_TYPE || type == group.getType()) {
if (type == ItineraryType.MARKERS || type == group.getType()) {
return group;
}
}
@ -528,11 +528,11 @@ public class MapMarkersHelper {
private MapMarkersGroup createGPXMarkerGroup(File fl) {
return new MapMarkersGroup(getMarkerGroupId(fl),
Algorithms.getFileNameWithoutExtension(fl.getName()),
MapMarkersGroup.GPX_TYPE);
ItineraryType.TRACK);
}
private MapMarkersGroup createFavMarkerGroup(FavoriteGroup favGroup) {
return new MapMarkersGroup(favGroup.getName(), favGroup.getName(), MapMarkersGroup.FAVORITES_TYPE);
return new MapMarkersGroup(favGroup.getName(), favGroup.getName(), ItineraryType.FAVOURITES);
}
private String getMarkerGroupId(File gpx) {
@ -546,7 +546,7 @@ public class MapMarkersHelper {
@NonNull
public List<MapMarkersGroup> getGroupsForDisplayedGpx() {
List<MapMarkersGroup> res = new ArrayList<>();
List<SelectedGpxFile> selectedGpxFiles = ctx.getSelectedGpxHelper().getSelectedGPXFiles();
List<SelectedGpxFile> selectedGpxFiles = app.getSelectedGpxHelper().getSelectedGPXFiles();
for (SelectedGpxFile selected : selectedGpxFiles) {
MapMarkersGroup search = getMarkersGroup(selected.getGpxFile());
if (search == null && selected.getGpxFile() != null && selected.getGpxFile().path != null) {
@ -562,13 +562,13 @@ public class MapMarkersHelper {
@NonNull
public List<MapMarkersGroup> getGroupsForSavedArticlesTravelBook() {
List<MapMarkersGroup> res = new ArrayList<>();
TravelHelper travelHelper = ctx.getTravelHelper();
TravelHelper travelHelper = app.getTravelHelper();
if (travelHelper.isAnyTravelBookPresent()) {
List<TravelArticle> savedArticles = travelHelper.getBookmarksHelper().getSavedArticles();
for (TravelArticle art : savedArticles) {
String gpxName = travelHelper.getGPXName(art);
File path = ctx.getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName);
MapMarkersGroup search = getMapMarkerGroupById(getMarkerGroupId(path), MapMarkersGroup.GPX_TYPE);
File path = app.getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName);
MapMarkersGroup search = getMapMarkerGroupById(getMarkerGroupId(path), ItineraryType.TRACK);
if (search == null) {
MapMarkersGroup group = createGPXMarkerGroup(path);
group.setDisabled(true);
@ -612,7 +612,7 @@ public class MapMarkersHelper {
private List<MapMarker> getMarkers() {
List<MapMarker> res = new ArrayList<>(mapMarkers);
if (ctx.getSettings().KEEP_PASSED_MARKERS_ON_MAP.get()) {
if (app.getSettings().KEEP_PASSED_MARKERS_ON_MAP.get()) {
res.addAll(mapMarkersHistory);
}
return res;
@ -642,7 +642,7 @@ public class MapMarkersHelper {
Iterator<MapMarker> iterator = groupMarkers.iterator();
while (iterator.hasNext()) {
MapMarker marker = iterator.next();
if (marker.id.equals(group.getId() + name + MapUtils.createShortLinkString(latLon.getLatitude(), latLon.getLongitude(), 15))) {
if (marker.id.equals(getMarkerId(app, group, marker))) {
exists = true;
marker.favouritePoint = favouritePoint;
marker.wptPt = wptPt;
@ -698,7 +698,9 @@ public class MapMarkersHelper {
public void addMarker(MapMarker marker) {
if (marker != null) {
markersDbHelper.addMarker(marker);
if (marker.groupKey == null) {
markersDbHelper.addMarker(marker);
}
if (marker.history) {
addToMapMarkersHistoryList(marker);
sortMarkers(mapMarkersHistory, true, BY_DATE_ADDED_DESC);
@ -879,7 +881,7 @@ public class MapMarkersHelper {
@Nullable List<WptPt> wptPts,
@Nullable List<String> mapObjNames) {
if (points.size() > 0) {
ctx.getSettings().SHOW_MAP_MARKERS.set(true);
app.getSettings().SHOW_MAP_MARKERS.set(true);
int colorIndex = -1;
List<MapMarker> addedMarkers = new ArrayList<>();
for (int i = 0; i < points.size(); i++) {
@ -895,7 +897,7 @@ public class MapMarkersHelper {
pointDescription = historyName;
}
if (pointDescription.isLocation() && Algorithms.isEmpty(pointDescription.getName())) {
pointDescription.setName(PointDescription.getSearchAddressStr(ctx));
pointDescription.setName(PointDescription.getSearchAddressStr(app));
}
if (colorIndex == -1) {
if (mapMarkers.size() > 0) {
@ -909,7 +911,7 @@ public class MapMarkersHelper {
MapMarker marker = new MapMarker(point, pointDescription, colorIndex, false, 0);
if (group != null) {
marker.id = group.getId() + marker.getName(ctx) + MapUtils.createShortLinkString(marker.point.getLatitude(), marker.point.getLongitude(), 15);
marker.id = getMarkerId(app, group, marker);
if (markersDbHelper.getMarker(marker.id) != null) {
continue;
}
@ -921,7 +923,9 @@ public class MapMarkersHelper {
marker.favouritePoint = favouritePoint;
marker.wptPt = wptPt;
marker.mapObjectName = mapObjName;
markersDbHelper.addMarker(marker);
if (marker.groupKey == null) {
markersDbHelper.addMarker(marker);
}
addToMapMarkersList(0, marker);
addedMarkers.add(marker);
reorderActiveMarkersIfNeeded();
@ -931,6 +935,10 @@ public class MapMarkersHelper {
}
}
public static String getMarkerId(OsmandApplication app, MapMarkersGroup group, MapMarker marker) {
return group.getId() + marker.getName(app) + createShortLinkString(marker.point.getLatitude(), marker.point.getLongitude(), 15);
}
public void updateMapMarker(MapMarker marker, boolean refresh) {
if (marker != null) {
markersDbHelper.updateMarker(marker);
@ -984,7 +992,7 @@ public class MapMarkersHelper {
}
private void refreshMarker(final MapMarker marker) {
ctx.runInUIThread(new Runnable() {
app.runInUIThread(new Runnable() {
@Override
public void run() {
for (MapMarkerChangedListener l : listeners) {
@ -995,7 +1003,7 @@ public class MapMarkersHelper {
}
private void refresh() {
ctx.runInUIThread(new Runnable() {
app.runInUIThread(new Runnable() {
@Override
public void run() {
for (MapMarkerChangedListener l : listeners) {
@ -1003,12 +1011,13 @@ public class MapMarkersHelper {
}
}
});
saveGroups();
}
public List<MapMarker> getMapMarkersFromDefaultGroups(boolean history) {
List<MapMarker> mapMarkers = new ArrayList<>();
for (MapMarkersGroup group : mapMarkersGroups) {
if (group.getType() == MapMarkersGroup.ANY_TYPE) {
if (group.getType() == ItineraryType.MARKERS) {
for (MapMarker marker : group.getMarkers()) {
if (history && marker.history || !history && !marker.history) {
mapMarkers.add(marker);
@ -1019,84 +1028,6 @@ public class MapMarkersHelper {
return mapMarkers;
}
public String saveMarkersToFile(String fileName) {
GPXFile gpxFile = generateGpx();
String dirName = IndexConstants.GPX_INDEX_DIR + IndexConstants.MAP_MARKERS_INDEX_DIR;
File dir = ctx.getAppPath(dirName);
if (!dir.exists()) {
dir.mkdirs();
}
String uniqueFileName = FileUtils.createUniqueFileName(ctx, fileName, dirName, IndexConstants.GPX_FILE_EXT);
File fout = new File(dir, uniqueFileName + IndexConstants.GPX_FILE_EXT);
GPXUtilities.writeGpxFile(fout, gpxFile);
return fout.getAbsolutePath();
}
public GPXFile generateGpx() {
return generateGpx(mapMarkers, false);
}
public GPXFile generateGpx(List<MapMarker> markers, boolean completeBackup) {
SimpleDateFormat format = new SimpleDateFormat(GPX_TIME_FORMAT, Locale.US);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
GPXFile gpxFile = new GPXFile(Version.getFullVersion(ctx));
for (MapMarker marker : markers) {
WptPt wpt = new WptPt();
wpt.lat = marker.getLatitude();
wpt.lon = marker.getLongitude();
wpt.name = marker.getOnlyName();
wpt.setColor(ContextCompat.getColor(ctx, MapMarker.getColorId(marker.colorIndex)));
if (completeBackup) {
if (marker.creationDate != 0) {
wpt.getExtensionsToWrite().put(CREATION_DATE, format.format(new Date(marker.creationDate)));
}
if (marker.visitedDate != 0) {
wpt.getExtensionsToWrite().put(VISITED_DATE, format.format(new Date(marker.visitedDate)));
}
}
gpxFile.addPoint(wpt);
}
return gpxFile;
}
public List<MapMarker> readMarkersFromGpx(GPXFile gpxFile, boolean history) {
SimpleDateFormat format = new SimpleDateFormat(GPX_TIME_FORMAT, Locale.US);
format.setTimeZone(TimeZone.getTimeZone("UTC"));
List<MapMarker> mapMarkers = new ArrayList<>();
for (WptPt point : gpxFile.getPoints()) {
LatLon latLon = new LatLon(point.lat, point.lon);
int colorIndex = MapMarker.getColorIndex(ctx, point.getColor());
PointDescription name = new PointDescription(PointDescription.POINT_TYPE_LOCATION, point.name);
MapMarker marker = new MapMarker(latLon, name, colorIndex, false, 0);
String visitedDateStr = point.getExtensionsToRead().get(VISITED_DATE);
String creationDateStr = point.getExtensionsToRead().get(CREATION_DATE);
marker.visitedDate = parseTime(visitedDateStr, format);
marker.creationDate = parseTime(creationDateStr, format);
marker.history = history;
marker.nextKey = history ? MapMarkersDbHelper.HISTORY_NEXT_VALUE : MapMarkersDbHelper.TAIL_NEXT_VALUE;
mapMarkers.add(marker);
}
return mapMarkers;
}
private static long parseTime(String text, SimpleDateFormat format) {
long time = 0;
if (text != null) {
try {
time = format.parse(text).getTime();
} catch (ParseException e) {
LOG.error(e);
}
}
return time;
}
// ---------------------------------------------------------------------------------------------
// accessors to active markers:
@ -1201,7 +1132,7 @@ public class MapMarkersHelper {
@Override
protected void onPreExecute() {
if (!syncListeners.isEmpty()) {
ctx.runInUIThread(new Runnable() {
app.runInUIThread(new Runnable() {
@Override
public void run() {
for (OnGroupSyncedListener listener : syncListeners) {
@ -1221,8 +1152,8 @@ public class MapMarkersHelper {
// TODO extract method from Asynctask to Helper directly
private void runGroupSynchronization() {
List<MapMarker> groupMarkers = new ArrayList<>(group.getMarkers());
if (group.getType() == MapMarkersGroup.FAVORITES_TYPE) {
FavoriteGroup favGroup = ctx.getFavorites().getGroup(group.getName());
if (group.getType() == ItineraryType.FAVOURITES) {
FavoriteGroup favGroup = app.getFavorites().getGroup(group.getName());
if (favGroup == null) {
return;
}
@ -1235,8 +1166,8 @@ public class MapMarkersHelper {
for (FavouritePoint fp : points) {
addNewMarkerIfNeeded(group, groupMarkers, new LatLon(fp.getLatitude(), fp.getLongitude()), fp.getName(), fp, null);
}
} else if (group.getType() == MapMarkersGroup.GPX_TYPE) {
GpxSelectionHelper gpxHelper = ctx.getSelectedGpxHelper();
} else if (group.getType() == ItineraryType.TRACK) {
GpxSelectionHelper gpxHelper = app.getSelectedGpxHelper();
File file = new File(group.getId());
if (!file.exists()) {
return;
@ -1267,7 +1198,7 @@ public class MapMarkersHelper {
@Override
protected void onPostExecute(Void aVoid) {
if (!syncListeners.isEmpty()) {
ctx.runInUIThread(new Runnable() {
app.runInUIThread(new Runnable() {
@Override
public void run() {
for (OnGroupSyncedListener listener : syncListeners) {

View file

@ -0,0 +1,171 @@
package net.osmand.plus.mapmarkers;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
import net.osmand.util.Algorithms;
import java.util.LinkedHashMap;
import java.util.Map;
import static net.osmand.plus.mapmarkers.MapMarkersDbHelper.MARKERS_COL_ACTIVE;
import static net.osmand.plus.mapmarkers.MapMarkersDbHelper.MARKERS_COL_DISABLED;
import static net.osmand.plus.mapmarkers.MapMarkersDbHelper.MARKERS_COL_GROUP_KEY;
import static net.osmand.plus.mapmarkers.MapMarkersDbHelper.MARKERS_TABLE_NAME;
public class MarkersDbHelperLegacy {
private static final String GROUPS_TABLE_NAME = "map_markers_groups";
private static final String GROUPS_COL_ID = "group_id";
private static final String GROUPS_COL_NAME = "group_name";
private static final String GROUPS_COL_TYPE = "group_type";
private static final String GROUPS_COL_DISABLED = "group_disabled";
private static final String GROUPS_COL_CATEGORIES = "group_categories";
private static final String GROUPS_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " +
GROUPS_TABLE_NAME + " (" +
GROUPS_COL_ID + " TEXT PRIMARY KEY, " +
GROUPS_COL_NAME + " TEXT, " +
GROUPS_COL_TYPE + " int, " +
GROUPS_COL_DISABLED + " int, " + // 1 = true, 0 = false
GROUPS_COL_CATEGORIES + " TEXT);";
private static final String GROUPS_TABLE_SELECT = "SELECT " +
GROUPS_COL_ID + ", " +
GROUPS_COL_NAME + ", " +
GROUPS_COL_TYPE + ", " +
GROUPS_COL_DISABLED + ", " +
GROUPS_COL_CATEGORIES +
" FROM " + GROUPS_TABLE_NAME;
private final OsmandApplication app;
private final MapMarkersDbHelper markersDbHelper;
public MarkersDbHelperLegacy(OsmandApplication app, MapMarkersDbHelper markersDbHelper) {
this.app = app;
this.markersDbHelper = markersDbHelper;
}
public void onCreate(SQLiteConnection db) {
db.execSQL(GROUPS_TABLE_CREATE);
}
public void onUpgrade(SQLiteConnection db, int oldVersion, int newVersion) {
if (oldVersion < 8) {
db.execSQL("ALTER TABLE " + GROUPS_TABLE_NAME + " ADD " + GROUPS_COL_DISABLED + " int");
}
if (oldVersion < 9) {
db.execSQL("UPDATE " + GROUPS_TABLE_NAME +
" SET " + GROUPS_COL_DISABLED + " = ? " +
"WHERE " + GROUPS_COL_DISABLED + " IS NULL", new Object[] {0});
}
if (oldVersion < 13) {
db.execSQL("ALTER TABLE " + GROUPS_TABLE_NAME + " ADD " + GROUPS_COL_CATEGORIES + " TEXT");
}
}
private SQLiteConnection openConnection(boolean readonly) {
return markersDbHelper.openConnection(readonly);
}
public void updateGroupDisabled(String id, boolean disabled) {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
db.execSQL("UPDATE " + GROUPS_TABLE_NAME +
" SET " + GROUPS_COL_DISABLED + " = ? " +
"WHERE " + GROUPS_COL_ID + " = ?", new Object[] {disabled ? 1 : 0, id});
db.execSQL("UPDATE " + MARKERS_TABLE_NAME +
" SET " + MARKERS_COL_DISABLED + " = ? " +
"WHERE " + MARKERS_COL_GROUP_KEY + " = ?", new Object[] {disabled ? 1 : 0, id});
} finally {
db.close();
}
}
}
public void removeDisabledGroups() {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
db.execSQL("DELETE FROM " + GROUPS_TABLE_NAME + " WHERE " + GROUPS_COL_DISABLED + " = ? ", new Object[] {1});
db.execSQL("DELETE FROM " + MARKERS_TABLE_NAME
+ " WHERE " + MARKERS_COL_DISABLED + " = ? AND " + MARKERS_COL_ACTIVE + " = ?", new Object[] {1, 1});
} finally {
db.close();
}
}
}
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().getTypeId(), group.isDisabled(), group.getWptCategoriesString()});
} finally {
db.close();
}
}
}
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 {
MapMarkersGroup group = readGroup(query);
res.put(group.getId(), group);
} while (query.moveToNext());
}
if (query != null) {
query.close();
}
} finally {
db.close();
}
}
return res;
}
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);
MapMarkersGroup res = new MapMarkersGroup(id, name, ItineraryType.findTypeForId(type));
res.setDisabled(disabled);
res.setWptCategories(categories == null ? null : Algorithms.decodeStringSet(categories));
return res;
}
public void removeMarkersGroup(String id) {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
db.execSQL("DELETE FROM " + GROUPS_TABLE_NAME + " WHERE " + GROUPS_COL_ID + " = ?", new Object[] {id});
} finally {
db.close();
}
}
}
public void updateGroupCategories(String id, String categories) {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
db.execSQL("UPDATE " + GROUPS_TABLE_NAME +
" SET " + GROUPS_COL_CATEGORIES + " = ? " +
"WHERE " + GROUPS_COL_ID + " = ?", new Object[] {categories, id});
} finally {
db.close();
}
}
}
}

View file

@ -45,11 +45,11 @@ public class MarkersPlanRouteContext {
private boolean adjustMapOnStart = true;
private boolean navigationFromMarkers;
Map<Pair<WptPt, WptPt>, List<WptPt>> getSnappedToRoadPoints() {
public Map<Pair<WptPt, WptPt>, List<WptPt>> getSnappedToRoadPoints() {
return snappedToRoadPoints;
}
TrkSegment getSnapTrkSegment() {
public TrkSegment getSnapTrkSegment() {
return snapTrkSegment;
}
@ -57,7 +57,7 @@ public class MarkersPlanRouteContext {
return snappedMode;
}
void setSnappedMode(ApplicationMode snappedMode) {
public void setSnappedMode(ApplicationMode snappedMode) {
this.snappedMode = snappedMode;
}
@ -69,11 +69,11 @@ public class MarkersPlanRouteContext {
this.listener = listener;
}
boolean isProgressBarVisible() {
public boolean isProgressBarVisible() {
return progressBarVisible;
}
void setProgressBarVisible(boolean progressBarVisible) {
public void setProgressBarVisible(boolean progressBarVisible) {
this.progressBarVisible = progressBarVisible;
}
@ -113,7 +113,7 @@ public class MarkersPlanRouteContext {
this.app = app;
}
void cancelSnapToRoad() {
public void cancelSnapToRoad() {
listener.hideProgressBar(true);
snapToRoadPairsToCalculate.clear();
if (calculationProgress != null) {
@ -151,7 +151,7 @@ public class MarkersPlanRouteContext {
}
}
void recreateSnapTrkSegment(boolean adjustMap) {
public void recreateSnapTrkSegment(boolean adjustMap) {
snapTrkSegment.points.clear();
List<WptPt> points = getPointsToCalculate();
if (snappedMode == ApplicationMode.DEFAULT) {
@ -281,7 +281,7 @@ public class MarkersPlanRouteContext {
return params;
}
interface PlanRouteProgressListener {
public interface PlanRouteProgressListener {
void showProgressBar();

View file

@ -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.mapmarkers.MapMarkersGroup;
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.mapmarkers.ItineraryType;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.util.Algorithms;
import java.util.Collections;
@ -215,7 +216,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
final MapMarker marker = getItem(pos);
mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker);
MapMarkersGroup group = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkerGroupById(marker.groupKey,
MapMarkersGroup.ANY_TYPE);
ItineraryType.MARKERS);
if (group != null) {
mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group);
}

View file

@ -7,7 +7,6 @@ import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.ImageView;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
@ -25,6 +24,7 @@ import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.mapmarkers.GroupHeader;
import net.osmand.plus.mapmarkers.ItineraryType;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.ShowHideHistoryButton;
@ -34,7 +34,7 @@ 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.SelectWptCategoriesBottomSheetDialogFragment;
import net.osmand.plus.mapmarkers.bottomsheets.SelectWptCategoriesBottomSheetDialogFragment;
import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment;
import net.osmand.plus.wikivoyage.data.TravelArticle;
import net.osmand.plus.wikivoyage.data.TravelHelper;
@ -253,7 +253,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
public int getGroupHeaderPosition(String groupId) {
int pos = -1;
MapMarkersGroup group = app.getMapMarkersHelper().getMapMarkerGroupById(groupId, MapMarkersGroup.ANY_TYPE);
MapMarkersGroup group = app.getMapMarkersHelper().getMapMarkerGroupById(groupId, ItineraryType.MARKERS);
if (group != null) {
pos = items.indexOf(group.getGroupHeader());
}
@ -425,7 +425,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
String groupName = group.getName();
if (groupName.isEmpty()) {
groupName = app.getString(R.string.shared_string_favorites);
} else if (group.getType() == MapMarkersGroup.GPX_TYPE) {
} else if (group.getType() == ItineraryType.TRACK) {
groupName = groupName.replace(IndexConstants.GPX_FILE_EXT, "").replace("/", " ").replace("_", " ");
}
if (group.isDisabled()) {
@ -483,7 +483,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
fragment.show(mapActivity.getSupportFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG);
}
mapMarkersHelper.updateGroupDisabled(group, disabled);
if (group.getType() == MapMarkersGroup.GPX_TYPE) {
if (group.getType() == ItineraryType.TRACK) {
group.setVisibleUntilRestart(disabled);
String gpxPath = group.getGpxPath();
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxPath);
@ -506,7 +506,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() == MapMarkersGroup.GPX_TYPE && gpxFile[0] != null) {
if (group.getType() == ItineraryType.TRACK && gpxFile[0] != null) {
switchGpxVisibility(gpxFile[0], null, true);
}
mapMarkersHelper.enableGroup(group);
@ -616,7 +616,7 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
Object item = items.get(position);
if (item instanceof MapMarker) {
return MARKER_TYPE;
} else if (item instanceof GroupHeader || item instanceof Integer) {
} else if (item instanceof GroupHeader || item instanceof MarkerGroupItem) {
return HEADER_TYPE;
} else if (item instanceof ShowHideHistoryButton) {
return SHOW_HIDE_HISTORY_TYPE;

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.bottomsheets;
import android.os.Bundle;

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.bottomsheets;
import android.app.Dialog;
import android.os.Bundle;

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.bottomsheets;
import android.annotation.SuppressLint;
import android.os.AsyncTask;

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.bottomsheets;
import android.os.Bundle;
import android.view.View;
@ -65,7 +65,7 @@ public class CoordinateInputActionsBottomSheet extends MenuBottomSheetDialogFrag
return R.string.shared_string_cancel;
}
interface CoordinateInputActionsListener {
public interface CoordinateInputActionsListener {
void removeItem(int position);

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.bottomsheets;
import android.content.Context;
import android.content.res.ColorStateList;
@ -162,7 +162,7 @@ public class CoordinateInputBottomSheetDialogFragment extends MenuBottomSheetDia
return R.string.shared_string_close;
}
interface CoordinateInputFormatChangeListener {
public interface CoordinateInputFormatChangeListener {
void onKeyboardChanged();

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.bottomsheets;
import android.os.Bundle;
import android.view.View;
@ -9,6 +9,7 @@ import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.util.Algorithms;
import java.text.SimpleDateFormat;
@ -95,7 +96,7 @@ public class HistoryMarkerMenuBottomSheetDialogFragment extends MenuBottomSheetD
return R.string.shared_string_close;
}
interface HistoryMarkerMenuFragmentListener {
public interface HistoryMarkerMenuFragmentListener {
void onMakeMarkerActive(int pos);

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.bottomsheets;
import android.app.Activity;
import android.os.Build;
@ -17,6 +17,8 @@ import net.osmand.AndroidUtils;
import net.osmand.plus.R;
import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapmarkers.fragments.MapMarkersDialogFragment;
import net.osmand.plus.mapmarkers.MapMarkersMode;
public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment {
@ -220,7 +222,7 @@ public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment
return scrH - stBarH - nBarH - AndroidUtils.dpToPx(activity, 56);
}
interface MarkerOptionsFragmentListener {
public interface MarkerOptionsFragmentListener {
void sortByOnClick();

View file

@ -1,9 +1,10 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.bottomsheets;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.mapmarkers.MapMarkersHelper.MapMarkersSortByDef;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
@ -119,7 +120,7 @@ public class OrderByBottomSheetDialogFragment extends MenuBottomSheetDialogFragm
return R.string.shared_string_close;
}
interface OrderByFragmentListener {
public interface OrderByFragmentListener {
void onMapMarkersOrderByModeChanged(@MapMarkersSortByDef int sortByMode);
}
}

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.bottomsheets;
import android.os.Bundle;
import android.view.View;
@ -125,7 +125,7 @@ public class PlanRouteOptionsBottomSheetDialogFragment extends MenuBottomSheetDi
return R.string.shared_string_close;
}
interface PlanRouteOptionsFragmentListener {
public interface PlanRouteOptionsFragmentListener {
void selectOnClick();

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.bottomsheets;
import android.os.Bundle;
import android.text.format.DateFormat;
@ -31,7 +31,7 @@ import net.osmand.plus.widgets.OsmandTextFieldBoxes;
import java.util.Date;
import static net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.ADDED_POINTS_NUMBER_KEY;
import static net.osmand.plus.mapmarkers.fragments.CoordinateInputDialogFragment.ADDED_POINTS_NUMBER_KEY;
public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragment {
@ -167,7 +167,7 @@ public class SaveAsTrackBottomSheetDialogFragment extends BottomSheetDialogFragm
}
}
interface MarkerSaveAsTrackFragmentListener {
public interface MarkerSaveAsTrackFragmentListener {
void saveGpx(String fileName);
}
}

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.bottomsheets;
import android.os.Bundle;
import android.view.View;
@ -20,6 +20,8 @@ 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.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import java.io.File;
import java.util.ArrayList;

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.bottomsheets;
import android.os.Bundle;
import android.view.View;
@ -64,7 +64,7 @@ public class SelectionMarkersGroupBottomSheetDialogFragment extends MenuBottomSh
return R.string.shared_string_close;
}
interface AddMarkersGroupFragmentListener {
public interface AddMarkersGroupFragmentListener {
void favouritesOnClick();

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.fragments;
import android.app.Activity;
import android.app.Dialog;
@ -71,11 +71,17 @@ 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.mapmarkers.CoordinateInputBottomSheetDialogFragment.CoordinateInputFormatChangeListener;
import net.osmand.plus.mapmarkers.CoordinateInputFormats;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.mapmarkers.bottomsheets.CoordinateInputActionsBottomSheet;
import net.osmand.plus.mapmarkers.bottomsheets.CoordinateInputBottomSheetDialogFragment;
import net.osmand.plus.mapmarkers.bottomsheets.CoordinateInputBottomSheetDialogFragment.CoordinateInputFormatChangeListener;
import net.osmand.plus.mapmarkers.CoordinateInputFormats.DDM;
import net.osmand.plus.mapmarkers.CoordinateInputFormats.DMS;
import net.osmand.plus.mapmarkers.CoordinateInputFormats.Format;
import net.osmand.plus.mapmarkers.adapters.CoordinateInputAdapter;
import net.osmand.plus.mapmarkers.bottomsheets.SaveAsTrackBottomSheetDialogFragment;
import net.osmand.plus.settings.backend.OsmandPreference;
import net.osmand.plus.track.TrackMenuFragment;
import net.osmand.plus.widgets.EditTextEx;

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.fragments;
import android.app.Activity;
import android.content.Context;
@ -30,6 +30,7 @@ import com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCal
import com.github.ksoichiro.android.observablescrollview.ScrollState;
import net.osmand.AndroidUtils;
import net.osmand.plus.mapmarkers.MapMarkersMode;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandPreference;

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.fragments;
import android.content.Context;
import android.graphics.drawable.Drawable;
@ -21,6 +21,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.helpers.MapMarkerDialogHelper;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.OnMarkerSelectListener;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.PointType;

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.fragments;
import android.os.Build;
import android.os.Bundle;
@ -26,6 +26,7 @@ import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter;
import net.osmand.plus.mapmarkers.adapters.MapMarkersActiveAdapter.MapMarkersActiveAdapterListener;
import net.osmand.plus.mapmarkers.adapters.MapMarkersItemTouchHelperCallback;

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.fragments;
import android.app.Dialog;
import android.graphics.drawable.Drawable;
@ -32,13 +32,18 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.OnPointsSavedListener;
import net.osmand.plus.mapmarkers.DirectionIndicationDialogFragment.DirectionIndicationFragmentListener;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.fragments.CoordinateInputDialogFragment.OnPointsSavedListener;
import net.osmand.plus.mapmarkers.fragments.DirectionIndicationDialogFragment.DirectionIndicationFragmentListener;
import net.osmand.plus.mapmarkers.MapMarkersHelper.MapMarkersSortByDef;
import net.osmand.plus.mapmarkers.MapMarkersHelper.OnGroupSyncedListener;
import net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener;
import net.osmand.plus.mapmarkers.OrderByBottomSheetDialogFragment.OrderByFragmentListener;
import net.osmand.plus.mapmarkers.SaveAsTrackBottomSheetDialogFragment.MarkerSaveAsTrackFragmentListener;
import net.osmand.plus.mapmarkers.bottomsheets.OptionsBottomSheetDialogFragment;
import net.osmand.plus.mapmarkers.bottomsheets.OptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener;
import net.osmand.plus.mapmarkers.bottomsheets.OrderByBottomSheetDialogFragment;
import net.osmand.plus.mapmarkers.bottomsheets.OrderByBottomSheetDialogFragment.OrderByFragmentListener;
import net.osmand.plus.mapmarkers.bottomsheets.SaveAsTrackBottomSheetDialogFragment;
import net.osmand.plus.mapmarkers.bottomsheets.SaveAsTrackBottomSheetDialogFragment.MarkerSaveAsTrackFragmentListener;
import net.osmand.plus.track.TrackMenuFragment;
import java.io.File;
@ -46,8 +51,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import static net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.GROUPS_MARKERS_MENU;
import static net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.HISTORY_MARKERS_MENU;
import static net.osmand.plus.mapmarkers.bottomsheets.OptionsBottomSheetDialogFragment.GROUPS_MARKERS_MENU;
import static net.osmand.plus.mapmarkers.bottomsheets.OptionsBottomSheetDialogFragment.HISTORY_MARKERS_MENU;
public class MapMarkersDialogFragment extends DialogFragment implements OnGroupSyncedListener {
@ -481,7 +486,7 @@ public class MapMarkersDialogFragment extends DialogFragment implements OnGroupS
@Override
public void saveGpx(final String fileName) {
final String gpxPath = mapActivity.getMyApplication().getMapMarkersHelper().saveMarkersToFile(fileName);
final String gpxPath = mapActivity.getMyApplication().getMapMarkersHelper().getSaveHelper().saveMarkersToFile(fileName);
snackbar = Snackbar.make(viewPager, String.format(getString(R.string.shared_string_file_is_saved), fileName) + ".", Snackbar.LENGTH_LONG)
.setAction(R.string.shared_string_show, new View.OnClickListener() {
@Override

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.fragments;
import android.graphics.Canvas;
import android.graphics.Paint;
@ -34,7 +34,13 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapmarkers.SelectionMarkersGroupBottomSheetDialogFragment.AddMarkersGroupFragmentListener;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.bottomsheets.AddFavouritesGroupBottomSheetDialogFragment;
import net.osmand.plus.mapmarkers.bottomsheets.AddGroupBottomSheetDialogFragment;
import net.osmand.plus.mapmarkers.bottomsheets.AddTracksGroupBottomSheetDialogFragment;
import net.osmand.plus.mapmarkers.bottomsheets.HistoryMarkerMenuBottomSheetDialogFragment;
import net.osmand.plus.mapmarkers.bottomsheets.SelectionMarkersGroupBottomSheetDialogFragment;
import net.osmand.plus.mapmarkers.bottomsheets.SelectionMarkersGroupBottomSheetDialogFragment.AddMarkersGroupFragmentListener;
import net.osmand.plus.mapmarkers.adapters.MapMarkerItemViewHolder;
import net.osmand.plus.mapmarkers.adapters.MapMarkersGroupsAdapter;
import net.osmand.plus.widgets.EmptyStateRecyclerView;

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.fragments;
import android.graphics.Canvas;
import android.graphics.Paint;
@ -24,12 +24,15 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapmarkers.MapMarkersHelper.MapMarkerChangedListener;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.adapters.MapMarkerHeaderViewHolder;
import net.osmand.plus.mapmarkers.adapters.MapMarkerItemViewHolder;
import net.osmand.plus.mapmarkers.adapters.MapMarkersHistoryAdapter;
import net.osmand.plus.mapmarkers.bottomsheets.HistoryMarkerMenuBottomSheetDialogFragment;
import net.osmand.plus.widgets.EmptyStateRecyclerView;
public class MapMarkersHistoryFragment extends Fragment implements MapMarkersHelper.MapMarkerChangedListener {
public class MapMarkersHistoryFragment extends Fragment implements MapMarkerChangedListener {
private MapMarkersHistoryAdapter adapter;
private OsmandApplication app;

View file

@ -1,4 +1,4 @@
package net.osmand.plus.mapmarkers;
package net.osmand.plus.mapmarkers.fragments;
import android.app.ProgressDialog;
import android.content.Context;
@ -48,7 +48,11 @@ import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapmarkers.PlanRouteOptionsBottomSheetDialogFragment.PlanRouteOptionsFragmentListener;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MarkersPlanRouteContext;
import net.osmand.plus.mapmarkers.bottomsheets.PlanRouteOptionsBottomSheetDialogFragment;
import net.osmand.plus.mapmarkers.bottomsheets.PlanRouteOptionsBottomSheetDialogFragment.PlanRouteOptionsFragmentListener;
import net.osmand.plus.mapmarkers.adapters.MapMarkersItemTouchHelperCallback;
import net.osmand.plus.mapmarkers.adapters.MapMarkersListAdapter;
import net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment;

View file

@ -76,7 +76,7 @@ import net.osmand.plus.base.OsmandExpandableListFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
import net.osmand.plus.helpers.enums.TracksSortByMode;
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment;
import net.osmand.plus.mapmarkers.fragments.CoordinateInputDialogFragment;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.myplaces.MoveGpxFileBottomSheet.OnTrackFileMoveListener;
import net.osmand.plus.osmedit.OsmEditingPlugin;
@ -107,7 +107,6 @@ import static net.osmand.plus.track.TrackMenuFragment.openTrack;
import static net.osmand.util.Algorithms.capitalizeFirstLetter;
import static net.osmand.util.Algorithms.formatDuration;
import static net.osmand.util.Algorithms.objectEquals;
import static net.osmand.util.Algorithms.removeAllFiles;
public class AvailableGPXFragment extends OsmandExpandableListFragment implements
FavoritesFragmentStateHolder, OsmAuthorizationListener, OnTrackFileMoveListener, RenameCallback {

View file

@ -62,7 +62,7 @@ import net.osmand.plus.activities.TrackActivity;
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.mapmarkers.fragments.CoordinateInputDialogFragment;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.myplaces.DeletePointsTask.OnPointsDeleteListener;

View file

@ -71,7 +71,7 @@ import net.osmand.plus.helpers.WaypointDialogHelper;
import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenuFragment;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment;
import net.osmand.plus.mapmarkers.fragments.MapMarkerSelectionFragment;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment.UpdateMapRouteMenuListener;
import net.osmand.plus.profiles.ConfigureAppModesBottomSheetDialogFragment;

View file

@ -10,6 +10,7 @@ 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.ItineraryType;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
@ -125,7 +126,7 @@ public class HistoryMarkersSettingsItem extends CollectionSettingsItem<MapMarker
public MapMarkersGroup getMarkersGroup() {
String name = app.getString(R.string.markers_history);
String groupId = ExportSettingsType.HISTORY_MARKERS.name();
MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, MapMarkersGroup.ANY_TYPE);
MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
markersGroup.setMarkers(items);
return markersGroup;
}
@ -142,7 +143,7 @@ public class HistoryMarkersSettingsItem extends CollectionSettingsItem<MapMarker
warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType())));
SettingsHelper.LOG.error("Failed read gpx file", gpxFile.error);
} else {
List<MapMarker> mapMarkers = markersHelper.readMarkersFromGpx(gpxFile, true);
List<MapMarker> mapMarkers = markersHelper.getSaveHelper().readMarkersFromGpx(gpxFile, true);
items.addAll(mapMarkers);
}
}
@ -152,7 +153,7 @@ public class HistoryMarkersSettingsItem extends CollectionSettingsItem<MapMarker
@Nullable
@Override
SettingsItemWriter<? extends SettingsItem> getWriter() {
GPXFile gpxFile = markersHelper.generateGpx(items, true);
GPXFile gpxFile = markersHelper.getSaveHelper().generateGpx(items, true);
return getGpxWriter(gpxFile);
}
}

View file

@ -10,6 +10,7 @@ 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.ItineraryType;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
@ -125,7 +126,7 @@ public class MarkersSettingsItem extends CollectionSettingsItem<MapMarker> {
public MapMarkersGroup getMarkersGroup() {
String name = app.getString(R.string.map_markers);
String groupId = ExportSettingsType.ACTIVE_MARKERS.name();
MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, MapMarkersGroup.ANY_TYPE);
MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
markersGroup.setMarkers(items);
return markersGroup;
}
@ -142,7 +143,7 @@ public class MarkersSettingsItem extends CollectionSettingsItem<MapMarker> {
warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType())));
SettingsHelper.LOG.error("Failed read gpx file", gpxFile.error);
} else {
List<MapMarker> mapMarkers = markersHelper.readMarkersFromGpx(gpxFile, false);
List<MapMarker> mapMarkers = markersHelper.getSaveHelper().readMarkersFromGpx(gpxFile, false);
items.addAll(mapMarkers);
}
}
@ -152,7 +153,7 @@ public class MarkersSettingsItem extends CollectionSettingsItem<MapMarker> {
@Nullable
@Override
SettingsItemWriter<? extends SettingsItem> getWriter() {
GPXFile gpxFile = markersHelper.generateGpx(items, true);
GPXFile gpxFile = markersHelper.getSaveHelper().generateGpx(items, true);
return getGpxWriter(gpxFile);
}
}

View file

@ -30,11 +30,11 @@ import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
import net.osmand.plus.helpers.LocaleHelper;
import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.ItineraryType;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine;
import net.osmand.plus.osmedit.OpenstreetmapPoint;
import net.osmand.plus.osmedit.OsmEditingPlugin;
@ -610,7 +610,7 @@ public class SettingsHelper {
if (!mapMarkers.isEmpty()) {
String name = app.getString(R.string.map_markers);
String groupId = ExportSettingsType.ACTIVE_MARKERS.name();
MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, MapMarkersGroup.ANY_TYPE);
MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
markersGroup.setMarkers(mapMarkers);
myPlacesItems.put(ExportSettingsType.ACTIVE_MARKERS, Collections.singletonList(markersGroup));
}
@ -618,7 +618,7 @@ public class SettingsHelper {
if (!markersHistory.isEmpty()) {
String name = app.getString(R.string.shared_string_history);
String groupId = ExportSettingsType.HISTORY_MARKERS.name();
MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, MapMarkersGroup.ANY_TYPE);
MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
markersGroup.setMarkers(markersHistory);
myPlacesItems.put(ExportSettingsType.HISTORY_MARKERS, Collections.singletonList(markersGroup));
}

View file

@ -14,7 +14,7 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
import net.osmand.plus.mapmarkers.fragments.MapMarkersDialogFragment;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.DirectionDrawable;

View file

@ -20,7 +20,7 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.mapmarkers.DirectionIndicationDialogFragment;
import net.osmand.plus.mapmarkers.fragments.DirectionIndicationDialogFragment;
import net.osmand.plus.quickaction.QuickActionListFragment;
import net.osmand.plus.views.layers.MapInfoLayer;
import net.osmand.plus.views.layers.MapQuickActionLayer;