Export markers and markers history to separate files

This commit is contained in:
Vitaliy 2020-11-11 03:15:17 +02:00
parent e0b967c23b
commit 24a3d8fd53
16 changed files with 389 additions and 204 deletions

View file

@ -11,6 +11,7 @@
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_paused_title">OsmAnd Live subscription has been paused</string>
<string name="subscription_expired_title">OsmAnd Live subscription has been expired</string>

View file

@ -2,9 +2,10 @@ package net.osmand.plus.mapmarkers;
import android.content.Context;
import androidx.annotation.ColorInt;
import androidx.core.content.ContextCompat;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint;
@ -15,6 +16,7 @@ import net.osmand.util.Algorithms;
import static net.osmand.data.PointDescription.POINT_TYPE_MAP_MARKER;
public class MapMarker implements LocationPoint {
private static int[] colors;
public String id;
@ -30,7 +32,7 @@ public class MapMarker implements LocationPoint {
public String nextKey;
public String groupKey;
public String groupName;
public GPXUtilities.WptPt wptPt;
public WptPt wptPt;
public FavouritePoint favouritePoint;
public String mapObjectName;
@ -45,7 +47,7 @@ public class MapMarker implements LocationPoint {
public int getType() {
return favouritePoint == null ?
(wptPt == null ? MapMarkersGroup.ANY_TYPE : MapMarkersGroup.GPX_TYPE) :
MapMarkersGroup.FAVORITES_TYPE;
MapMarkersGroup.FAVORITES_TYPE;
}
public PointDescription getPointDescription(Context ctx) {
@ -110,7 +112,7 @@ public class MapMarker implements LocationPoint {
return result;
}
private static final int[] colorsIds = new int[]{
private static final int[] colorsIds = new int[] {
R.color.marker_blue,
R.color.marker_green,
R.color.marker_orange,
@ -134,4 +136,14 @@ public class MapMarker implements LocationPoint {
public static int getColorId(int colorIndex) {
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;
}
}

View file

@ -59,11 +59,8 @@ public class MapMarkersHelper {
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 CREATION_DATE = "creation_date";
private static final Log LOG = PlatformUtil.getLog(MapMarkersHelper.class);
@ -1035,18 +1032,38 @@ public class MapMarkersHelper {
wpt.name = marker.getOnlyName();
wpt.setColor(ContextCompat.getColor(ctx, MapMarker.getColorId(marker.colorIndex)));
if (completeBackup) {
wpt.category = marker.groupKey;
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(VISITED_DATE, String.valueOf(marker.visitedDate));
if (marker.creationDate != 0) {
wpt.getExtensionsToWrite().put(CREATION_DATE, String.valueOf(marker.creationDate));
}
if (marker.visitedDate != 0) {
wpt.getExtensionsToWrite().put(VISITED_DATE, String.valueOf(marker.visitedDate));
}
}
gpxFile.addPoint(wpt);
}
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:

View file

@ -17,5 +17,6 @@ public enum ExportSettingsType {
FAVORITES,
TTS_VOICE,
VOICE,
MARKERS
ACTIVE_MARKERS,
HISTORY_MARKERS
}

View file

@ -16,10 +16,7 @@ import net.osmand.plus.R;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
@ -69,11 +66,6 @@ public class FavoritesSettingsItem extends CollectionSettingsItem<FavoriteGroup>
return ctx.getString(R.string.shared_string_favorites);
}
@NonNull
public String getDefaultFileName() {
return getName() + getDefaultFileExtension();
}
@NonNull
public String getDefaultFileExtension() {
return GPX_FILE_EXT;
@ -177,21 +169,9 @@ public class FavoritesSettingsItem extends CollectionSettingsItem<FavoriteGroup>
@Nullable
@Override
SettingsItemWriter<FavoritesSettingsItem> getWriter() {
return new SettingsItemWriter<FavoritesSettingsItem>(this) {
@Override
public boolean writeToStream(@NonNull OutputStream outputStream) throws IOException {
List<FavouritePoint> favourites = getPointsFromGroups(items);
GPXFile gpxFile = favoritesHelper.asGpxFile(favourites);
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;
}
};
SettingsItemWriter<? extends SettingsItem> getWriter() {
List<FavouritePoint> favourites = getPointsFromGroups(items);
GPXFile gpxFile = favoritesHelper.asGpxFile(favourites);
return getGpxWriter(gpxFile);
}
}

View file

@ -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);
}
}

View file

@ -7,8 +7,6 @@ import androidx.annotation.Nullable;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandApplication;
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.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.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
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 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);
}
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);
}
@ -58,13 +46,13 @@ public class MarkersSettingsItem extends CollectionSettingsItem<MapMarkersGroup>
protected void init() {
super.init();
markersHelper = app.getMapMarkersHelper();
existingItems = new ArrayList<>(markersHelper.getMapMarkersGroups());
existingItems = new ArrayList<>(markersHelper.getMapMarkers());
}
@NonNull
@Override
public SettingsItemType getType() {
return SettingsItemType.MARKERS;
return SettingsItemType.ACTIVE_MARKERS;
}
@NonNull
@ -79,11 +67,6 @@ public class MarkersSettingsItem extends CollectionSettingsItem<MapMarkersGroup>
return ctx.getString(R.string.map_markers);
}
@NonNull
public String getDefaultFileName() {
return getName() + getDefaultFileExtension();
}
@NonNull
public String getDefaultFileExtension() {
return GPX_FILE_EXT;
@ -91,37 +74,29 @@ public class MarkersSettingsItem extends CollectionSettingsItem<MapMarkersGroup>
@Override
public void apply() {
List<MapMarkersGroup> newItems = getNewItems();
List<MapMarker> newItems = getNewItems();
if (!newItems.isEmpty() || !duplicateItems.isEmpty()) {
appliedItems = new ArrayList<>(newItems);
for (MapMarkersGroup duplicate : duplicateItems) {
for (MapMarker duplicate : duplicateItems) {
if (shouldReplace) {
MapMarkersGroup existingGroup = markersHelper.getMapMarkerGroupById(duplicate.getId(), duplicate.getType());
if (existingGroup != null) {
List<MapMarker> existingMarkers = new ArrayList<>(existingGroup.getMarkers());
for (MapMarker marker : existingMarkers) {
markersHelper.removeMarker(marker);
}
}
MapMarker existingMarker = markersHelper.getMapMarker(duplicate.point);
markersHelper.removeMarker(existingMarker);
}
appliedItems.add(duplicate);
appliedItems.add(shouldReplace ? duplicate : renameItem(duplicate));
}
for (MapMarkersGroup markersGroup : appliedItems) {
for (MapMarker marker : markersGroup.getMarkers()) {
markersHelper.addMarker(marker);
}
for (MapMarker marker : appliedItems) {
markersHelper.addMarker(marker);
}
}
}
@Override
public boolean isDuplicate(@NonNull MapMarkersGroup markersGroup) {
String name = markersGroup.getName();
for (MapMarkersGroup group : existingItems) {
if (Algorithms.stringsEqual(group.getName(), name)
&& !Algorithms.isEmpty(group.getMarkers())
&& !Algorithms.isEmpty(markersGroup.getMarkers())) {
public boolean isDuplicate(@NonNull MapMarker mapMarker) {
for (MapMarker marker : existingItems) {
if (marker.equals(mapMarker)
&& Algorithms.objectEquals(marker.getOriginalPointDescription(), mapMarker.getOriginalPointDescription())) {
return true;
}
}
@ -135,8 +110,26 @@ public class MarkersSettingsItem extends CollectionSettingsItem<MapMarkersGroup>
@NonNull
@Override
public MapMarkersGroup renameItem(@NonNull MapMarkersGroup item) {
return item;
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.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
@ -151,88 +144,17 @@ public class MarkersSettingsItem extends CollectionSettingsItem<MapMarkersGroup>
warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType())));
SettingsHelper.LOG.error("Failed read gpx file", gpxFile.error);
} else {
List<Integer> markerColors = getMarkersColors();
for (WptPt point : gpxFile.getPoints()) {
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);
}
List<MapMarker> mapMarkers = markersHelper.readMarkersFromGpx(gpxFile, false);
items.addAll(mapMarkers);
}
}
};
}
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
@Override
SettingsItemWriter<MarkersSettingsItem> getWriter() {
return new SettingsItemWriter<MarkersSettingsItem>(this) {
@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;
SettingsItemWriter<? extends SettingsItem> getWriter() {
GPXFile gpxFile = markersHelper.generateGpx(items, true);
return getGpxWriter(gpxFile);
}
}

View file

@ -16,9 +16,9 @@ import net.osmand.map.ITileSource;
import net.osmand.map.TileSourceManager;
import net.osmand.map.TileSourceManager.TileSourceTemplate;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.SQLiteTileSource;
import net.osmand.plus.activities.LocalIndexHelper;
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.GpxUiHelper;
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.OsmEditingPlugin;
import net.osmand.plus.osmedit.OsmNotesPoint;
@ -595,9 +597,21 @@ public class SettingsHelper {
if (!files.isEmpty()) {
dataList.put(ExportSettingsType.VOICE, files);
}
List<MapMarkersGroup> markersGroups = app.getMapMarkersHelper().getMapMarkersGroups();
if (!markersGroups.isEmpty()) {
dataList.put(ExportSettingsType.MARKERS, markersGroups);
List<MapMarker> mapMarkers = app.getMapMarkersHelper().getMapMarkers();
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);
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;
}
@ -639,6 +653,7 @@ public class SettingsHelper {
List<OsmNotesPoint> osmNotesPointList = new ArrayList<>();
List<OpenstreetmapPoint> osmEditsPointList = new ArrayList<>();
List<MapMarkersGroup> markersGroups = new ArrayList<>();
List<MapMarkersGroup> markersHistoryGroups = new ArrayList<>();
for (Object object : data) {
if (object instanceof QuickAction) {
@ -664,7 +679,12 @@ public class SettingsHelper {
} else if (object instanceof FavoriteGroup) {
favoriteGroups.add((FavoriteGroup) object);
} else if (object instanceof MapMarkersGroup) {
markersGroups.add((MapMarkersGroup) object);
MapMarkersGroup markersGroup = (MapMarkersGroup) object;
if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) {
markersGroups.add((MapMarkersGroup) object);
} else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) {
markersHistoryGroups.add((MapMarkersGroup) object);
}
}
}
if (!quickActions.isEmpty()) {
@ -697,7 +717,18 @@ public class SettingsHelper {
settingsItems.add(new FavoritesSettingsItem(app, favoriteGroups));
}
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;
}
@ -721,6 +752,7 @@ public class SettingsHelper {
List<OpenstreetmapPoint> editsPointList = new ArrayList<>();
List<FavoriteGroup> favoriteGroups = new ArrayList<>();
List<MapMarkersGroup> markersGroups = new ArrayList<>();
List<MapMarkersGroup> markersHistoryGroups = new ArrayList<>();
for (SettingsItem item : settingsItems) {
switch (item.getType()) {
@ -800,9 +832,13 @@ public class SettingsHelper {
FavoritesSettingsItem favoritesSettingsItem = (FavoritesSettingsItem) item;
favoriteGroups.addAll(favoritesSettingsItem.getItems());
break;
case MARKERS:
case ACTIVE_MARKERS:
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;
default:
break;
@ -858,7 +894,10 @@ public class SettingsHelper {
settingsToOperate.put(ExportSettingsType.VOICE, voiceFilesList);
}
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;
}

View file

@ -5,7 +5,10 @@ import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.util.Algorithms;
import org.json.JSONException;
@ -17,6 +20,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.List;
@ -205,6 +209,7 @@ public abstract class SettingsItem {
String s = json.toString(2);
outputStream.write(s.getBytes("UTF-8"));
} 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);
}
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
public int hashCode() {
return (getType().name() + getName()).hashCode();

View file

@ -16,5 +16,6 @@ public enum SettingsItemType {
OSM_NOTES,
OSM_EDITS,
FAVOURITES,
MARKERS
ACTIVE_MARKERS,
HISTORY_MARKERS
}

View file

@ -134,9 +134,12 @@ class SettingsItemsFactory {
case FAVOURITES:
item = new FavoritesSettingsItem(app, json);
break;
case MARKERS:
case ACTIVE_MARKERS:
item = new MarkersSettingsItem(app, json);
break;
case HISTORY_MARKERS:
item = new HistoryMarkersSettingsItem(app, json);
break;
}
return item;
}

View file

@ -14,18 +14,14 @@ import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.map.ITileSource;
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.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
import net.osmand.plus.helpers.FileNameTranslationHelper;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.profiles.ProfileIconColors;
import net.osmand.plus.profiles.RoutingProfileDataObject.RoutingProfilesResources;
@ -40,7 +36,7 @@ import org.apache.commons.logging.Log;
import java.io.File;
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> {
@ -162,11 +158,7 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_favorite, activeColorRes));
} else if (currentItem instanceof MapMarkersGroup) {
MapMarkersGroup markersGroup = (MapMarkersGroup) currentItem;
String groupName = markersGroup.getName();
if (Algorithms.isEmpty(groupName)) {
groupName = app.getString(R.string.map_markers);
}
itemHolder.title.setText(groupName);
itemHolder.title.setText(markersGroup.getName());
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_flag, activeColorRes));
}
itemHolder.divider.setVisibility(shouldShowDivider(position) ? View.VISIBLE : View.GONE);

View file

@ -17,7 +17,6 @@ import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.map.ITileSource;
import net.osmand.plus.FavouritesDbHelper.FavoriteGroup;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
@ -303,13 +302,12 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
title.setText(FileNameTranslationHelper.getFileNameWithRegion(app, file.getName()));
setupIcon(icon, R.drawable.ic_action_volume_up, itemSelected);
break;
case MARKERS:
MapMarkersGroup markersGroup = (MapMarkersGroup) currentItem;
String groupName = markersGroup.getName();
if (Algorithms.isEmpty(groupName)) {
groupName = app.getString(R.string.map_markers);
}
title.setText(groupName);
case ACTIVE_MARKERS:
title.setText(R.string.map_markers);
setupIcon(icon, R.drawable.ic_action_flag, itemSelected);
break;
case HISTORY_MARKERS:
title.setText(R.string.markers_history);
setupIcon(icon, R.drawable.ic_action_flag, itemSelected);
break;
default:
@ -412,8 +410,10 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
return R.string.local_indexes_cat_tts;
case VOICE:
return R.string.local_indexes_cat_voice;
case MARKERS:
case ACTIVE_MARKERS:
return R.string.map_markers;
case HISTORY_MARKERS:
return R.string.markers_history;
default:
return R.string.access_empty_list;
}

View file

@ -38,6 +38,7 @@ import net.osmand.plus.osmedit.OsmNotesPoint;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.quickaction.QuickAction;
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.ImportAsyncTask;
import net.osmand.plus.settings.backend.backup.SettingsHelper.ImportType;
@ -49,7 +50,7 @@ import java.io.File;
import java.util.ArrayList;
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;
@ -202,6 +203,7 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment {
List<File> voiceFilesList = new ArrayList<>();
List<File> mapFilesList = new ArrayList<>();
List<MapMarkersGroup> markersGroups = new ArrayList<>();
List<MapMarkersGroup> markersHistoryGroups = new ArrayList<>();
for (Object object : duplicatesList) {
if (object instanceof ApplicationMode.ApplicationModeBean) {
@ -239,7 +241,12 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment {
} else if (object instanceof OpenstreetmapPoint) {
osmEditsPointList.add((OpenstreetmapPoint) object);
} 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()) {
@ -306,6 +313,10 @@ public class ImportDuplicatesFragment extends BaseOsmAndFragment {
duplicates.add(getString(R.string.map_markers));
duplicates.addAll(markersGroups);
}
if (!markersHistoryGroups.isEmpty()) {
duplicates.add(getString(R.string.markers_history));
duplicates.addAll(markersHistoryGroups);
}
return duplicates;
}

View file

@ -41,6 +41,7 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.osmedit.OpenstreetmapPoint;
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.settings.backend.ApplicationMode.ApplicationModeBean;
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.FileSettingsItem;
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.OsmEditsSettingsItem;
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.ProfileSettingsItem;
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.SettingsItemType;
import net.osmand.plus.widgets.TextViewEx;
@ -439,6 +441,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment {
List<OpenstreetmapPoint> osmEditsPointList = new ArrayList<>();
List<FavoriteGroup> favoriteGroups = new ArrayList<>();
List<MapMarkersGroup> markersGroups = new ArrayList<>();
List<MapMarkersGroup> markersHistoryGroups = new ArrayList<>();
for (Object object : data) {
if (object instanceof ApplicationModeBean) {
appModeBeans.add((ApplicationModeBean) object);
@ -463,7 +466,12 @@ public class ImportSettingsFragment extends BaseOsmAndFragment {
} else if (object instanceof GlobalSettingsItem) {
settingsItems.add((GlobalSettingsItem) object);
} else if (object instanceof MapMarkersGroup) {
markersGroups.add((MapMarkersGroup) object);
MapMarkersGroup markersGroup = (MapMarkersGroup) object;
if (ExportSettingsType.ACTIVE_MARKERS.name().equals(markersGroup.getId())) {
markersGroups.add((MapMarkersGroup) object);
} else if (ExportSettingsType.HISTORY_MARKERS.name().equals(markersGroup.getId())) {
markersHistoryGroups.add((MapMarkersGroup) object);
}
}
}
if (!appModeBeans.isEmpty()) {
@ -496,9 +504,22 @@ public class ImportSettingsFragment extends BaseOsmAndFragment {
settingsItems.add(new FavoritesSettingsItem(app, baseItem, favoriteGroups));
}
if (!markersGroups.isEmpty()) {
MarkersSettingsItem baseItem = getBaseItem(SettingsItemType.MARKERS, MarkersSettingsItem.class);
settingsItems.add(new MarkersSettingsItem(app, baseItem, markersGroups));
List<MapMarker> mapMarkers = new ArrayList<>();
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;
}

View file

@ -142,10 +142,14 @@ public class ImportedSettingsItemsAdapter extends
holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_settings, activeColorRes));
holder.title.setText(R.string.general_settings_2);
break;
case MARKERS:
case ACTIVE_MARKERS:
holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_flag, activeColorRes));
holder.title.setText(R.string.map_markers);
break;
case HISTORY_MARKERS:
holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_flag, activeColorRes));
holder.title.setText(R.string.markers_history);
break;
}
}