Export markers and markers history to separate files
This commit is contained in:
parent
e0b967c23b
commit
24a3d8fd53
16 changed files with 389 additions and 204 deletions
|
@ -11,6 +11,7 @@
|
||||||
Thx - Hardy
|
Thx - Hardy
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
<string name="markers_history">Markers history</string>
|
||||||
<string name="subscription_on_hold_title">OsmAnd Live subscription is on hold</string>
|
<string name="subscription_on_hold_title">OsmAnd Live subscription is on hold</string>
|
||||||
<string name="subscription_paused_title">OsmAnd Live subscription has been paused</string>
|
<string name="subscription_paused_title">OsmAnd Live subscription has been paused</string>
|
||||||
<string name="subscription_expired_title">OsmAnd Live subscription has been expired</string>
|
<string name="subscription_expired_title">OsmAnd Live subscription has been expired</string>
|
||||||
|
|
|
@ -2,9 +2,10 @@ package net.osmand.plus.mapmarkers;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.annotation.ColorInt;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import net.osmand.GPXUtilities;
|
import net.osmand.GPXUtilities.WptPt;
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.LocationPoint;
|
import net.osmand.data.LocationPoint;
|
||||||
|
@ -15,6 +16,7 @@ import net.osmand.util.Algorithms;
|
||||||
import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER;
|
import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER;
|
||||||
|
|
||||||
public class MapMarker implements LocationPoint {
|
public class MapMarker implements LocationPoint {
|
||||||
|
|
||||||
private static int[] colors;
|
private static int[] colors;
|
||||||
|
|
||||||
public String id;
|
public String id;
|
||||||
|
@ -30,7 +32,7 @@ public class MapMarker implements LocationPoint {
|
||||||
public String nextKey;
|
public String nextKey;
|
||||||
public String groupKey;
|
public String groupKey;
|
||||||
public String groupName;
|
public String groupName;
|
||||||
public GPXUtilities.WptPt wptPt;
|
public WptPt wptPt;
|
||||||
public FavouritePoint favouritePoint;
|
public FavouritePoint favouritePoint;
|
||||||
public String mapObjectName;
|
public String mapObjectName;
|
||||||
|
|
||||||
|
@ -134,4 +136,14 @@ public class MapMarker implements LocationPoint {
|
||||||
public static int getColorId(int colorIndex) {
|
public static int getColorId(int colorIndex) {
|
||||||
return (colorIndex >= 0 && colorIndex < colorsIds.length) ? colorsIds[colorIndex] : colorsIds[0];
|
return (colorIndex >= 0 && colorIndex < colorsIds.length) ? colorsIds[colorIndex] : colorsIds[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getColorIndex(Context context, @ColorInt int color) {
|
||||||
|
int[] colors = getColors(context);
|
||||||
|
for (int i = 0; i < colors.length; i++) {
|
||||||
|
if (color == colors[i]) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,11 +59,8 @@ public class MapMarkersHelper {
|
||||||
|
|
||||||
public static final int BY_DATE_ADDED_ASC = 4;
|
public static final int BY_DATE_ADDED_ASC = 4;
|
||||||
|
|
||||||
public static final String GROUP_NAME = "group_name";
|
|
||||||
public static final String GROUP_TYPE = "group_type";
|
|
||||||
public static final String MARKER_HISTORY = "marker_history";
|
|
||||||
public static final String CREATION_DATE = "creation_date";
|
|
||||||
public static final String VISITED_DATE = "visited_date";
|
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);
|
private static final Log LOG = PlatformUtil.getLog(MapMarkersHelper.class);
|
||||||
|
|
||||||
|
@ -1035,18 +1032,38 @@ public class MapMarkersHelper {
|
||||||
wpt.name = marker.getOnlyName();
|
wpt.name = marker.getOnlyName();
|
||||||
wpt.setColor(ContextCompat.getColor(ctx, MapMarker.getColorId(marker.colorIndex)));
|
wpt.setColor(ContextCompat.getColor(ctx, MapMarker.getColorId(marker.colorIndex)));
|
||||||
if (completeBackup) {
|
if (completeBackup) {
|
||||||
wpt.category = marker.groupKey;
|
if (marker.creationDate != 0) {
|
||||||
wpt.getExtensionsToWrite().put(GROUP_NAME, marker.groupName);
|
|
||||||
wpt.getExtensionsToWrite().put(GROUP_TYPE, String.valueOf(marker.getType()));
|
|
||||||
wpt.getExtensionsToWrite().put(MARKER_HISTORY, String.valueOf(marker.history));
|
|
||||||
wpt.getExtensionsToWrite().put(CREATION_DATE, String.valueOf(marker.creationDate));
|
wpt.getExtensionsToWrite().put(CREATION_DATE, String.valueOf(marker.creationDate));
|
||||||
|
}
|
||||||
|
if (marker.visitedDate != 0) {
|
||||||
wpt.getExtensionsToWrite().put(VISITED_DATE, String.valueOf(marker.visitedDate));
|
wpt.getExtensionsToWrite().put(VISITED_DATE, String.valueOf(marker.visitedDate));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
gpxFile.addPoint(wpt);
|
gpxFile.addPoint(wpt);
|
||||||
}
|
}
|
||||||
return gpxFile;
|
return gpxFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<MapMarker> readMarkersFromGpx(GPXFile gpxFile, boolean history) {
|
||||||
|
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 = Algorithms.parseLongSilently(visitedDateStr, 0);
|
||||||
|
marker.creationDate = Algorithms.parseLongSilently(creationDateStr, 0);
|
||||||
|
marker.nextKey = history ? MapMarkersDbHelper.HISTORY_NEXT_VALUE : MapMarkersDbHelper.TAIL_NEXT_VALUE;
|
||||||
|
|
||||||
|
mapMarkers.add(marker);
|
||||||
|
}
|
||||||
|
return mapMarkers;
|
||||||
|
}
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// accessors to active markers:
|
// accessors to active markers:
|
||||||
|
|
|
@ -17,5 +17,6 @@ public enum ExportSettingsType {
|
||||||
FAVORITES,
|
FAVORITES,
|
||||||
TTS_VOICE,
|
TTS_VOICE,
|
||||||
VOICE,
|
VOICE,
|
||||||
MARKERS
|
ACTIVE_MARKERS,
|
||||||
|
HISTORY_MARKERS
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,7 @@ import net.osmand.plus.R;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -69,11 +66,6 @@ public class FavoritesSettingsItem extends CollectionSettingsItem<FavoriteGroup>
|
||||||
return ctx.getString(R.string.shared_string_favorites);
|
return ctx.getString(R.string.shared_string_favorites);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public String getDefaultFileName() {
|
|
||||||
return getName() + getDefaultFileExtension();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public String getDefaultFileExtension() {
|
public String getDefaultFileExtension() {
|
||||||
return GPX_FILE_EXT;
|
return GPX_FILE_EXT;
|
||||||
|
@ -177,21 +169,9 @@ public class FavoritesSettingsItem extends CollectionSettingsItem<FavoriteGroup>
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
SettingsItemWriter<FavoritesSettingsItem> getWriter() {
|
SettingsItemWriter<? extends SettingsItem> getWriter() {
|
||||||
return new SettingsItemWriter<FavoritesSettingsItem>(this) {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean writeToStream(@NonNull OutputStream outputStream) throws IOException {
|
|
||||||
List<FavouritePoint> favourites = getPointsFromGroups(items);
|
List<FavouritePoint> favourites = getPointsFromGroups(items);
|
||||||
GPXFile gpxFile = favoritesHelper.asGpxFile(favourites);
|
GPXFile gpxFile = favoritesHelper.asGpxFile(favourites);
|
||||||
Exception error = GPXUtilities.writeGpx(new OutputStreamWriter(outputStream, "UTF-8"), gpxFile);
|
return getGpxWriter(gpxFile);
|
||||||
if (error != null) {
|
|
||||||
warnings.add(app.getString(R.string.settings_item_write_error, String.valueOf(getType())));
|
|
||||||
SettingsHelper.LOG.error("Failed write to gpx file", error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -0,0 +1,160 @@
|
||||||
|
package net.osmand.plus.settings.backend.backup;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import net.osmand.GPXUtilities;
|
||||||
|
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.MapMarker;
|
||||||
|
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
|
||||||
|
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||||
|
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
||||||
|
import net.osmand.plus.settings.backend.ExportSettingsType;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static net.osmand.IndexConstants.GPX_FILE_EXT;
|
||||||
|
|
||||||
|
public class HistoryMarkersSettingsItem extends CollectionSettingsItem<MapMarker> {
|
||||||
|
|
||||||
|
private MapMarkersHelper markersHelper;
|
||||||
|
|
||||||
|
public HistoryMarkersSettingsItem(@NonNull OsmandApplication app, @NonNull List<MapMarker> items) {
|
||||||
|
super(app, null, items);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HistoryMarkersSettingsItem(@NonNull OsmandApplication app, @Nullable HistoryMarkersSettingsItem baseItem, @NonNull List<MapMarker> items) {
|
||||||
|
super(app, baseItem, items);
|
||||||
|
}
|
||||||
|
|
||||||
|
HistoryMarkersSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException {
|
||||||
|
super(app, json);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init() {
|
||||||
|
super.init();
|
||||||
|
markersHelper = app.getMapMarkersHelper();
|
||||||
|
existingItems = new ArrayList<>(markersHelper.getMapMarkersHistory());
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public SettingsItemType getType() {
|
||||||
|
return SettingsItemType.HISTORY_MARKERS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return "history_markers";
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public String getPublicName(@NonNull Context ctx) {
|
||||||
|
return ctx.getString(R.string.markers_history);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
public String getDefaultFileExtension() {
|
||||||
|
return GPX_FILE_EXT;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply() {
|
||||||
|
List<MapMarker> newItems = getNewItems();
|
||||||
|
if (!newItems.isEmpty() || !duplicateItems.isEmpty()) {
|
||||||
|
appliedItems = new ArrayList<>(newItems);
|
||||||
|
|
||||||
|
for (MapMarker duplicate : duplicateItems) {
|
||||||
|
if (shouldReplace) {
|
||||||
|
MapMarker existingMarker = markersHelper.getMapMarker(duplicate.point);
|
||||||
|
markersHelper.removeMarker(existingMarker);
|
||||||
|
}
|
||||||
|
appliedItems.add(shouldReplace ? duplicate : renameItem(duplicate));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (MapMarker marker : appliedItems) {
|
||||||
|
markersHelper.moveMapMarkerToHistory(marker);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDuplicate(@NonNull MapMarker mapMarker) {
|
||||||
|
for (MapMarker marker : existingItems) {
|
||||||
|
if (marker.equals(mapMarker)
|
||||||
|
&& Algorithms.objectEquals(marker.getOriginalPointDescription(), mapMarker.getOriginalPointDescription())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldReadOnCollecting() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public MapMarker renameItem(@NonNull MapMarker item) {
|
||||||
|
int number = 0;
|
||||||
|
while (true) {
|
||||||
|
number++;
|
||||||
|
String name = item.getOnlyName() + "_" + number;
|
||||||
|
PointDescription description = new PointDescription(PointDescription.POINT_TYPE_LOCATION, name);
|
||||||
|
MapMarker renamedMarker = new MapMarker(item.point, description, item.getColor(), item.selected, item.index);
|
||||||
|
if (!isDuplicate(renamedMarker)) {
|
||||||
|
renamedMarker.nextKey = MapMarkersDbHelper.HISTORY_NEXT_VALUE;
|
||||||
|
return renamedMarker;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
markersGroup.setMarkers(items);
|
||||||
|
return markersGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
SettingsItemReader<HistoryMarkersSettingsItem> getReader() {
|
||||||
|
return new SettingsItemReader<HistoryMarkersSettingsItem>(this) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFromStream(@NonNull InputStream inputStream, String entryName) throws IllegalArgumentException {
|
||||||
|
GPXFile gpxFile = GPXUtilities.loadGPXFile(inputStream);
|
||||||
|
if (gpxFile.error != null) {
|
||||||
|
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);
|
||||||
|
items.addAll(mapMarkers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
SettingsItemWriter<? extends SettingsItem> getWriter() {
|
||||||
|
GPXFile gpxFile = markersHelper.generateGpx(items, true);
|
||||||
|
return getGpxWriter(gpxFile);
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,8 +7,6 @@ import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import net.osmand.GPXUtilities;
|
import net.osmand.GPXUtilities;
|
||||||
import net.osmand.GPXUtilities.GPXFile;
|
import net.osmand.GPXUtilities.GPXFile;
|
||||||
import net.osmand.GPXUtilities.WptPt;
|
|
||||||
import net.osmand.data.LatLon;
|
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
|
@ -16,37 +14,27 @@ import net.osmand.plus.mapmarkers.MapMarker;
|
||||||
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
|
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
|
||||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||||
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
import net.osmand.plus.mapmarkers.MapMarkersHelper;
|
||||||
|
import net.osmand.plus.settings.backend.ExportSettingsType;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.io.OutputStreamWriter;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import static net.osmand.IndexConstants.GPX_FILE_EXT;
|
import static net.osmand.IndexConstants.GPX_FILE_EXT;
|
||||||
import static net.osmand.plus.mapmarkers.MapMarkersHelper.CREATION_DATE;
|
|
||||||
import static net.osmand.plus.mapmarkers.MapMarkersHelper.GROUP_NAME;
|
|
||||||
import static net.osmand.plus.mapmarkers.MapMarkersHelper.GROUP_TYPE;
|
|
||||||
import static net.osmand.plus.mapmarkers.MapMarkersHelper.MARKER_HISTORY;
|
|
||||||
import static net.osmand.plus.mapmarkers.MapMarkersHelper.VISITED_DATE;
|
|
||||||
|
|
||||||
public class MarkersSettingsItem extends CollectionSettingsItem<MapMarkersGroup> {
|
public class MarkersSettingsItem extends CollectionSettingsItem<MapMarker> {
|
||||||
|
|
||||||
private MapMarkersHelper markersHelper;
|
private MapMarkersHelper markersHelper;
|
||||||
private Map<String, MapMarkersGroup> flatGroups = new LinkedHashMap<>();
|
|
||||||
|
|
||||||
public MarkersSettingsItem(@NonNull OsmandApplication app, @NonNull List<MapMarkersGroup> items) {
|
public MarkersSettingsItem(@NonNull OsmandApplication app, @NonNull List<MapMarker> items) {
|
||||||
super(app, null, items);
|
super(app, null, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MarkersSettingsItem(@NonNull OsmandApplication app, @Nullable MarkersSettingsItem baseItem, @NonNull List<MapMarkersGroup> items) {
|
public MarkersSettingsItem(@NonNull OsmandApplication app, @Nullable MarkersSettingsItem baseItem, @NonNull List<MapMarker> items) {
|
||||||
super(app, baseItem, items);
|
super(app, baseItem, items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,13 +46,13 @@ public class MarkersSettingsItem extends CollectionSettingsItem<MapMarkersGroup>
|
||||||
protected void init() {
|
protected void init() {
|
||||||
super.init();
|
super.init();
|
||||||
markersHelper = app.getMapMarkersHelper();
|
markersHelper = app.getMapMarkersHelper();
|
||||||
existingItems = new ArrayList<>(markersHelper.getMapMarkersGroups());
|
existingItems = new ArrayList<>(markersHelper.getMapMarkers());
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public SettingsItemType getType() {
|
public SettingsItemType getType() {
|
||||||
return SettingsItemType.MARKERS;
|
return SettingsItemType.ACTIVE_MARKERS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
|
@ -79,11 +67,6 @@ public class MarkersSettingsItem extends CollectionSettingsItem<MapMarkersGroup>
|
||||||
return ctx.getString(R.string.map_markers);
|
return ctx.getString(R.string.map_markers);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public String getDefaultFileName() {
|
|
||||||
return getName() + getDefaultFileExtension();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public String getDefaultFileExtension() {
|
public String getDefaultFileExtension() {
|
||||||
return GPX_FILE_EXT;
|
return GPX_FILE_EXT;
|
||||||
|
@ -91,37 +74,29 @@ public class MarkersSettingsItem extends CollectionSettingsItem<MapMarkersGroup>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply() {
|
public void apply() {
|
||||||
List<MapMarkersGroup> newItems = getNewItems();
|
List<MapMarker> newItems = getNewItems();
|
||||||
if (!newItems.isEmpty() || !duplicateItems.isEmpty()) {
|
if (!newItems.isEmpty() || !duplicateItems.isEmpty()) {
|
||||||
appliedItems = new ArrayList<>(newItems);
|
appliedItems = new ArrayList<>(newItems);
|
||||||
|
|
||||||
for (MapMarkersGroup duplicate : duplicateItems) {
|
for (MapMarker duplicate : duplicateItems) {
|
||||||
if (shouldReplace) {
|
if (shouldReplace) {
|
||||||
MapMarkersGroup existingGroup = markersHelper.getMapMarkerGroupById(duplicate.getId(), duplicate.getType());
|
MapMarker existingMarker = markersHelper.getMapMarker(duplicate.point);
|
||||||
if (existingGroup != null) {
|
markersHelper.removeMarker(existingMarker);
|
||||||
List<MapMarker> existingMarkers = new ArrayList<>(existingGroup.getMarkers());
|
|
||||||
for (MapMarker marker : existingMarkers) {
|
|
||||||
markersHelper.removeMarker(marker);
|
|
||||||
}
|
}
|
||||||
|
appliedItems.add(shouldReplace ? duplicate : renameItem(duplicate));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
appliedItems.add(duplicate);
|
for (MapMarker marker : appliedItems) {
|
||||||
}
|
|
||||||
for (MapMarkersGroup markersGroup : appliedItems) {
|
|
||||||
for (MapMarker marker : markersGroup.getMarkers()) {
|
|
||||||
markersHelper.addMarker(marker);
|
markersHelper.addMarker(marker);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDuplicate(@NonNull MapMarkersGroup markersGroup) {
|
public boolean isDuplicate(@NonNull MapMarker mapMarker) {
|
||||||
String name = markersGroup.getName();
|
for (MapMarker marker : existingItems) {
|
||||||
for (MapMarkersGroup group : existingItems) {
|
if (marker.equals(mapMarker)
|
||||||
if (Algorithms.stringsEqual(group.getName(), name)
|
&& Algorithms.objectEquals(marker.getOriginalPointDescription(), mapMarker.getOriginalPointDescription())) {
|
||||||
&& !Algorithms.isEmpty(group.getMarkers())
|
|
||||||
&& !Algorithms.isEmpty(markersGroup.getMarkers())) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,8 +110,26 @@ public class MarkersSettingsItem extends CollectionSettingsItem<MapMarkersGroup>
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public MapMarkersGroup renameItem(@NonNull MapMarkersGroup item) {
|
public MapMarker renameItem(@NonNull MapMarker item) {
|
||||||
return item;
|
int number = 0;
|
||||||
|
while (true) {
|
||||||
|
number++;
|
||||||
|
String name = item.getOnlyName() + "_" + number;
|
||||||
|
PointDescription description = new PointDescription(PointDescription.POINT_TYPE_LOCATION, name);
|
||||||
|
MapMarker renamedMarker = new MapMarker(item.point, description, item.getColor(), item.selected, item.index);
|
||||||
|
if (!isDuplicate(renamedMarker)) {
|
||||||
|
renamedMarker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE;
|
||||||
|
return renamedMarker;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
markersGroup.setMarkers(items);
|
||||||
|
return markersGroup;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -151,88 +144,17 @@ public class MarkersSettingsItem extends CollectionSettingsItem<MapMarkersGroup>
|
||||||
warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType())));
|
warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType())));
|
||||||
SettingsHelper.LOG.error("Failed read gpx file", gpxFile.error);
|
SettingsHelper.LOG.error("Failed read gpx file", gpxFile.error);
|
||||||
} else {
|
} else {
|
||||||
List<Integer> markerColors = getMarkersColors();
|
List<MapMarker> mapMarkers = markersHelper.readMarkersFromGpx(gpxFile, false);
|
||||||
for (WptPt point : gpxFile.getPoints()) {
|
items.addAll(mapMarkers);
|
||||||
LatLon latLon = new LatLon(point.lat, point.lon);
|
|
||||||
|
|
||||||
int colorIndex = markerColors.indexOf(point.getColor());
|
|
||||||
if (colorIndex == -1) {
|
|
||||||
colorIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_LOCATION, point.name);
|
|
||||||
MapMarker marker = new MapMarker(latLon, pointDescription, colorIndex, false, 0);
|
|
||||||
|
|
||||||
String historyStr = point.getExtensionsToRead().get(MARKER_HISTORY);
|
|
||||||
String creationDateStr = point.getExtensionsToRead().get(CREATION_DATE);
|
|
||||||
String visitedDateStr = point.getExtensionsToRead().get(VISITED_DATE);
|
|
||||||
marker.creationDate = Algorithms.parseLongSilently(creationDateStr, 0);
|
|
||||||
marker.visitedDate = Algorithms.parseLongSilently(visitedDateStr, 0);
|
|
||||||
marker.history = Boolean.parseBoolean(historyStr);
|
|
||||||
marker.nextKey = MapMarkersDbHelper.TAIL_NEXT_VALUE;
|
|
||||||
|
|
||||||
MapMarkersGroup group = getOrCreateGroup(point);
|
|
||||||
group.getMarkers().add(marker);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private MapMarkersGroup getOrCreateGroup(WptPt point) {
|
|
||||||
MapMarkersGroup markersGroup = flatGroups.get(point.category);
|
|
||||||
if (markersGroup != null) {
|
|
||||||
return markersGroup;
|
|
||||||
}
|
|
||||||
Map<String, String> extensions = point.getExtensionsToRead();
|
|
||||||
String groupName = extensions.get(GROUP_NAME);
|
|
||||||
String groupType = extensions.get(GROUP_TYPE);
|
|
||||||
int type = Algorithms.parseIntSilently(groupType, MapMarkersGroup.ANY_TYPE);
|
|
||||||
|
|
||||||
if (point.category != null && groupName != null) {
|
|
||||||
markersGroup = new MapMarkersGroup(point.category, groupName, type);
|
|
||||||
} else {
|
|
||||||
markersGroup = new MapMarkersGroup();
|
|
||||||
}
|
|
||||||
flatGroups.put(markersGroup.getId(), markersGroup);
|
|
||||||
items.add(markersGroup);
|
|
||||||
|
|
||||||
return markersGroup;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<Integer> getMarkersColors() {
|
|
||||||
List<Integer> colors = new ArrayList<>();
|
|
||||||
for (int color : MapMarker.getColors(app)) {
|
|
||||||
colors.add(color);
|
|
||||||
}
|
|
||||||
return colors;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
SettingsItemWriter<MarkersSettingsItem> getWriter() {
|
SettingsItemWriter<? extends SettingsItem> getWriter() {
|
||||||
return new SettingsItemWriter<MarkersSettingsItem>(this) {
|
GPXFile gpxFile = markersHelper.generateGpx(items, true);
|
||||||
|
return getGpxWriter(gpxFile);
|
||||||
@Override
|
|
||||||
public boolean writeToStream(@NonNull OutputStream outputStream) throws IOException {
|
|
||||||
List<MapMarker> mapMarkers = getMarkersFromGroups(items);
|
|
||||||
GPXFile gpxFile = markersHelper.generateGpx(mapMarkers, true);
|
|
||||||
Exception error = GPXUtilities.writeGpx(new OutputStreamWriter(outputStream, "UTF-8"), gpxFile);
|
|
||||||
if (error != null) {
|
|
||||||
warnings.add(app.getString(R.string.settings_item_write_error, String.valueOf(getType())));
|
|
||||||
SettingsHelper.LOG.error("Failed write to gpx file", error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<MapMarker> getMarkersFromGroups(List<MapMarkersGroup> markersGroups) {
|
|
||||||
List<MapMarker> mapMarkers = new ArrayList<>();
|
|
||||||
for (MapMarkersGroup group : markersGroups) {
|
|
||||||
mapMarkers.addAll(group.getMarkers());
|
|
||||||
}
|
|
||||||
return mapMarkers;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,9 +16,9 @@ import net.osmand.map.ITileSource;
|
||||||
import net.osmand.map.TileSourceManager;
|
import net.osmand.map.TileSourceManager;
|
||||||
import net.osmand.map.TileSourceManager.TileSourceTemplate;
|
import net.osmand.map.TileSourceManager.TileSourceTemplate;
|
||||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.OsmandPlugin;
|
import net.osmand.plus.OsmandPlugin;
|
||||||
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.SQLiteTileSource;
|
import net.osmand.plus.SQLiteTileSource;
|
||||||
import net.osmand.plus.activities.LocalIndexHelper;
|
import net.osmand.plus.activities.LocalIndexHelper;
|
||||||
import net.osmand.plus.activities.LocalIndexInfo;
|
import net.osmand.plus.activities.LocalIndexInfo;
|
||||||
|
@ -29,6 +29,8 @@ import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
|
||||||
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||||
import net.osmand.plus.helpers.GpxUiHelper;
|
import net.osmand.plus.helpers.GpxUiHelper;
|
||||||
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
|
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
|
||||||
|
import net.osmand.plus.mapmarkers.MapMarker;
|
||||||
|
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||||
import net.osmand.plus.osmedit.OpenstreetmapPoint;
|
import net.osmand.plus.osmedit.OpenstreetmapPoint;
|
||||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||||
import net.osmand.plus.osmedit.OsmNotesPoint;
|
import net.osmand.plus.osmedit.OsmNotesPoint;
|
||||||
|
@ -595,9 +597,21 @@ public class SettingsHelper {
|
||||||
if (!files.isEmpty()) {
|
if (!files.isEmpty()) {
|
||||||
dataList.put(ExportSettingsType.VOICE, files);
|
dataList.put(ExportSettingsType.VOICE, files);
|
||||||
}
|
}
|
||||||
List<MapMarkersGroup> markersGroups = app.getMapMarkersHelper().getMapMarkersGroups();
|
List<MapMarker> mapMarkers = app.getMapMarkersHelper().getMapMarkers();
|
||||||
if (!markersGroups.isEmpty()) {
|
if (!mapMarkers.isEmpty()) {
|
||||||
dataList.put(ExportSettingsType.MARKERS, markersGroups);
|
String name = app.getString(R.string.map_markers);
|
||||||
|
String groupId = ExportSettingsType.ACTIVE_MARKERS.name();
|
||||||
|
MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, MapMarkersGroup.ANY_TYPE);
|
||||||
|
markersGroup.setMarkers(mapMarkers);
|
||||||
|
dataList.put(ExportSettingsType.ACTIVE_MARKERS, Collections.singletonList(markersGroup));
|
||||||
|
}
|
||||||
|
List<MapMarker> markersHistory = app.getMapMarkersHelper().getMapMarkersHistory();
|
||||||
|
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);
|
||||||
|
markersGroup.setMarkers(markersHistory);
|
||||||
|
dataList.put(ExportSettingsType.HISTORY_MARKERS, Collections.singletonList(markersGroup));
|
||||||
}
|
}
|
||||||
return dataList;
|
return dataList;
|
||||||
}
|
}
|
||||||
|
@ -639,6 +653,7 @@ public class SettingsHelper {
|
||||||
List<OsmNotesPoint> osmNotesPointList = new ArrayList<>();
|
List<OsmNotesPoint> osmNotesPointList = new ArrayList<>();
|
||||||
List<OpenstreetmapPoint> osmEditsPointList = new ArrayList<>();
|
List<OpenstreetmapPoint> osmEditsPointList = new ArrayList<>();
|
||||||
List<MapMarkersGroup> markersGroups = new ArrayList<>();
|
List<MapMarkersGroup> markersGroups = new ArrayList<>();
|
||||||
|
List<MapMarkersGroup> markersHistoryGroups = new ArrayList<>();
|
||||||
|
|
||||||
for (Object object : data) {
|
for (Object object : data) {
|
||||||
if (object instanceof QuickAction) {
|
if (object instanceof QuickAction) {
|
||||||
|
@ -664,7 +679,12 @@ public class SettingsHelper {
|
||||||
} else if (object instanceof FavoriteGroup) {
|
} else if (object instanceof FavoriteGroup) {
|
||||||
favoriteGroups.add((FavoriteGroup) object);
|
favoriteGroups.add((FavoriteGroup) object);
|
||||||
} else if (object instanceof MapMarkersGroup) {
|
} else if (object instanceof MapMarkersGroup) {
|
||||||
|
MapMarkersGroup markersGroup = (MapMarkersGroup) object;
|
||||||
|
if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) {
|
||||||
markersGroups.add((MapMarkersGroup) object);
|
markersGroups.add((MapMarkersGroup) object);
|
||||||
|
} else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) {
|
||||||
|
markersHistoryGroups.add((MapMarkersGroup) object);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!quickActions.isEmpty()) {
|
if (!quickActions.isEmpty()) {
|
||||||
|
@ -697,7 +717,18 @@ public class SettingsHelper {
|
||||||
settingsItems.add(new FavoritesSettingsItem(app, favoriteGroups));
|
settingsItems.add(new FavoritesSettingsItem(app, favoriteGroups));
|
||||||
}
|
}
|
||||||
if (!markersGroups.isEmpty()) {
|
if (!markersGroups.isEmpty()) {
|
||||||
settingsItems.add(new MarkersSettingsItem(app, markersGroups));
|
List<MapMarker> mapMarkers = new ArrayList<>();
|
||||||
|
for (MapMarkersGroup group : markersGroups) {
|
||||||
|
mapMarkers.addAll(group.getMarkers());
|
||||||
|
}
|
||||||
|
settingsItems.add(new MarkersSettingsItem(app, mapMarkers));
|
||||||
|
}
|
||||||
|
if (!markersHistoryGroups.isEmpty()) {
|
||||||
|
List<MapMarker> mapMarkers = new ArrayList<>();
|
||||||
|
for (MapMarkersGroup group : markersHistoryGroups) {
|
||||||
|
mapMarkers.addAll(group.getMarkers());
|
||||||
|
}
|
||||||
|
settingsItems.add(new HistoryMarkersSettingsItem(app, mapMarkers));
|
||||||
}
|
}
|
||||||
return settingsItems;
|
return settingsItems;
|
||||||
}
|
}
|
||||||
|
@ -721,6 +752,7 @@ public class SettingsHelper {
|
||||||
List<OpenstreetmapPoint> editsPointList = new ArrayList<>();
|
List<OpenstreetmapPoint> editsPointList = new ArrayList<>();
|
||||||
List<FavoriteGroup> favoriteGroups = new ArrayList<>();
|
List<FavoriteGroup> favoriteGroups = new ArrayList<>();
|
||||||
List<MapMarkersGroup> markersGroups = new ArrayList<>();
|
List<MapMarkersGroup> markersGroups = new ArrayList<>();
|
||||||
|
List<MapMarkersGroup> markersHistoryGroups = new ArrayList<>();
|
||||||
|
|
||||||
for (SettingsItem item : settingsItems) {
|
for (SettingsItem item : settingsItems) {
|
||||||
switch (item.getType()) {
|
switch (item.getType()) {
|
||||||
|
@ -800,9 +832,13 @@ public class SettingsHelper {
|
||||||
FavoritesSettingsItem favoritesSettingsItem = (FavoritesSettingsItem) item;
|
FavoritesSettingsItem favoritesSettingsItem = (FavoritesSettingsItem) item;
|
||||||
favoriteGroups.addAll(favoritesSettingsItem.getItems());
|
favoriteGroups.addAll(favoritesSettingsItem.getItems());
|
||||||
break;
|
break;
|
||||||
case MARKERS:
|
case ACTIVE_MARKERS:
|
||||||
MarkersSettingsItem markersSettingsItem = (MarkersSettingsItem) item;
|
MarkersSettingsItem markersSettingsItem = (MarkersSettingsItem) item;
|
||||||
markersGroups.addAll(markersSettingsItem.getItems());
|
markersGroups.add(markersSettingsItem.getMarkersGroup());
|
||||||
|
break;
|
||||||
|
case HISTORY_MARKERS:
|
||||||
|
HistoryMarkersSettingsItem historyMarkersSettingsItem = (HistoryMarkersSettingsItem) item;
|
||||||
|
markersHistoryGroups.add(historyMarkersSettingsItem.getMarkersGroup());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -858,7 +894,10 @@ public class SettingsHelper {
|
||||||
settingsToOperate.put(ExportSettingsType.VOICE, voiceFilesList);
|
settingsToOperate.put(ExportSettingsType.VOICE, voiceFilesList);
|
||||||
}
|
}
|
||||||
if (!markersGroups.isEmpty()) {
|
if (!markersGroups.isEmpty()) {
|
||||||
settingsToOperate.put(ExportSettingsType.MARKERS, markersGroups);
|
settingsToOperate.put(ExportSettingsType.ACTIVE_MARKERS, markersGroups);
|
||||||
|
}
|
||||||
|
if (!markersGroups.isEmpty()) {
|
||||||
|
settingsToOperate.put(ExportSettingsType.HISTORY_MARKERS, markersHistoryGroups);
|
||||||
}
|
}
|
||||||
return settingsToOperate;
|
return settingsToOperate;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,10 @@ import android.content.Context;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import net.osmand.GPXUtilities;
|
||||||
|
import net.osmand.GPXUtilities.GPXFile;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.R;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
@ -17,6 +20,7 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -205,6 +209,7 @@ public abstract class SettingsItem {
|
||||||
String s = json.toString(2);
|
String s = json.toString(2);
|
||||||
outputStream.write(s.getBytes("UTF-8"));
|
outputStream.write(s.getBytes("UTF-8"));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
|
warnings.add(app.getString(R.string.settings_item_write_error, String.valueOf(getType())));
|
||||||
SettingsHelper.LOG.error("Failed to write json to stream", e);
|
SettingsHelper.LOG.error("Failed to write json to stream", e);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -214,6 +219,22 @@ public abstract class SettingsItem {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
|
SettingsItemWriter<? extends SettingsItem> getGpxWriter(@NonNull final GPXFile gpxFile) {
|
||||||
|
return new SettingsItemWriter<SettingsItem>(this) {
|
||||||
|
@Override
|
||||||
|
public boolean writeToStream(@NonNull OutputStream outputStream) throws IOException {
|
||||||
|
Exception error = GPXUtilities.writeGpx(new OutputStreamWriter(outputStream, "UTF-8"), gpxFile);
|
||||||
|
if (error != null) {
|
||||||
|
warnings.add(app.getString(R.string.settings_item_write_error, String.valueOf(getType())));
|
||||||
|
SettingsHelper.LOG.error("Failed write to gpx file", error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return (getType().name() + getName()).hashCode();
|
return (getType().name() + getName()).hashCode();
|
||||||
|
|
|
@ -16,5 +16,6 @@ public enum SettingsItemType {
|
||||||
OSM_NOTES,
|
OSM_NOTES,
|
||||||
OSM_EDITS,
|
OSM_EDITS,
|
||||||
FAVOURITES,
|
FAVOURITES,
|
||||||
MARKERS
|
ACTIVE_MARKERS,
|
||||||
|
HISTORY_MARKERS
|
||||||
}
|
}
|
|
@ -134,9 +134,12 @@ class SettingsItemsFactory {
|
||||||
case FAVOURITES:
|
case FAVOURITES:
|
||||||
item = new FavoritesSettingsItem(app, json);
|
item = new FavoritesSettingsItem(app, json);
|
||||||
break;
|
break;
|
||||||
case MARKERS:
|
case ACTIVE_MARKERS:
|
||||||
item = new MarkersSettingsItem(app, json);
|
item = new MarkersSettingsItem(app, json);
|
||||||
break;
|
break;
|
||||||
|
case HISTORY_MARKERS:
|
||||||
|
item = new HistoryMarkersSettingsItem(app, json);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,18 +14,14 @@ import net.osmand.IndexConstants;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.map.ITileSource;
|
import net.osmand.map.ITileSource;
|
||||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||||
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
|
||||||
import net.osmand.plus.helpers.FileNameTranslationHelper;
|
|
||||||
import net.osmand.plus.helpers.GpxUiHelper;
|
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean;
|
|
||||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
||||||
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
|
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;
|
||||||
|
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||||
import net.osmand.plus.poi.PoiUIFilter;
|
import net.osmand.plus.poi.PoiUIFilter;
|
||||||
import net.osmand.plus.profiles.ProfileIconColors;
|
import net.osmand.plus.profiles.ProfileIconColors;
|
||||||
import net.osmand.plus.profiles.RoutingProfileDataObject.RoutingProfilesResources;
|
import net.osmand.plus.profiles.RoutingProfileDataObject.RoutingProfilesResources;
|
||||||
|
@ -40,7 +36,7 @@ import org.apache.commons.logging.Log;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static net.osmand.plus.settings.backend.backup.FileSettingsItem.*;
|
import static net.osmand.plus.settings.backend.backup.FileSettingsItem.FileSubtype;
|
||||||
|
|
||||||
public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
|
|
||||||
|
@ -162,11 +158,7 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView
|
||||||
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_favorite, activeColorRes));
|
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_favorite, activeColorRes));
|
||||||
} else if (currentItem instanceof MapMarkersGroup) {
|
} else if (currentItem instanceof MapMarkersGroup) {
|
||||||
MapMarkersGroup markersGroup = (MapMarkersGroup) currentItem;
|
MapMarkersGroup markersGroup = (MapMarkersGroup) currentItem;
|
||||||
String groupName = markersGroup.getName();
|
itemHolder.title.setText(markersGroup.getName());
|
||||||
if (Algorithms.isEmpty(groupName)) {
|
|
||||||
groupName = app.getString(R.string.map_markers);
|
|
||||||
}
|
|
||||||
itemHolder.title.setText(groupName);
|
|
||||||
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_flag, activeColorRes));
|
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_flag, activeColorRes));
|
||||||
}
|
}
|
||||||
itemHolder.divider.setVisibility(shouldShowDivider(position) ? View.VISIBLE : View.GONE);
|
itemHolder.divider.setVisibility(shouldShowDivider(position) ? View.VISIBLE : View.GONE);
|
||||||
|
|
|
@ -17,7 +17,6 @@ import net.osmand.IndexConstants;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.map.ITileSource;
|
import net.osmand.map.ITileSource;
|
||||||
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
|
||||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
|
@ -303,13 +302,12 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
||||||
title.setText(FileNameTranslationHelper.getFileNameWithRegion(app, file.getName()));
|
title.setText(FileNameTranslationHelper.getFileNameWithRegion(app, file.getName()));
|
||||||
setupIcon(icon, R.drawable.ic_action_volume_up, itemSelected);
|
setupIcon(icon, R.drawable.ic_action_volume_up, itemSelected);
|
||||||
break;
|
break;
|
||||||
case MARKERS:
|
case ACTIVE_MARKERS:
|
||||||
MapMarkersGroup markersGroup = (MapMarkersGroup) currentItem;
|
title.setText(R.string.map_markers);
|
||||||
String groupName = markersGroup.getName();
|
setupIcon(icon, R.drawable.ic_action_flag, itemSelected);
|
||||||
if (Algorithms.isEmpty(groupName)) {
|
break;
|
||||||
groupName = app.getString(R.string.map_markers);
|
case HISTORY_MARKERS:
|
||||||
}
|
title.setText(R.string.markers_history);
|
||||||
title.setText(groupName);
|
|
||||||
setupIcon(icon, R.drawable.ic_action_flag, itemSelected);
|
setupIcon(icon, R.drawable.ic_action_flag, itemSelected);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -412,8 +410,10 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
||||||
return R.string.local_indexes_cat_tts;
|
return R.string.local_indexes_cat_tts;
|
||||||
case VOICE:
|
case VOICE:
|
||||||
return R.string.local_indexes_cat_voice;
|
return R.string.local_indexes_cat_voice;
|
||||||
case MARKERS:
|
case ACTIVE_MARKERS:
|
||||||
return R.string.map_markers;
|
return R.string.map_markers;
|
||||||
|
case HISTORY_MARKERS:
|
||||||
|
return R.string.markers_history;
|
||||||
default:
|
default:
|
||||||
return R.string.access_empty_list;
|
return R.string.access_empty_list;
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,6 +38,7 @@ import net.osmand.plus.osmedit.OsmNotesPoint;
|
||||||
import net.osmand.plus.poi.PoiUIFilter;
|
import net.osmand.plus.poi.PoiUIFilter;
|
||||||
import net.osmand.plus.quickaction.QuickAction;
|
import net.osmand.plus.quickaction.QuickAction;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
|
import net.osmand.plus.settings.backend.ExportSettingsType;
|
||||||
import net.osmand.plus.settings.backend.backup.SettingsHelper;
|
import net.osmand.plus.settings.backend.backup.SettingsHelper;
|
||||||
import net.osmand.plus.settings.backend.backup.SettingsHelper.ImportAsyncTask;
|
import net.osmand.plus.settings.backend.backup.SettingsHelper.ImportAsyncTask;
|
||||||
import net.osmand.plus.settings.backend.backup.SettingsHelper.ImportType;
|
import net.osmand.plus.settings.backend.backup.SettingsHelper.ImportType;
|
||||||
|
@ -49,7 +50,7 @@ import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static net.osmand.plus.settings.backend.backup.FileSettingsItem.*;
|
import static net.osmand.plus.settings.backend.backup.FileSettingsItem.FileSubtype;
|
||||||
import static net.osmand.plus.settings.fragments.ImportSettingsFragment.IMPORT_SETTINGS_TAG;
|
import static net.osmand.plus.settings.fragments.ImportSettingsFragment.IMPORT_SETTINGS_TAG;
|
||||||
|
|
||||||
|
|
||||||
|
@ -202,6 +203,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment {
|
||||||
List<File> voiceFilesList = new ArrayList<>();
|
List<File> voiceFilesList = new ArrayList<>();
|
||||||
List<File> mapFilesList = new ArrayList<>();
|
List<File> mapFilesList = new ArrayList<>();
|
||||||
List<MapMarkersGroup> markersGroups = new ArrayList<>();
|
List<MapMarkersGroup> markersGroups = new ArrayList<>();
|
||||||
|
List<MapMarkersGroup> markersHistoryGroups = new ArrayList<>();
|
||||||
|
|
||||||
for (Object object : duplicatesList) {
|
for (Object object : duplicatesList) {
|
||||||
if (object instanceof ApplicationMode.ApplicationModeBean) {
|
if (object instanceof ApplicationMode.ApplicationModeBean) {
|
||||||
|
@ -239,7 +241,12 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment {
|
||||||
} else if (object instanceof OpenstreetmapPoint) {
|
} else if (object instanceof OpenstreetmapPoint) {
|
||||||
osmEditsPointList.add((OpenstreetmapPoint) object);
|
osmEditsPointList.add((OpenstreetmapPoint) object);
|
||||||
} else if (object instanceof MapMarkersGroup) {
|
} else if (object instanceof MapMarkersGroup) {
|
||||||
markersGroups.add((MapMarkersGroup) object);
|
MapMarkersGroup markersGroup = (MapMarkersGroup) object;
|
||||||
|
if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) {
|
||||||
|
markersGroups.add(markersGroup);
|
||||||
|
} else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) {
|
||||||
|
markersHistoryGroups.add(markersGroup);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!profiles.isEmpty()) {
|
if (!profiles.isEmpty()) {
|
||||||
|
@ -306,6 +313,10 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment {
|
||||||
duplicates.add(getString(R.string.map_markers));
|
duplicates.add(getString(R.string.map_markers));
|
||||||
duplicates.addAll(markersGroups);
|
duplicates.addAll(markersGroups);
|
||||||
}
|
}
|
||||||
|
if (!markersHistoryGroups.isEmpty()) {
|
||||||
|
duplicates.add(getString(R.string.markers_history));
|
||||||
|
duplicates.addAll(markersHistoryGroups);
|
||||||
|
}
|
||||||
return duplicates;
|
return duplicates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,6 +41,7 @@ import net.osmand.plus.UiUtilities;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||||
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
|
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
|
||||||
|
import net.osmand.plus.mapmarkers.MapMarker;
|
||||||
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
import net.osmand.plus.mapmarkers.MapMarkersGroup;
|
||||||
import net.osmand.plus.osmedit.OpenstreetmapPoint;
|
import net.osmand.plus.osmedit.OpenstreetmapPoint;
|
||||||
import net.osmand.plus.osmedit.OsmNotesPoint;
|
import net.osmand.plus.osmedit.OsmNotesPoint;
|
||||||
|
@ -48,20 +49,21 @@ import net.osmand.plus.poi.PoiUIFilter;
|
||||||
import net.osmand.plus.quickaction.QuickAction;
|
import net.osmand.plus.quickaction.QuickAction;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean;
|
import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean;
|
||||||
import net.osmand.plus.settings.backend.ExportSettingsType;
|
import net.osmand.plus.settings.backend.ExportSettingsType;
|
||||||
|
import net.osmand.plus.settings.backend.backup.AvoidRoadsSettingsItem;
|
||||||
import net.osmand.plus.settings.backend.backup.FavoritesSettingsItem;
|
import net.osmand.plus.settings.backend.backup.FavoritesSettingsItem;
|
||||||
|
import net.osmand.plus.settings.backend.backup.FileSettingsItem;
|
||||||
import net.osmand.plus.settings.backend.backup.GlobalSettingsItem;
|
import net.osmand.plus.settings.backend.backup.GlobalSettingsItem;
|
||||||
|
import net.osmand.plus.settings.backend.backup.HistoryMarkersSettingsItem;
|
||||||
|
import net.osmand.plus.settings.backend.backup.MapSourcesSettingsItem;
|
||||||
import net.osmand.plus.settings.backend.backup.MarkersSettingsItem;
|
import net.osmand.plus.settings.backend.backup.MarkersSettingsItem;
|
||||||
import net.osmand.plus.settings.backend.backup.OsmEditsSettingsItem;
|
import net.osmand.plus.settings.backend.backup.OsmEditsSettingsItem;
|
||||||
import net.osmand.plus.settings.backend.backup.OsmNotesSettingsItem;
|
import net.osmand.plus.settings.backend.backup.OsmNotesSettingsItem;
|
||||||
import net.osmand.plus.settings.backend.backup.SettingsHelper;
|
|
||||||
import net.osmand.plus.settings.backend.backup.AvoidRoadsSettingsItem;
|
|
||||||
import net.osmand.plus.settings.backend.backup.FileSettingsItem;
|
|
||||||
import net.osmand.plus.settings.backend.backup.SettingsHelper.ImportAsyncTask;
|
|
||||||
import net.osmand.plus.settings.backend.backup.SettingsHelper.ImportType;
|
|
||||||
import net.osmand.plus.settings.backend.backup.MapSourcesSettingsItem;
|
|
||||||
import net.osmand.plus.settings.backend.backup.PoiUiFiltersSettingsItem;
|
import net.osmand.plus.settings.backend.backup.PoiUiFiltersSettingsItem;
|
||||||
import net.osmand.plus.settings.backend.backup.ProfileSettingsItem;
|
import net.osmand.plus.settings.backend.backup.ProfileSettingsItem;
|
||||||
import net.osmand.plus.settings.backend.backup.QuickActionsSettingsItem;
|
import net.osmand.plus.settings.backend.backup.QuickActionsSettingsItem;
|
||||||
|
import net.osmand.plus.settings.backend.backup.SettingsHelper;
|
||||||
|
import net.osmand.plus.settings.backend.backup.SettingsHelper.ImportAsyncTask;
|
||||||
|
import net.osmand.plus.settings.backend.backup.SettingsHelper.ImportType;
|
||||||
import net.osmand.plus.settings.backend.backup.SettingsItem;
|
import net.osmand.plus.settings.backend.backup.SettingsItem;
|
||||||
import net.osmand.plus.settings.backend.backup.SettingsItemType;
|
import net.osmand.plus.settings.backend.backup.SettingsItemType;
|
||||||
import net.osmand.plus.widgets.TextViewEx;
|
import net.osmand.plus.widgets.TextViewEx;
|
||||||
|
@ -439,6 +441,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment {
|
||||||
List<OpenstreetmapPoint> osmEditsPointList = new ArrayList<>();
|
List<OpenstreetmapPoint> osmEditsPointList = new ArrayList<>();
|
||||||
List<FavoriteGroup> favoriteGroups = new ArrayList<>();
|
List<FavoriteGroup> favoriteGroups = new ArrayList<>();
|
||||||
List<MapMarkersGroup> markersGroups = new ArrayList<>();
|
List<MapMarkersGroup> markersGroups = new ArrayList<>();
|
||||||
|
List<MapMarkersGroup> markersHistoryGroups = new ArrayList<>();
|
||||||
for (Object object : data) {
|
for (Object object : data) {
|
||||||
if (object instanceof ApplicationModeBean) {
|
if (object instanceof ApplicationModeBean) {
|
||||||
appModeBeans.add((ApplicationModeBean) object);
|
appModeBeans.add((ApplicationModeBean) object);
|
||||||
|
@ -463,7 +466,12 @@ public class ImportSettingsFragment extends BaseOsmAndFragment {
|
||||||
} else if (object instanceof GlobalSettingsItem) {
|
} else if (object instanceof GlobalSettingsItem) {
|
||||||
settingsItems.add((GlobalSettingsItem) object);
|
settingsItems.add((GlobalSettingsItem) object);
|
||||||
} else if (object instanceof MapMarkersGroup) {
|
} else if (object instanceof MapMarkersGroup) {
|
||||||
|
MapMarkersGroup markersGroup = (MapMarkersGroup) object;
|
||||||
|
if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) {
|
||||||
markersGroups.add((MapMarkersGroup) object);
|
markersGroups.add((MapMarkersGroup) object);
|
||||||
|
} else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) {
|
||||||
|
markersHistoryGroups.add((MapMarkersGroup) object);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!appModeBeans.isEmpty()) {
|
if (!appModeBeans.isEmpty()) {
|
||||||
|
@ -496,9 +504,22 @@ public class ImportSettingsFragment extends BaseOsmAndFragment {
|
||||||
settingsItems.add(new FavoritesSettingsItem(app, baseItem, favoriteGroups));
|
settingsItems.add(new FavoritesSettingsItem(app, baseItem, favoriteGroups));
|
||||||
}
|
}
|
||||||
if (!markersGroups.isEmpty()) {
|
if (!markersGroups.isEmpty()) {
|
||||||
MarkersSettingsItem baseItem = getBaseItem(SettingsItemType.MARKERS, MarkersSettingsItem.class);
|
List<MapMarker> mapMarkers = new ArrayList<>();
|
||||||
settingsItems.add(new MarkersSettingsItem(app, baseItem, markersGroups));
|
for (MapMarkersGroup group : markersGroups) {
|
||||||
|
mapMarkers.addAll(group.getMarkers());
|
||||||
}
|
}
|
||||||
|
MarkersSettingsItem baseItem = getBaseItem(SettingsItemType.ACTIVE_MARKERS, MarkersSettingsItem.class);
|
||||||
|
settingsItems.add(new MarkersSettingsItem(app, baseItem, mapMarkers));
|
||||||
|
}
|
||||||
|
if (!markersHistoryGroups.isEmpty()) {
|
||||||
|
List<MapMarker> mapMarkers = new ArrayList<>();
|
||||||
|
for (MapMarkersGroup group : markersHistoryGroups) {
|
||||||
|
mapMarkers.addAll(group.getMarkers());
|
||||||
|
}
|
||||||
|
HistoryMarkersSettingsItem baseItem = getBaseItem(SettingsItemType.HISTORY_MARKERS, HistoryMarkersSettingsItem.class);
|
||||||
|
settingsItems.add(new HistoryMarkersSettingsItem(app, baseItem, mapMarkers));
|
||||||
|
}
|
||||||
|
|
||||||
return settingsItems;
|
return settingsItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -142,10 +142,14 @@ public class ImportedSettingsItemsAdapter extends
|
||||||
holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_settings, activeColorRes));
|
holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_settings, activeColorRes));
|
||||||
holder.title.setText(R.string.general_settings_2);
|
holder.title.setText(R.string.general_settings_2);
|
||||||
break;
|
break;
|
||||||
case MARKERS:
|
case ACTIVE_MARKERS:
|
||||||
holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_flag, activeColorRes));
|
holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_flag, activeColorRes));
|
||||||
holder.title.setText(R.string.map_markers);
|
holder.title.setText(R.string.map_markers);
|
||||||
break;
|
break;
|
||||||
|
case HISTORY_MARKERS:
|
||||||
|
holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_flag, activeColorRes));
|
||||||
|
holder.title.setText(R.string.markers_history);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue