From d676cb3d5536c09c93b3109a7188dea5f7ba6708 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Fri, 16 Oct 2020 19:21:03 +0300 Subject: [PATCH 1/7] Export OSM Note, OSM Edit --- .../main/java/net/osmand/osm/edit/Entity.java | 7 + .../plus/osmedit/OpenstreetmapPoint.java | 14 ++ .../osmand/plus/osmedit/OsmEditingPlugin.java | 15 ++ .../osmand/plus/osmedit/OsmEditsAdapter.java | 18 +-- .../osmand/plus/osmedit/OsmEditsFragment.java | 22 +-- .../settings/backend/ExportSettingsType.java | 3 +- .../backend/backup/OsmEditsSettingsItem.java | 140 ++++++++++++++++++ .../backend/backup/OsmNotesSettingsItem.java | 119 +++++++++++++++ .../backend/backup/SettingsHelper.java | 51 +++++++ .../backend/backup/SettingsItemType.java | 3 +- .../ExportImportSettingsAdapter.java | 30 ++-- .../ImportedSettingsItemsAdapter.java | 8 + 12 files changed, 379 insertions(+), 51 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java create mode 100644 OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmNotesSettingsItem.java diff --git a/OsmAnd-java/src/main/java/net/osmand/osm/edit/Entity.java b/OsmAnd-java/src/main/java/net/osmand/osm/edit/Entity.java index 6005f85035..7bb8edbf49 100644 --- a/OsmAnd-java/src/main/java/net/osmand/osm/edit/Entity.java +++ b/OsmAnd-java/src/main/java/net/osmand/osm/edit/Entity.java @@ -114,6 +114,8 @@ public abstract class Entity implements Serializable { public static final int MODIFY_DELETED = -1; public static final int MODIFY_MODIFIED = 1; public static final int MODIFY_CREATED = 2; + public static final String POI_TYPE_TAG = "poi_type_tag"; + public static final String REMOVE_TAG_PREFIX = "----"; public Entity(long id) { this.id = id; @@ -241,6 +243,11 @@ public abstract class Entity implements Serializable { return Collections.unmodifiableMap(tags); } + public boolean isNotValid(String tag) { + String val = getTag(tag); + return val == null || val.length() == 0 || tag.length() == 0 + || tag.startsWith(REMOVE_TAG_PREFIX) || tag.equals(POI_TYPE_TAG); + } public Collection getTagKeySet() { if (tags == null) { diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapPoint.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapPoint.java index 69bc753ab4..7e7a35d6f1 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapPoint.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapPoint.java @@ -75,6 +75,20 @@ public class OpenstreetmapPoint extends OsmPoint { this.comment = comment; } + public String getTagsString() { + StringBuilder sb = new StringBuilder(); + for (String tag : entity.getTagKeySet()) { + String val = entity.getTag(tag); + if (entity.isNotValid(tag)) { + continue; + } + sb.append(tag).append(" : "); + sb.append(val).append("; "); + } + return sb.toString(); + } + + @Override public String toString() { return new StringBuffer("Openstreetmap Point ").append(this.getAction()).append(" ").append(this.getName()) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index 5030530f88..ec774134e5 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -5,17 +5,23 @@ import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; +import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.os.AsyncTask; +import android.text.SpannableString; +import android.text.TextUtils; +import android.text.style.StyleSpan; import android.view.LayoutInflater; import android.view.View; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.Spinner; import android.widget.Toast; + import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.Fragment; + import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; import net.osmand.data.Amenity; @@ -528,6 +534,15 @@ public class OsmEditingPlugin extends OsmandPlugin { } } + public static SpannableString getTitle(OsmPoint osmPoint, Context ctx) { + SpannableString title = new SpannableString(getName(osmPoint)); + if (TextUtils.isEmpty(title)) { + title = SpannableString.valueOf(getCategory(osmPoint, ctx)); + title.setSpan(new StyleSpan(Typeface.ITALIC), 0, title.length(), 0); + } + return title; + } + public static String getName(OsmPoint point) { if (point.getGroup() == OsmPoint.Group.POI) { return ((OpenstreetmapPoint) point).getName(); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java index f965318109..92159c49df 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java @@ -1,11 +1,7 @@ package net.osmand.plus.osmedit; import android.content.Context; -import android.graphics.Typeface; import android.graphics.drawable.Drawable; -import android.text.SpannableString; -import android.text.TextUtils; -import android.text.style.StyleSpan; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -182,7 +178,7 @@ public class OsmEditsAdapter extends ArrayAdapter { private void bindOsmEditViewHolder(final OsmEditViewHolder holder, final OsmPoint osmEdit, final int position) { setupBackground(holder.mainView); - holder.titleTextView.setText(getTitle(osmEdit)); + holder.titleTextView.setText(OsmEditingPlugin.getTitle(osmEdit, getContext())); holder.descriptionTextView.setText(getDescription(osmEdit)); Drawable icon = getIcon(osmEdit); if (icon != null) { @@ -243,14 +239,6 @@ public class OsmEditsAdapter extends ArrayAdapter { return items.size(); } - private SpannableString getTitle(OsmPoint osmPoint) { - SpannableString title = new SpannableString(OsmEditingPlugin.getName(osmPoint)); - if (TextUtils.isEmpty(title)) { - title = SpannableString.valueOf(getCategory(osmPoint)); - title.setSpan(new StyleSpan(Typeface.ITALIC), 0, title.length(), 0); - } - return title; - } private Drawable getIcon(OsmPoint point) { if (point.getGroup() == OsmPoint.Group.POI) { @@ -304,10 +292,6 @@ public class OsmEditsAdapter extends ArrayAdapter { return true; } - private String getCategory(OsmPoint point) { - return OsmEditingPlugin.getCategory(point, getContext()); - } - private String getDescription(OsmPoint point) { return OsmEditingPlugin.getDescription(point, getContext(), true); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java index f39b695d50..40f62e55b6 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsFragment.java @@ -781,7 +781,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo if (point.getGroup() == Group.POI) { OpenstreetmapPoint p = (OpenstreetmapPoint) point; WptPt wpt = new WptPt(); - wpt.name = getTagsString(p); + wpt.name = p.getTagsString(); wpt.lat = p.getLatitude(); wpt.lon = p.getLongitude(); wpt.desc = "id: " + String.valueOf(p.getId()) + @@ -817,24 +817,6 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo return sb.toString(); } - private String getTagsString(OpenstreetmapPoint point) { - StringBuilder sb = new StringBuilder(); - for (String tag : point.getEntity().getTagKeySet()) { - String val = point.getEntity().getTag(tag); - if (isNotValid(tag, val)) { - continue; - } - sb.append(tag).append(" : "); - sb.append(val).append("; "); - } - return sb.toString(); - } - - private boolean isNotValid(String tag, String val) { - return val == null || val.length() == 0 || tag.length() == 0 - || tag.startsWith(EditPoiData.REMOVE_TAG_PREFIX) || tag.equals("poi_type_tag"); - } - private void writeContent(XmlSerializer sz, OsmPoint[] points, OsmPoint.Action a) throws IllegalArgumentException, IllegalStateException, IOException { for (OsmPoint point : points) { if (point.getGroup() == Group.POI) { @@ -878,7 +860,7 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo private void writeTags(XmlSerializer sz, Entity p) { for (String tag : p.getTagKeySet()) { String val = p.getTag(tag); - if (isNotValid(tag, val)) { + if (p.isNotValid(tag)) { continue; } try { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java b/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java index 79e35ffdf8..1b4231b873 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java @@ -12,5 +12,6 @@ public enum ExportSettingsType { FAVORITES, TRACKS, MULTIMEDIA_NOTES, - OSM_CHANGES + OSM_NOTES, + OSM_EDITS } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java new file mode 100644 index 0000000000..1eb1e25393 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java @@ -0,0 +1,140 @@ +package net.osmand.plus.settings.backend.backup; + +import android.content.Context; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import net.osmand.osm.edit.Entity; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.R; +import net.osmand.plus.osmedit.OpenstreetmapPoint; +import net.osmand.plus.osmedit.OsmEditingPlugin; +import net.osmand.plus.osmedit.OsmPoint; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +public class OsmEditsSettingsItem extends CollectionSettingsItem { + + public OsmEditsSettingsItem(@NonNull OsmandApplication app, @NonNull List items) { + super(app, null, items); + } + + @Override + protected void init() { + super.init(); + OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); + if (osmEditingPlugin != null) { + existingItems = osmEditingPlugin.getDBPOI().getOpenstreetmapPoints(); + } + } + + @NonNull + @Override + public SettingsItemType getType() { + return SettingsItemType.OSM_EDITS; + } + + @Override + public void apply() { + List newItems = getNewItems(); + if (!newItems.isEmpty() || !duplicateItems.isEmpty()) { + appliedItems = new ArrayList<>(newItems); + + for (OpenstreetmapPoint duplicate : duplicateItems) { + appliedItems.add(shouldReplace ? duplicate : renameItem(duplicate)); + } + } + } + + @Override + public boolean isDuplicate(@NonNull OpenstreetmapPoint item) { + return false; + } + + @NonNull + @Override + public OpenstreetmapPoint renameItem(@NonNull OpenstreetmapPoint item) { + return item; + } + + @NonNull + @Override + public String getName() { + return "osm_edits"; + } + + @NonNull + @Override + public String getPublicName(@NonNull Context ctx) { + return ctx.getString(R.string.osm_edits); + } + + @Override + public boolean shouldReadOnCollecting() { + return true; + } + + @Override + void readItemsFromJson(@NonNull JSONObject json) throws IllegalArgumentException { + } + + @Override + void writeItemsToJson(@NonNull JSONObject json) { + JSONArray jsonArray = new JSONArray(); + if (!items.isEmpty()) { + try { + for (OpenstreetmapPoint point : items) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("name", point.getTagsString()); + jsonObject.put("lat", point.getLatitude()); + jsonObject.put("lon", point.getLongitude()); + jsonObject.put("action", OsmPoint.stringAction.get(point.getAction())); + jsonArray.put(jsonObject); + jsonArray.put(writeTags(point.getEntity())); + } + json.put("items", jsonArray); + } catch (JSONException e) { + warnings.add(app.getString(R.string.settings_item_write_error, String.valueOf(getType()))); + SettingsHelper.LOG.error("Failed write to json", e); + } + } + } + + private JSONArray writeTags(Entity entity) { + JSONArray tagList = new JSONArray(); + for (String tag : entity.getTagKeySet()) { + String val = entity.getTag(tag); + if (entity.isNotValid(tag)) { + continue; + } + try { + JSONObject tagItem = new JSONObject(); + tagItem.put("k", tag); + tagItem.put("v", val); + tagList.put(tagItem); + } catch (JSONException e) { + e.printStackTrace(); + } + } + return tagList; + } + + @Nullable + @Override + SettingsItemReader getReader() { + return getJsonReader(); + } + + @Nullable + @Override + SettingsItemWriter getWriter() { + return null; + } +} diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmNotesSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmNotesSettingsItem.java new file mode 100644 index 0000000000..500d70f426 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmNotesSettingsItem.java @@ -0,0 +1,119 @@ +package net.osmand.plus.settings.backend.backup; + +import android.content.Context; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.OsmandPlugin; +import net.osmand.plus.R; +import net.osmand.plus.osmedit.OsmEditingPlugin; +import net.osmand.plus.osmedit.OsmNotesPoint; +import net.osmand.plus.osmedit.OsmPoint; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.List; + +public class OsmNotesSettingsItem extends CollectionSettingsItem { + + public OsmNotesSettingsItem(@NonNull OsmandApplication app, @NonNull List items) { + super(app, null, items); + } + + @Override + protected void init() { + super.init(); + OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); + if (osmEditingPlugin != null) { + existingItems = osmEditingPlugin.getDBBug().getOsmbugsPoints(); + } + } + + @NonNull + @Override + public SettingsItemType getType() { + return SettingsItemType.OSM_NOTES; + } + + @Override + public void apply() { + List newItems = getNewItems(); + if (!newItems.isEmpty() || !duplicateItems.isEmpty()) { + appliedItems = new ArrayList<>(newItems); + + for (OsmNotesPoint duplicate : duplicateItems) { + appliedItems.add(shouldReplace ? duplicate : renameItem(duplicate)); + } + } + } + + @Override + public boolean isDuplicate(@NonNull OsmNotesPoint item) { + return false; + } + + @NonNull + @Override + public OsmNotesPoint renameItem(@NonNull OsmNotesPoint item) { + return item; + } + + @NonNull + @Override + public String getName() { + return "osm_notes"; + } + + @NonNull + @Override + public String getPublicName(@NonNull Context ctx) { + return ctx.getString(R.string.osm_notes); + } + + @Override + public boolean shouldReadOnCollecting() { + return true; + } + + @Override + void readItemsFromJson(@NonNull JSONObject json) throws IllegalArgumentException { + } + + @Override + void writeItemsToJson(@NonNull JSONObject json) { + JSONArray jsonArray = new JSONArray(); + if (!items.isEmpty()) { + try { + for (OsmNotesPoint point : items) { + JSONObject jsonObject = new JSONObject(); + jsonObject.put("text", point.getText()); + jsonObject.put("lat", point.getLatitude()); + jsonObject.put("lon", point.getLongitude()); + jsonObject.put("action", OsmPoint.stringAction.get(point.getAction())); + jsonArray.put(jsonObject); + } + json.put("items", jsonArray); + } catch (JSONException e) { + warnings.add(app.getString(R.string.settings_item_write_error, String.valueOf(getType()))); + SettingsHelper.LOG.error("Failed write to json", e); + } + } + } + + @Nullable + @Override + SettingsItemReader getReader() { + return getJsonReader(); + } + + @Nullable + @Override + SettingsItemWriter getWriter() { + return null; + } +} diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java index 530147b84f..c8d116241c 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -21,6 +21,9 @@ import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording; import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXInfo; +import net.osmand.plus.osmedit.OpenstreetmapPoint; +import net.osmand.plus.osmedit.OsmEditingPlugin; +import net.osmand.plus.osmedit.OsmNotesPoint; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickActionRegistry; @@ -505,6 +508,17 @@ public class SettingsHelper { dataList.put(ExportSettingsType.TRACKS, files); } } + OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); + if (osmEditingPlugin != null) { + List notesPointList = osmEditingPlugin.getDBBug().getOsmbugsPoints(); + if (!notesPointList.isEmpty()) { + dataList.put(ExportSettingsType.OSM_NOTES, notesPointList); + } + List editsPointList = osmEditingPlugin.getDBPOI().getOpenstreetmapPoints(); + if (!editsPointList.isEmpty()) { + dataList.put(ExportSettingsType.OSM_EDITS, editsPointList); + } + } return dataList; } @@ -514,6 +528,9 @@ public class SettingsHelper { List poiUIFilters = new ArrayList<>(); List tileSourceTemplates = new ArrayList<>(); List avoidRoads = new ArrayList<>(); + List osmNotesPointList = new ArrayList<>(); + List osmEditsPointList = new ArrayList<>(); + for (Object object : data) { if (object instanceof QuickAction) { quickActions.add((QuickAction) object); @@ -529,6 +546,10 @@ public class SettingsHelper { } } else if (object instanceof AvoidRoadInfo) { avoidRoads.add((AvoidRoadInfo) object); + } else if (object instanceof OsmNotesPoint) { + osmNotesPointList.add((OsmNotesPoint) object); + } else if (object instanceof OpenstreetmapPoint) { + osmEditsPointList.add((OpenstreetmapPoint) object); } } if (!quickActions.isEmpty()) { @@ -543,6 +564,12 @@ public class SettingsHelper { if (!avoidRoads.isEmpty()) { settingsItems.add(new AvoidRoadsSettingsItem(app, avoidRoads)); } + if (!osmNotesPointList.isEmpty()) { + settingsItems.add(new OsmNotesSettingsItem(app, osmNotesPointList)); + } + if (!osmEditsPointList.isEmpty()) { + settingsItems.add(new OsmEditsSettingsItem(app, osmEditsPointList)); + } return settingsItems; } @@ -557,6 +584,8 @@ public class SettingsHelper { List multimediaFilesList = new ArrayList<>(); List tracksFilesList = new ArrayList<>(); List avoidRoads = new ArrayList<>(); + List notesPointList = new ArrayList<>(); + List editsPointList = new ArrayList<>(); for (SettingsItem item : settingsItems) { switch (item.getType()) { case PROFILE: @@ -606,6 +635,22 @@ public class SettingsHelper { avoidRoads.addAll(avoidRoadsItem.getItems()); } break; + case OSM_NOTES: + OsmNotesSettingsItem osmNotesSettingsItem = (OsmNotesSettingsItem) item; + if (importComplete) { + notesPointList.addAll(osmNotesSettingsItem.getAppliedItems()); + } else { + notesPointList.addAll(osmNotesSettingsItem.getItems()); + } + break; + case OSM_EDITS: + OsmEditsSettingsItem osmEditsSettingsItem = (OsmEditsSettingsItem) item; + if (importComplete) { + editsPointList.addAll(osmEditsSettingsItem.getAppliedItems()); + } else { + editsPointList.addAll(osmEditsSettingsItem.getItems()); + } + break; default: break; } @@ -638,6 +683,12 @@ public class SettingsHelper { if (!tracksFilesList.isEmpty()) { settingsToOperate.put(ExportSettingsType.TRACKS, tracksFilesList); } + if (!notesPointList.isEmpty()) { + settingsToOperate.put(ExportSettingsType.OSM_NOTES, notesPointList); + } + if (!editsPointList.isEmpty()) { + settingsToOperate.put(ExportSettingsType.OSM_NOTES, editsPointList); + } return settingsToOperate; } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java index 163e457e58..051f122c2e 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java @@ -17,5 +17,6 @@ public enum SettingsItemType { FAVORITES, TRACKS, AUDIO_VIDEO_NOTES, - OSM_CHANGES + OSM_NOTES, + OSM_EDITS } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java index eac1917850..c1ca0fb590 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java @@ -23,6 +23,9 @@ import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; import net.osmand.plus.helpers.GpxUiHelper; +import net.osmand.plus.osmedit.OpenstreetmapPoint; +import net.osmand.plus.osmedit.OsmEditingPlugin; +import net.osmand.plus.osmedit.OsmNotesPoint; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.profiles.ProfileIconColors; import net.osmand.plus.profiles.RoutingProfileDataObject.RoutingProfilesResources; @@ -153,6 +156,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { TextView title = child.findViewById(R.id.title_tv); TextView subText = child.findViewById(R.id.sub_title_tv); + subText.setVisibility(View.GONE); final CheckBox checkBox = child.findViewById(R.id.check_box); ImageView icon = child.findViewById(R.id.icon); View lineDivider = child.findViewById(R.id.divider); @@ -197,9 +201,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { LOG.error("Error trying to get routing resource for " + routingProfileValue + "\n" + e); } } - if (Algorithms.isEmpty(routingProfile)) { - subText.setVisibility(View.GONE); - } else { + if (!Algorithms.isEmpty(routingProfile)) { subText.setText(String.format( app.getString(R.string.ltr_or_rtl_combine_via_colon), app.getString(R.string.nav_type_hint), @@ -213,38 +215,32 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { case QUICK_ACTIONS: title.setText(((QuickAction) currentItem).getName(app.getApplicationContext())); setupIcon(icon, ((QuickAction) currentItem).getIconRes(), itemSelected); - subText.setVisibility(View.GONE); break; case POI_TYPES: title.setText(((PoiUIFilter) currentItem).getName()); int iconRes = RenderingIcons.getBigIconResourceId(((PoiUIFilter) currentItem).getIconId()); setupIcon(icon, iconRes != 0 ? iconRes : R.drawable.ic_action_user, itemSelected); - subText.setVisibility(View.GONE); break; case MAP_SOURCES: title.setText(((ITileSource) currentItem).getName()); setupIcon(icon, R.drawable.ic_map, itemSelected); - subText.setVisibility(View.GONE); break; case CUSTOM_RENDER_STYLE: String renderName = ((File) currentItem).getName(); renderName = renderName.replace('_', ' ').replaceAll(IndexConstants.RENDERER_INDEX_EXT, ""); title.setText(renderName); setupIcon(icon, R.drawable.ic_action_map_style, itemSelected); - subText.setVisibility(View.GONE); break; case CUSTOM_ROUTING: String routingName = ((File) currentItem).getName(); routingName = routingName.replace('_', ' ').replaceAll(".xml", ""); title.setText(routingName); setupIcon(icon, R.drawable.ic_action_route_distance, itemSelected); - subText.setVisibility(View.GONE); break; case AVOID_ROADS: AvoidRoadInfo avoidRoadInfo = (AvoidRoadInfo) currentItem; title.setText(avoidRoadInfo.name); setupIcon(icon, R.drawable.ic_action_alert, itemSelected); - subText.setVisibility(View.GONE); break; case MULTIMEDIA_NOTES: File file = (File) currentItem; @@ -254,13 +250,19 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { iconId = R.drawable.ic_action_photo_dark; } setupIcon(icon, iconId, itemSelected); - subText.setVisibility(View.GONE); break; case TRACKS: String fileName = ((File) currentItem).getName(); title.setText(GpxUiHelper.getGpxTitle(fileName)); setupIcon(icon, R.drawable.ic_action_route_distance, itemSelected); - subText.setVisibility(View.GONE); + break; + case OSM_NOTES: + title.setText(((OsmNotesPoint) currentItem).getText()); + setupIcon(icon, R.drawable.ic_action_osm_note_add, itemSelected); + break; + case OSM_EDITS: + title.setText(OsmEditingPlugin.getTitle((OpenstreetmapPoint) currentItem, app)); + setupIcon(icon, R.drawable.ic_action_info_dark, itemSelected); break; default: return child; @@ -338,6 +340,10 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { return R.string.shared_string_tracks; case MULTIMEDIA_NOTES: return R.string.audionotes_plugin_name; + case OSM_NOTES: + return R.string.osm_notes; + case OSM_EDITS: + return R.string.osm_edit_modified_poi; default: return R.string.access_empty_list; } @@ -377,4 +383,4 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { List getData() { return this.data; } -} +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java index 57198c2f04..7acd88ee4b 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportedSettingsItemsAdapter.java @@ -114,6 +114,14 @@ public class ImportedSettingsItemsAdapter extends holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_route_distance, activeColorRes)); holder.title.setText(R.string.shared_string_tracks); break; + case OSM_NOTES: + holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_osm_note_add, activeColorRes)); + holder.title.setText(R.string.osm_notes); + break; + case OSM_EDITS: + holder.icon.setImageDrawable(uiUtils.getIcon(R.drawable.ic_action_info_dark, activeColorRes)); + holder.title.setText(R.string.osm_edit_modified_poi); + break; } } From 4021d38635b9c17257a885dc9b3ff5c51b25120e Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Mon, 19 Oct 2020 18:36:13 +0300 Subject: [PATCH 2/7] Import OSM Note --- .../backend/backup/OsmEditsSettingsItem.java | 26 ++++++-- .../backend/backup/OsmNotesSettingsItem.java | 62 +++++++++++++++++-- .../backend/backup/SettingsHelper.java | 2 +- .../backend/backup/SettingsItemsFactory.java | 6 ++ .../fragments/ImportSettingsFragment.java | 28 +++++++++ 5 files changed, 115 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java index 1eb1e25393..3d84d23487 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java @@ -22,10 +22,26 @@ import java.util.List; public class OsmEditsSettingsItem extends CollectionSettingsItem { + public static final String ID_KEY = "id"; + public static final String NAME_KEY = "name"; + public static final String LAT_KEY = "lat"; + public static final String LON_KEY = "lon"; + public static final String COMMENT_KEY = "comment"; + public static final String ACTION_KEY = "action"; + public OsmEditsSettingsItem(@NonNull OsmandApplication app, @NonNull List items) { super(app, null, items); } + public OsmEditsSettingsItem(@NonNull OsmandApplication app, @Nullable OsmEditsSettingsItem baseItem, + @NonNull List items) { + super(app, baseItem, items); + } + + public OsmEditsSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException { + super(app, json); + } + @Override protected void init() { super.init(); @@ -92,10 +108,12 @@ public class OsmEditsSettingsItem extends CollectionSettingsItem { + public static final String ID_KEY = "id"; + public static final String TEXT_KEY = "text"; + public static final String LAT_KEY = "lat"; + public static final String LON_KEY = "lon"; + public static final String AUTHOR_KEY = "author"; + public static final String ACTION_KEY = "action"; + public OsmNotesSettingsItem(@NonNull OsmandApplication app, @NonNull List items) { super(app, null, items); } + public OsmNotesSettingsItem(@NonNull OsmandApplication app, @Nullable OsmNotesSettingsItem baseItem, + @NonNull List items) { + super(app, baseItem, items); + } + + public OsmNotesSettingsItem(@NonNull OsmandApplication app, @NonNull JSONObject json) throws JSONException { + super(app, json); + } + @Override protected void init() { super.init(); @@ -49,6 +66,14 @@ public class OsmNotesSettingsItem extends CollectionSettingsItem for (OsmNotesPoint duplicate : duplicateItems) { appliedItems.add(shouldReplace ? duplicate : renameItem(duplicate)); } + OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); + OsmBugsDbHelper db; + if (osmEditingPlugin != null) { + db = osmEditingPlugin.getDBBug(); + for (OsmNotesPoint point : appliedItems) { + db.addOsmbugs(point); + } + } } } @@ -82,6 +107,33 @@ public class OsmNotesSettingsItem extends CollectionSettingsItem @Override void readItemsFromJson(@NonNull JSONObject json) throws IllegalArgumentException { + try { + if (!json.has("items")) { + return; + } + JSONArray jsonArray = json.getJSONArray("items"); + for (int i = 0; i < jsonArray.length(); i++) { + JSONObject object = jsonArray.getJSONObject(i); + long id = object.getLong(ID_KEY); + String text = object.optString(TEXT_KEY); + double lat = object.getDouble(LAT_KEY); + double lon = object.getDouble(LON_KEY); + String author = object.optString(AUTHOR_KEY, null); + String action = object.getString(ACTION_KEY); + + OsmNotesPoint point = new OsmNotesPoint(); + point.setId(id); + point.setText(text); + point.setLatitude(lat); + point.setLongitude(lon); + point.setAuthor(author); + point.setAction(action); + items.add(point); + } + } catch (JSONException e) { + warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType()))); + throw new IllegalArgumentException("Json parse error", e); + } } @Override @@ -91,10 +143,12 @@ public class OsmNotesSettingsItem extends CollectionSettingsItem try { for (OsmNotesPoint point : items) { JSONObject jsonObject = new JSONObject(); - jsonObject.put("text", point.getText()); - jsonObject.put("lat", point.getLatitude()); - jsonObject.put("lon", point.getLongitude()); - jsonObject.put("action", OsmPoint.stringAction.get(point.getAction())); + jsonObject.put(ID_KEY, point.getId()); + jsonObject.put(TEXT_KEY, point.getText()); + jsonObject.put(LAT_KEY, point.getLatitude()); + jsonObject.put(LON_KEY, point.getLongitude()); + jsonObject.put(AUTHOR_KEY, point.getAuthor()); + jsonObject.put(ACTION_KEY, OsmPoint.stringAction.get(point.getAction())); jsonArray.put(jsonObject); } json.put("items", jsonArray); diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java index c8d116241c..7bcb692058 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -687,7 +687,7 @@ public class SettingsHelper { settingsToOperate.put(ExportSettingsType.OSM_NOTES, notesPointList); } if (!editsPointList.isEmpty()) { - settingsToOperate.put(ExportSettingsType.OSM_NOTES, editsPointList); + settingsToOperate.put(ExportSettingsType.OSM_EDITS, editsPointList); } return settingsToOperate; } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemsFactory.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemsFactory.java index d4a639da4d..8545b37503 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemsFactory.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemsFactory.java @@ -125,6 +125,12 @@ class SettingsItemsFactory { case DOWNLOADS: item = new DownloadsItem(app, json); break; + case OSM_NOTES: + item = new OsmNotesSettingsItem(app, json); + break; + case OSM_EDITS: + item = new OsmEditsSettingsItem(app, json); + break; } return item; } diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java index 6002c8a58e..b564f733cf 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java @@ -38,10 +38,14 @@ 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.osmedit.OpenstreetmapPoint; +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.ApplicationModeBean; import net.osmand.plus.settings.backend.ExportSettingsType; +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; @@ -374,6 +378,16 @@ public class ImportSettingsFragment extends BaseOsmAndFragment return null; } + @Nullable + private T getBaseItem(SettingsItemType settingsItemType, Class clazz) { + for (SettingsItem settingsItem : settingsItems) { + if (settingsItem.getType() == settingsItemType && clazz.isInstance(settingsItem)) { + return clazz.cast(settingsItem); + } + } + return null; + } + private List getSettingsItemsFromData(List data) { List settingsItems = new ArrayList<>(); List appModeBeans = new ArrayList<>(); @@ -381,6 +395,8 @@ public class ImportSettingsFragment extends BaseOsmAndFragment List poiUIFilters = new ArrayList<>(); List tileSourceTemplates = new ArrayList<>(); List avoidRoads = new ArrayList<>(); + List osmNotesPointList = new ArrayList<>(); + List osmEditsPointList = new ArrayList<>(); for (Object object : data) { if (object instanceof ApplicationModeBean) { appModeBeans.add((ApplicationModeBean) object); @@ -394,6 +410,10 @@ public class ImportSettingsFragment extends BaseOsmAndFragment settingsItems.add(new FileSettingsItem(app, (File) object)); } else if (object instanceof AvoidRoadInfo) { avoidRoads.add((AvoidRoadInfo) object); + } else if (object instanceof OsmNotesPoint) { + osmNotesPointList.add((OsmNotesPoint) object); + } else if (object instanceof OpenstreetmapPoint) { + osmEditsPointList.add((OpenstreetmapPoint) object); } } if (!appModeBeans.isEmpty()) { @@ -413,6 +433,14 @@ public class ImportSettingsFragment extends BaseOsmAndFragment if (!avoidRoads.isEmpty()) { settingsItems.add(new AvoidRoadsSettingsItem(app, getBaseAvoidRoadsSettingsItem(), avoidRoads)); } + if (!osmNotesPointList.isEmpty()) { + OsmNotesSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_NOTES, OsmNotesSettingsItem.class); + settingsItems.add(new OsmNotesSettingsItem(app, baseItem, osmNotesPointList)); + } + if (!osmEditsPointList.isEmpty()) { + OsmEditsSettingsItem baseItem = getBaseItem(SettingsItemType.OSM_EDITS, OsmEditsSettingsItem.class); + settingsItems.add(new OsmEditsSettingsItem(app, baseItem, osmEditsPointList)); + } return settingsItems; } From 1d6a0b39b7ca8b5e229551bdd814d54bb129c000 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 20 Oct 2020 18:48:41 +0300 Subject: [PATCH 3/7] Import OSM Edit --- .../backend/backup/OsmEditsSettingsItem.java | 70 +++++++++++-------- .../backend/backup/OsmNotesSettingsItem.java | 4 +- .../fragments/ImportCompleteFragment.java | 10 +++ 3 files changed, 54 insertions(+), 30 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java index 3d84d23487..f0af94a009 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java @@ -6,6 +6,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import net.osmand.osm.edit.Entity; +import net.osmand.osm.edit.Node; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; @@ -28,6 +29,9 @@ public class OsmEditsSettingsItem extends CollectionSettingsItem items) { super(app, null, items); @@ -99,6 +103,32 @@ public class OsmEditsSettingsItem extends CollectionSettingsItem getReader() { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmNotesSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmNotesSettingsItem.java index 3288aa5a20..c90e44b45e 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmNotesSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmNotesSettingsItem.java @@ -118,9 +118,9 @@ public class OsmNotesSettingsItem extends CollectionSettingsItem String text = object.optString(TEXT_KEY); double lat = object.getDouble(LAT_KEY); double lon = object.getDouble(LON_KEY); - String author = object.optString(AUTHOR_KEY, null); + String author = object.optString(AUTHOR_KEY); + author = author.isEmpty() ? null : author; String action = object.getString(ACTION_KEY); - OsmNotesPoint point = new OsmNotesPoint(); point.setId(id); point.setText(text); diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportCompleteFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportCompleteFragment.java index 27278775f0..f11df23d09 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportCompleteFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportCompleteFragment.java @@ -1,6 +1,7 @@ package net.osmand.plus.settings.fragments; import android.app.Activity; +import android.content.Intent; import android.graphics.Typeface; import android.os.Build; import android.os.Bundle; @@ -31,6 +32,7 @@ import net.osmand.plus.quickaction.QuickActionListFragment; import net.osmand.plus.routepreparationmenu.AvoidRoadsBottomSheetDialogFragment; import net.osmand.plus.search.QuickSearchDialogFragment; import net.osmand.plus.settings.backend.ExportSettingsType; +import net.osmand.plus.settings.backend.OsmAndAppCustomization; import net.osmand.plus.settings.backend.backup.SettingsHelper; import net.osmand.plus.settings.backend.backup.SettingsItem; @@ -187,6 +189,14 @@ public class ImportCompleteFragment extends BaseOsmAndFragment { case AVOID_ROADS: new AvoidRoadsBottomSheetDialogFragment().show(fm, AvoidRoadsBottomSheetDialogFragment.TAG); break; + case OSM_NOTES: + case OSM_EDITS: + OsmAndAppCustomization appCustomization = app.getAppCustomization(); + final Intent favorites = new Intent(activity, appCustomization.getFavoritesActivity()); + favorites.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); + app.getSettings().FAVORITES_TAB.set(R.string.osm_edits); + startActivity(favorites); + break; default: break; } From d89d48474ad37ab00dc0016234c3369b7587a2f5 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Wed, 21 Oct 2020 15:41:36 +0300 Subject: [PATCH 4/7] Import OSM Edit tags --- .../backend/backup/OsmEditsSettingsItem.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java index f0af94a009..e2c06d14d6 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java @@ -5,12 +5,16 @@ import android.content.Context; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + import net.osmand.osm.edit.Entity; import net.osmand.osm.edit.Node; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.osmedit.OpenstreetmapPoint; +import net.osmand.plus.osmedit.OpenstreetmapsDbHelper; import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmedit.OsmPoint; @@ -19,7 +23,9 @@ import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class OsmEditsSettingsItem extends CollectionSettingsItem { @@ -71,6 +77,14 @@ public class OsmEditsSettingsItem extends CollectionSettingsItem tagMap = new Gson().fromJson( + tags, new TypeToken>() { + }.getType() + ); String action = entityJson.getString(ACTION_KEY); Entity entity; entity = new Node(lat, lon, id); + entity.replaceTags(tagMap); OpenstreetmapPoint point = new OpenstreetmapPoint(); point.setComment(comment); point.setEntity(entity); @@ -144,7 +164,8 @@ public class OsmEditsSettingsItem extends CollectionSettingsItem Date: Thu, 22 Oct 2020 11:29:41 +0300 Subject: [PATCH 5/7] Import/export offline maps --- .../settings/backend/ExportSettingsType.java | 3 +- .../backend/backup/SettingsHelper.java | 30 +++++++++++++ .../backend/backup/SettingsItemType.java | 3 +- .../ExportImportSettingsAdapter.java | 7 +++ .../fragments/ImportSettingsFragment.java | 43 +++++++++++++++++++ 5 files changed, 84 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java b/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java index 1b4231b873..d6718d9579 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/ExportSettingsType.java @@ -13,5 +13,6 @@ public enum ExportSettingsType { TRACKS, MULTIMEDIA_NOTES, OSM_NOTES, - OSM_EDITS + OSM_EDITS, + OFFLINE_MAPS } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java index 7bcb692058..e7d30ce30f 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -16,8 +16,11 @@ import net.osmand.map.TileSourceManager.TileSourceTemplate; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.SQLiteTileSource; +import net.osmand.plus.activities.LocalIndexHelper; +import net.osmand.plus.activities.LocalIndexInfo; import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording; +import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask; import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXInfo; @@ -519,9 +522,30 @@ public class SettingsHelper { dataList.put(ExportSettingsType.OSM_EDITS, editsPointList); } } + List files = getLocalMapFiles(); + if (!files.isEmpty()) { + dataList.put(ExportSettingsType.OFFLINE_MAPS, files); + } return dataList; } + private List getLocalMapFiles() { + List files = new ArrayList<>(); + LocalIndexHelper helper = new LocalIndexHelper(app); + List localMapFileList = helper.getLocalFullMaps(new AbstractLoadLocalIndexTask() { + @Override + public void loadFile(LocalIndexInfo... loaded) { + } + }); + for (LocalIndexInfo map : localMapFileList) { + File file = new File(map.getPathToData()); + if (file != null && file.exists()) { + files.add(file); + } + } + return files; + } + public List prepareAdditionalSettingsItems(List data) { List settingsItems = new ArrayList<>(); List quickActions = new ArrayList<>(); @@ -583,6 +607,7 @@ public class SettingsHelper { List renderFilesList = new ArrayList<>(); List multimediaFilesList = new ArrayList<>(); List tracksFilesList = new ArrayList<>(); + List mapFilesList = new ArrayList<>(); List avoidRoads = new ArrayList<>(); List notesPointList = new ArrayList<>(); List editsPointList = new ArrayList<>(); @@ -601,6 +626,8 @@ public class SettingsHelper { multimediaFilesList.add(fileItem.getFile()); } else if (fileItem.getSubtype() == FileSettingsItem.FileSubtype.GPX) { tracksFilesList.add(fileItem.getFile()); + } else if (fileItem.getSubtype() == FileSettingsItem.FileSubtype.OBF_MAP) { + mapFilesList.add(fileItem.getFile()); } break; case QUICK_ACTIONS: @@ -689,6 +716,9 @@ public class SettingsHelper { if (!editsPointList.isEmpty()) { settingsToOperate.put(ExportSettingsType.OSM_EDITS, editsPointList); } + if (!mapFilesList.isEmpty()) { + settingsToOperate.put(ExportSettingsType.OFFLINE_MAPS, mapFilesList); + } return settingsToOperate; } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java index 051f122c2e..d931e5a5c4 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java @@ -18,5 +18,6 @@ public enum SettingsItemType { TRACKS, AUDIO_VIDEO_NOTES, OSM_NOTES, - OSM_EDITS + OSM_EDITS, + OFFLINE_MAPS } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java index c1ca0fb590..8fa7c93a14 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java @@ -264,6 +264,11 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { title.setText(OsmEditingPlugin.getTitle((OpenstreetmapPoint) currentItem, app)); setupIcon(icon, R.drawable.ic_action_info_dark, itemSelected); break; + case OFFLINE_MAPS: + file = (File) currentItem; + title.setText(file.getName()); + setupIcon(icon, R.drawable.ic_map, itemSelected); + break; default: return child; } @@ -344,6 +349,8 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { return R.string.osm_notes; case OSM_EDITS: return R.string.osm_edit_modified_poi; + case OFFLINE_MAPS: + return R.string.download_regular_maps; default: return R.string.access_empty_list; } diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java index b564f733cf..52a85fee11 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java @@ -4,6 +4,7 @@ import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.graphics.Typeface; +import android.os.AsyncTask; import android.os.Build; import android.os.Bundle; import android.text.style.StyleSpan; @@ -27,6 +28,7 @@ import androidx.fragment.app.FragmentManager; import com.google.android.material.appbar.CollapsingToolbarLayout; import net.osmand.AndroidUtils; +import net.osmand.IProgress; import net.osmand.PlatformUtil; import net.osmand.map.ITileSource; import net.osmand.map.TileSourceManager.TileSourceTemplate; @@ -63,11 +65,14 @@ import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; import java.io.File; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import static net.osmand.plus.settings.backend.backup.FileSettingsItem.FileSubtype.*; + public class ImportSettingsFragment extends BaseOsmAndFragment implements View.OnClickListener { @@ -271,6 +276,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment if (succeed) { app.getRendererRegistry().updateExternalRenderers(); AppInitializer.loadRoutingFiles(app, null); + reloadIndexes(items); if (fm != null && file != null) { ImportCompleteFragment.showInstance(fm, items, file.getName()); } @@ -279,6 +285,43 @@ public class ImportSettingsFragment extends BaseOsmAndFragment }; } + private void reloadIndexes(@NonNull List items) { + for (SettingsItem item : items) { + if (item instanceof FileSettingsItem && ((FileSettingsItem) item).getSubtype() == OBF_MAP) { + Activity activity = getActivity(); + if (activity instanceof MapActivity) { + new ReloadIndexesTack((MapActivity) activity).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + break; + } + } + } + + private static class ReloadIndexesTack extends AsyncTask { + + private final WeakReference mapActivityRef; + private final OsmandApplication app; + + ReloadIndexesTack(@NonNull MapActivity mapActivity) { + this.mapActivityRef = new WeakReference<>(mapActivity); + this.app = mapActivity.getMyApplication(); + } + + @Override + protected Void doInBackground(Void[] params) { + app.getResourceManager().reloadIndexes(IProgress.EMPTY_PROGRESS, new ArrayList()); + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + MapActivity mapActivity = mapActivityRef.get(); + if (mapActivity != null) { + mapActivity.refreshMap(); + } + } + } + private SettingsHelper.CheckDuplicatesListener getDuplicatesListener() { return new SettingsHelper.CheckDuplicatesListener() { @Override From cab7484e4aadb2d1298047b6b6c3631f9ff3f970 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 27 Oct 2020 21:39:45 +0200 Subject: [PATCH 6/7] Export/import all offline maps --- OsmAnd/res/values/strings.xml | 1 + .../backend/backup/FileSettingsItem.java | 25 +++++++++++- .../backend/backup/SettingsHelper.java | 14 ++++--- .../backend/backup/SettingsImporter.java | 22 +++++++++- .../ExportImportSettingsAdapter.java | 40 +++++++++++++++---- .../fragments/ImportSettingsFragment.java | 2 + 6 files changed, 90 insertions(+), 14 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index a30f9c4fc5..cd0d9dd2b0 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -11,6 +11,7 @@ Thx - Hardy --> + Local maps Wait for the route recalculation.\nGraph will be available after recalculation. %1$s data available only on the roads, you need to calculate a route using “Route between points” to get it. Graph diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/FileSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/FileSettingsItem.java index 357c0aadbf..6afddc9664 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/FileSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/FileSettingsItem.java @@ -21,11 +21,15 @@ import java.io.OutputStream; public class FileSettingsItem extends StreamSettingsItem { + + public enum FileSubtype { UNKNOWN("", null), OTHER("other", ""), ROUTING_CONFIG("routing_config", IndexConstants.ROUTING_PROFILES_DIR), RENDERING_STYLE("rendering_style", IndexConstants.RENDERERS_DIR), + WIKI_MAP("wiki_map", IndexConstants.WIKI_INDEX_DIR), + SRTM_MAP("srtm_map", IndexConstants.SRTM_INDEX_DIR), OBF_MAP("obf_map", IndexConstants.MAPS_PATH), TILES_MAP("tiles_map", IndexConstants.TILES_INDEX_DIR), GPX("gpx", IndexConstants.GPX_INDEX_DIR), @@ -68,8 +72,18 @@ public class FileSettingsItem extends StreamSettingsItem { case UNKNOWN: case OTHER: break; + case SRTM_MAP: + if (name.endsWith(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)) { + return subtype; + } + break; + case WIKI_MAP: + if (name.endsWith(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT)) { + return subtype; + } + break; case OBF_MAP: - if (name.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT)) { + if (name.endsWith(IndexConstants.BINARY_MAP_INDEX_EXT) && !name.contains(File.separator)) { return subtype; } break; @@ -93,6 +107,7 @@ public class FileSettingsItem extends StreamSettingsItem { protected File file; private File appPath; protected FileSubtype subtype; + private long size; public FileSettingsItem(@NonNull OsmandApplication app, @NonNull File file) throws IllegalArgumentException { super(app, file.getPath().replace(app.getAppPath(null).getPath(), "")); @@ -171,6 +186,14 @@ public class FileSettingsItem extends StreamSettingsItem { } } + public long getSize() { + return size; + } + + public void setSize(long size) { + this.size = size; + } + @NonNull public File getFile() { return file; diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java index e7d30ce30f..df44ee2337 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsHelper.java @@ -46,6 +46,7 @@ import java.util.Map; import java.util.Set; import static net.osmand.IndexConstants.OSMAND_SETTINGS_FILE_EXT; +import static net.osmand.plus.activities.LocalIndexHelper.*; /* Usage: @@ -532,14 +533,14 @@ public class SettingsHelper { private List getLocalMapFiles() { List files = new ArrayList<>(); LocalIndexHelper helper = new LocalIndexHelper(app); - List localMapFileList = helper.getLocalFullMaps(new AbstractLoadLocalIndexTask() { + List localMapFileList = helper.getLocalIndexData(new AbstractLoadLocalIndexTask() { @Override public void loadFile(LocalIndexInfo... loaded) { } }); for (LocalIndexInfo map : localMapFileList) { File file = new File(map.getPathToData()); - if (file != null && file.exists()) { + if (file != null && file.exists() && map.getType() != LocalIndexType.TTS_VOICE_DATA) { files.add(file); } } @@ -607,7 +608,7 @@ public class SettingsHelper { List renderFilesList = new ArrayList<>(); List multimediaFilesList = new ArrayList<>(); List tracksFilesList = new ArrayList<>(); - List mapFilesList = new ArrayList<>(); + List mapFilesList = new ArrayList<>(); List avoidRoads = new ArrayList<>(); List notesPointList = new ArrayList<>(); List editsPointList = new ArrayList<>(); @@ -626,8 +627,11 @@ public class SettingsHelper { multimediaFilesList.add(fileItem.getFile()); } else if (fileItem.getSubtype() == FileSettingsItem.FileSubtype.GPX) { tracksFilesList.add(fileItem.getFile()); - } else if (fileItem.getSubtype() == FileSettingsItem.FileSubtype.OBF_MAP) { - mapFilesList.add(fileItem.getFile()); + } else if (fileItem.getSubtype() == FileSettingsItem.FileSubtype.OBF_MAP + || fileItem.getSubtype() == FileSettingsItem.FileSubtype.WIKI_MAP + || fileItem.getSubtype() == FileSettingsItem.FileSubtype.SRTM_MAP + || fileItem.getSubtype() == FileSettingsItem.FileSubtype.TILES_MAP) { + mapFilesList.add(fileItem); } break; case QUICK_ACTIONS: diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsImporter.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsImporter.java index a06b8e8749..c9eb980b9d 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsImporter.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsImporter.java @@ -15,8 +15,10 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; +import java.util.Enumeration; import java.util.List; import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; import java.util.zip.ZipInputStream; import static net.osmand.IndexConstants.OSMAND_SETTINGS_FILE_EXT; @@ -57,7 +59,9 @@ class SettingsImporter { } try { SettingsItemsFactory itemsFactory = new SettingsItemsFactory(app, itemsJson); - items.addAll(itemsFactory.getItems()); + List settingsItemList = itemsFactory.getItems(); + getFilesSize(file, settingsItemList); + items.addAll(settingsItemList); } catch (IllegalArgumentException e) { SettingsHelper.LOG.error("Error parsing items: " + itemsJson, e); throw new IllegalArgumentException("No items"); @@ -77,6 +81,22 @@ class SettingsImporter { return items; } + private void getFilesSize(@NonNull File file, List settingsItemList) throws IOException { + ZipFile zipfile = new ZipFile(file.getPath()); + Enumeration zipEnum = zipfile.entries(); + while (zipEnum.hasMoreElements()) { + ZipEntry zipEntry = zipEnum.nextElement(); + int size = (int) zipEntry.getSize(); + for (SettingsItem settingsItem : settingsItemList) { + if (settingsItem instanceof FileSettingsItem + && zipEntry.getName().equals(settingsItem.getFileName())) { + ((FileSettingsItem) settingsItem).setSize(size); + break; + } + } + } + } + private List processItems(@NonNull File file, @Nullable List items) throws IllegalArgumentException, IOException { boolean collecting = items == null; if (collecting) { diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java index 8fa7c93a14..ea702e8c85 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java @@ -22,6 +22,7 @@ import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.OsmandBaseExpandableListAdapter; 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.osmedit.OpenstreetmapPoint; import net.osmand.plus.osmedit.OsmEditingPlugin; @@ -34,6 +35,7 @@ import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.ApplicationMode.ApplicationModeBean; import net.osmand.plus.settings.backend.ExportSettingsType; +import net.osmand.plus.settings.backend.backup.FileSettingsItem; import net.osmand.util.Algorithms; import net.osmand.view.ThreeStateCheckbox; @@ -46,6 +48,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import static net.osmand.plus.settings.backend.ExportSettingsType.*; +import static net.osmand.plus.settings.backend.backup.FileSettingsItem.*; import static net.osmand.view.ThreeStateCheckbox.State.CHECKED; import static net.osmand.view.ThreeStateCheckbox.State.MISC; import static net.osmand.view.ThreeStateCheckbox.State.UNCHECKED; @@ -105,7 +109,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { cardBottomDivider.setVisibility(importState && !isExpanded ? View.VISIBLE : View.GONE); final List listItems = itemsMap.get(type); - subTextTv.setText(getSelectedItemsAmount(listItems)); + subTextTv.setText(getSelectedItemsAmount(listItems, type)); if (data.containsAll(listItems)) { checkBox.setState(CHECKED); @@ -265,9 +269,25 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { setupIcon(icon, R.drawable.ic_action_info_dark, itemSelected); break; case OFFLINE_MAPS: - file = (File) currentItem; - title.setText(file.getName()); - setupIcon(icon, R.drawable.ic_map, itemSelected); + FileSettingsItem currentFileItem = (FileSettingsItem) currentItem; + file = currentFileItem.getFile(); + title.setText(FileNameTranslationHelper.getFileName(app, + app.getResourceManager().getOsmandRegions(), + file.getName())); + FileSubtype subtype = FileSubtype.getSubtypeByFileName(file.getPath().replace(app.getAppPath(null).getPath(), "")); + switch (subtype) { + case SRTM_MAP: + iconId = R.drawable.ic_plugin_srtm; + break; + case WIKI_MAP: + iconId = R.drawable.ic_plugin_wikipedia; + break; + default: + iconId = R.drawable.ic_map; + } + setupIcon(icon, iconId, itemSelected); + subText.setText(AndroidUtils.formatSize(app, currentFileItem.getSize())); + subText.setVisibility(View.VISIBLE); break; default: return child; @@ -315,14 +335,20 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { return true; } - private String getSelectedItemsAmount(List listItems) { + private String getSelectedItemsAmount(List listItems, ExportSettingsType type) { int amount = 0; + long amountSize = 0; for (Object item : listItems) { if (data.contains(item)) { amount++; + if (type == OFFLINE_MAPS && item instanceof FileSettingsItem) { + amountSize += ((FileSettingsItem) item).getSize(); + } } } - return app.getString(R.string.n_items_of_z, String.valueOf(amount), String.valueOf(listItems.size())); + String itemsOf = app.getString(R.string.n_items_of_z, String.valueOf(amount), String.valueOf(listItems.size())); + return amountSize == 0 ? itemsOf : app.getString(R.string.ltr_or_rtl_combine_via_bold_point, itemsOf, + AndroidUtils.formatSize(app, amountSize)); } private int getGroupTitle(ExportSettingsType type) { @@ -350,7 +376,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { case OSM_EDITS: return R.string.osm_edit_modified_poi; case OFFLINE_MAPS: - return R.string.download_regular_maps; + return R.string.shared_string_local_maps; default: return R.string.access_empty_list; } diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java index 52a85fee11..46752fd758 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java @@ -451,6 +451,8 @@ public class ImportSettingsFragment extends BaseOsmAndFragment tileSourceTemplates.add((ITileSource) object); } else if (object instanceof File) { settingsItems.add(new FileSettingsItem(app, (File) object)); + } else if (object instanceof FileSettingsItem) { + settingsItems.add((FileSettingsItem) object); } else if (object instanceof AvoidRoadInfo) { avoidRoads.add((AvoidRoadInfo) object); } else if (object instanceof OsmNotesPoint) { From 890d41a56fe6452d75f7c8322eef310863b873e6 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Wed, 28 Oct 2020 21:11:06 +0200 Subject: [PATCH 7/7] Fix review --- .../net/osmand/plus/osmedit/AddPOIAction.java | 4 ++-- .../plus/osmedit/AdvancedEditPoiFragment.java | 7 +++--- .../plus/osmedit/EditPOIMenuBuilder.java | 9 ++++--- .../plus/osmedit/EditPOIMenuController.java | 4 +++- .../net/osmand/plus/osmedit/EditPoiData.java | 24 +++++++++---------- .../plus/osmedit/EditPoiDialogFragment.java | 14 ++++++----- .../plus/osmedit/OpenstreetmapLocalUtil.java | 4 +++- .../plus/osmedit/OpenstreetmapPoint.java | 2 +- .../plus/osmedit/OpenstreetmapRemoteUtil.java | 13 +++++----- .../osmand/plus/osmedit/OsmEditingPlugin.java | 3 ++- .../osmand/plus/osmedit/OsmEditsAdapter.java | 3 ++- .../osmand/plus/osmedit/OsmEditsLayer.java | 2 +- .../dialogs/SendPoiDialogFragment.java | 4 ++-- .../backend/backup/FileSettingsItem.java | 4 ++++ .../backend/backup/OsmEditsSettingsItem.java | 12 +++++++--- .../backend/backup/OsmNotesSettingsItem.java | 3 +-- .../backend/backup/SettingsImporter.java | 2 +- .../backend/backup/SettingsItemType.java | 5 ---- .../ExportImportSettingsAdapter.java | 16 +++++++++---- .../fragments/ImportSettingsFragment.java | 5 +--- 20 files changed, 81 insertions(+), 59 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/AddPOIAction.java b/OsmAnd/src/net/osmand/plus/osmedit/AddPOIAction.java index 81462b1d4d..1db6bd0542 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/AddPOIAction.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/AddPOIAction.java @@ -58,7 +58,7 @@ import java.util.List; import java.util.Map; import static net.osmand.plus.osmedit.AdvancedEditPoiFragment.addPoiToStringSet; -import static net.osmand.plus.osmedit.EditPoiData.POI_TYPE_TAG; +import static net.osmand.osm.edit.Entity.POI_TYPE_TAG; public class AddPOIAction extends QuickAction { public static final QuickActionType TYPE = new QuickActionType(13, @@ -140,7 +140,7 @@ public class AddPOIAction extends QuickAction { Node newNode = new Node(node.getLatitude(), node.getLongitude(), node.getId()); OsmPoint.Action action = newNode.getId() < 0 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY; for (Map.Entry tag : editPoiData.getTagValues().entrySet()) { - if (tag.getKey().equals(EditPoiData.POI_TYPE_TAG)) { + if (tag.getKey().equals(POI_TYPE_TAG)) { final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(tag.getValue().trim().toLowerCase()); if (poiType != null) { newNode.putTagNoLC(poiType.getEditOsmTag(), poiType.getEditOsmValue()); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java index 3eabf35f6c..b538ccd0c5 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/AdvancedEditPoiFragment.java @@ -28,6 +28,7 @@ import net.osmand.osm.MapPoiTypes; import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiFilter; import net.osmand.osm.PoiType; +import net.osmand.osm.edit.Entity; import net.osmand.osm.edit.OSMSettings; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -112,7 +113,7 @@ public class AdvancedEditPoiFragment extends BaseOsmAndFragment if (Algorithms.objectEquals(anyTag, OSMSettings.OSMTagKey.NAME.getValue())) { updateName(); } - if (Algorithms.objectEquals(anyTag, EditPoiData.POI_TYPE_TAG)) { + if (Algorithms.objectEquals(anyTag, Entity.POI_TYPE_TAG)) { updatePoiType(); } } @@ -197,9 +198,9 @@ public class AdvancedEditPoiFragment extends BaseOsmAndFragment currentPoiTypeKey = pt.getEditOsmTag(); } for (Entry tag : editPoiData.getTagValues().entrySet()) { - if (tag.getKey().equals(EditPoiData.POI_TYPE_TAG) + if (tag.getKey().equals(Entity.POI_TYPE_TAG) || tag.getKey().equals(OSMSettings.OSMTagKey.NAME.getValue()) - || tag.getKey().startsWith(EditPoiData.REMOVE_TAG_PREFIX) + || tag.getKey().startsWith(Entity.REMOVE_TAG_PREFIX) || tag.getKey().equals(currentPoiTypeKey)) continue; addTagView(tag.getKey(), tag.getValue()); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuBuilder.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuBuilder.java index 9a47563fe4..eb2b7b8c2b 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuBuilder.java @@ -5,6 +5,7 @@ import android.view.View; import androidx.annotation.NonNull; import net.osmand.osm.PoiType; +import net.osmand.osm.edit.Entity; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MenuBuilder; @@ -12,6 +13,8 @@ import net.osmand.plus.render.RenderingIcons; import java.util.Map; +import static net.osmand.osm.edit.Entity.POI_TYPE_TAG; + public class EditPOIMenuBuilder extends MenuBuilder { private final OsmPoint osmPoint; @@ -38,7 +41,7 @@ public class EditPOIMenuBuilder extends MenuBuilder { OpenstreetmapPoint point = (OpenstreetmapPoint) osmPoint; for (Map.Entry e : point.getEntity().getTags().entrySet()) { - if (EditPoiData.POI_TYPE_TAG.equals(e.getKey())) { + if (POI_TYPE_TAG.equals(e.getKey())) { String poiTranslation = e.getValue(); Map poiTypeMap = app.getPoiTypes().getAllTranslatedNames(false); PoiType poiType = poiTypeMap.get(poiTranslation.toLowerCase()); @@ -63,8 +66,8 @@ public class EditPOIMenuBuilder extends MenuBuilder { } for (Map.Entry e : point.getEntity().getTags().entrySet()) { - if (EditPoiData.POI_TYPE_TAG.equals(e.getKey()) || - e.getKey().startsWith(EditPoiData.REMOVE_TAG_PREFIX)) { + if (POI_TYPE_TAG.equals(e.getKey()) || + e.getKey().startsWith(Entity.REMOVE_TAG_PREFIX)) { continue; } String text = e.getKey() + "=" + e.getValue(); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java index 7d04c73252..8134e5a3be 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPOIMenuController.java @@ -18,6 +18,8 @@ import net.osmand.util.Algorithms; import java.util.Map; +import static net.osmand.osm.edit.Entity.POI_TYPE_TAG; + public class EditPOIMenuController extends MenuController { private OsmPoint osmPoint; @@ -166,7 +168,7 @@ public class EditPOIMenuController extends MenuController { if (osmPoint.getGroup() == OsmPoint.Group.POI) { OpenstreetmapPoint osmP = (OpenstreetmapPoint) osmPoint; int iconResId = 0; - String poiTranslation = osmP.getEntity().getTag(EditPoiData.POI_TYPE_TAG); + String poiTranslation = osmP.getEntity().getTag(POI_TYPE_TAG); MapActivity mapActivity = getMapActivity(); if (poiTranslation != null && mapActivity != null) { Map poiTypeMap = mapActivity.getMyApplication().getPoiTypes().getAllTranslatedNames(false); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiData.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiData.java index b11c828436..7dab7780b0 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiData.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiData.java @@ -17,15 +17,15 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; +import static net.osmand.osm.edit.Entity.POI_TYPE_TAG; + public class EditPoiData { private static final Log LOG = PlatformUtil.getLog(EditPoiData.class); private Set mListeners = new HashSet<>(); - private LinkedHashMap tagValues = new LinkedHashMap(); + private final LinkedHashMap tagValues = new LinkedHashMap(); private boolean isInEdit = false; private Entity entity; - - public static final String POI_TYPE_TAG = "poi_type_tag"; - public static final String REMOVE_TAG_PREFIX = "----"; + public static final String REMOVE_TAG_VALUE = "DELETE"; private boolean hasChangesBeenMade = false; private Map allTranslatedSubTypes; @@ -123,7 +123,7 @@ public class EditPoiData { checkNotInEdit(); try { isInEdit = true; - tagValues.remove(REMOVE_TAG_PREFIX+tag); + tagValues.remove(Entity.REMOVE_TAG_PREFIX + tag); String oldValue = tagValues.get(tag); if (oldValue == null || !oldValue.equals(value)) { changedTags.add(tag); @@ -154,9 +154,9 @@ public class EditPoiData { public void removeTag(String tag) { checkNotInEdit(); - try { + try { isInEdit = true; - tagValues.put(REMOVE_TAG_PREFIX+tag, REMOVE_TAG_VALUE); + tagValues.put(Entity.REMOVE_TAG_PREFIX + tag, REMOVE_TAG_VALUE); tagValues.remove(tag); changedTags.remove(tag); notifyDatasetChanged(tag); @@ -216,7 +216,7 @@ public class EditPoiData { PoiType pt = getPoiTypeDefined(); String editOsmTag = pt != null ? pt.getEditOsmTag() : null; if (editOsmTag != null) { - removeTypeTagWithPrefix(!tagValues.containsKey(REMOVE_TAG_PREFIX + editOsmTag)); + removeTypeTagWithPrefix(!tagValues.containsKey(Entity.REMOVE_TAG_PREFIX + editOsmTag)); currentPoiType = pt; String tagVal = pt.getEditOsmValue() != null ? pt.getEditOsmValue() : ""; tagValues.put(editOsmTag, tagVal); @@ -237,11 +237,11 @@ public class EditPoiData { private void removeTypeTagWithPrefix(boolean needRemovePrefix) { if (currentPoiType != null) { if (needRemovePrefix) { - tagValues.put(REMOVE_TAG_PREFIX + currentPoiType.getEditOsmTag(), REMOVE_TAG_VALUE); - tagValues.put(REMOVE_TAG_PREFIX + currentPoiType.getOsmTag2(), REMOVE_TAG_VALUE); + tagValues.put(Entity.REMOVE_TAG_PREFIX + currentPoiType.getEditOsmTag(), REMOVE_TAG_VALUE); + tagValues.put(Entity.REMOVE_TAG_PREFIX + currentPoiType.getOsmTag2(), REMOVE_TAG_VALUE); } else { - tagValues.remove(REMOVE_TAG_PREFIX + currentPoiType.getEditOsmTag()); - tagValues.remove(REMOVE_TAG_PREFIX + currentPoiType.getOsmTag2()); + tagValues.remove(Entity.REMOVE_TAG_PREFIX + currentPoiType.getEditOsmTag()); + tagValues.remove(Entity.REMOVE_TAG_PREFIX + currentPoiType.getOsmTag2()); } removeCurrentTypeTag(); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java index 7c0edb7168..ecdc776c78 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/EditPoiDialogFragment.java @@ -90,6 +90,8 @@ import java.util.Set; import studio.carbonylgroup.textfieldboxes.ExtendedEditText; +import static net.osmand.osm.edit.Entity.POI_TYPE_TAG; + public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { public static final String TAG = EditPoiDialogFragment.class.getSimpleName(); private static final Log LOG = PlatformUtil.getLog(EditPoiDialogFragment.class); @@ -499,21 +501,21 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { Action action = entity.getId() < 0 ? Action.CREATE : Action.MODIFY; for (Map.Entry tag : editPoiData.getTagValues().entrySet()) { - if (!Algorithms.isEmpty(tag.getKey()) && !Algorithms.isEmpty(tag.getValue()) && - !tag.getKey().equals(EditPoiData.POI_TYPE_TAG)) { + if (!Algorithms.isEmpty(tag.getKey()) && !Algorithms.isEmpty(tag.getValue()) && + !tag.getKey().equals(POI_TYPE_TAG)) { entity.putTagNoLC(tag.getKey(), tag.getValue()); } } - String poiTypeTag = editPoiData.getTagValues().get(EditPoiData.POI_TYPE_TAG); + String poiTypeTag = editPoiData.getTagValues().get(POI_TYPE_TAG); String comment = ""; if (poiTypeTag != null) { final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(poiTypeTag.trim().toLowerCase()); if (poiType != null) { entity.putTagNoLC(poiType.getEditOsmTag(), poiType.getEditOsmValue()); - entity.removeTag(EditPoiData.REMOVE_TAG_PREFIX + poiType.getEditOsmTag()); + entity.removeTag(Entity.REMOVE_TAG_PREFIX + poiType.getEditOsmTag()); if (poiType.getOsmTag2() != null) { entity.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2()); - entity.removeTag(EditPoiData.REMOVE_TAG_PREFIX + poiType.getOsmTag2()); + entity.removeTag(Entity.REMOVE_TAG_PREFIX + poiType.getOsmTag2()); } } else if (!Algorithms.isEmpty(poiTypeTag)) { PoiCategory category = editPoiData.getPoiCategory(); @@ -522,7 +524,7 @@ public class EditPoiDialogFragment extends BaseOsmAndDialogFragment { } } if (offlineEdit && !Algorithms.isEmpty(poiTypeTag)) { - entity.putTagNoLC(EditPoiData.POI_TYPE_TAG, poiTypeTag); + entity.putTagNoLC(POI_TYPE_TAG, poiTypeTag); } String actionString = action == Action.CREATE ? getString(R.string.default_changeset_add) : getString(R.string.default_changeset_edit); comment = actionString + " " + poiTypeTag; diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java index c55e2099ed..26eda5f4e5 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapLocalUtil.java @@ -24,6 +24,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import static net.osmand.osm.edit.Entity.POI_TYPE_TAG; + public class OpenstreetmapLocalUtil implements OpenstreetmapUtil { public final static Log LOG = PlatformUtil.getLog(OpenstreetmapLocalUtil.class); @@ -122,7 +124,7 @@ public class OpenstreetmapLocalUtil implements OpenstreetmapUtil { entity = new Node(loc.getLatitude(), loc.getLongitude(), entityId); } if (poiType != null) { - entity.putTagNoLC(EditPoiData.POI_TYPE_TAG, poiType.getTranslation()); + entity.putTagNoLC(POI_TYPE_TAG, poiType.getTranslation()); if (poiType.getOsmTag2() != null) { entity.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2()); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapPoint.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapPoint.java index 7e7a35d6f1..d7c17c1ec2 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapPoint.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapPoint.java @@ -28,7 +28,7 @@ public class OpenstreetmapPoint extends OsmPoint { String type = "amenity"; for (String k : entity.getTagKeySet()) { if (!OSMTagKey.NAME.getValue().equals(k) && !OSMTagKey.OPENING_HOURS.getValue().equals(k) && - !k.startsWith(EditPoiData.REMOVE_TAG_PREFIX)) { + !k.startsWith(Entity.REMOVE_TAG_PREFIX)) { type = k; break; } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java index b90a22c0b9..8940093c19 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OpenstreetmapRemoteUtil.java @@ -39,7 +39,8 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; -import java.util.concurrent.ExecutionException; + +import static net.osmand.osm.edit.Entity.POI_TYPE_TAG; public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil { @@ -273,8 +274,8 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil { throws IllegalArgumentException, IllegalStateException, IOException { for (String k : entity.getTagKeySet()) { String val = entity.getTag(k); - if (val.length() == 0 || k.length() == 0 || EditPoiData.POI_TYPE_TAG.equals(k) || - k.startsWith(EditPoiData.REMOVE_TAG_PREFIX) || k.contains(EditPoiData.REMOVE_TAG_PREFIX)) + if (val.length() == 0 || k.length() == 0 || POI_TYPE_TAG.equals(k) || + k.startsWith(Entity.REMOVE_TAG_PREFIX) || k.contains(Entity.REMOVE_TAG_PREFIX)) continue; ser.startTag(null, "tag"); //$NON-NLS-1$ ser.attribute(null, "k", k); //$NON-NLS-1$ @@ -455,7 +456,7 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil { } private boolean deletedTag(Entity entity, String tag) { - return entity.getTagKeySet().contains(EditPoiData.REMOVE_TAG_PREFIX + tag); + return entity.getTagKeySet().contains(Entity.REMOVE_TAG_PREFIX + tag); } @Override @@ -542,12 +543,12 @@ public class OpenstreetmapRemoteUtil implements OpenstreetmapUtil { PoiType poiType = type.getPoiTypeByKeyName(subType); if (poiType != null && poiType.getEditOsmValue().equals(entity.getTag(poiType.getEditOsmTag()))) { entity.removeTag(poiType.getEditOsmTag()); - entity.putTagNoLC(EditPoiData.POI_TYPE_TAG, poiType.getTranslation()); + entity.putTagNoLC(POI_TYPE_TAG, poiType.getTranslation()); } else { for (PoiType pt : type.getPoiTypes()) { if (pt.getEditOsmValue().equals(entity.getTag(pt.getEditOsmTag()))) { entity.removeTag(pt.getEditOsmTag()); - entity.putTagNoLC(EditPoiData.POI_TYPE_TAG, pt.getTranslation()); + entity.putTagNoLC(POI_TYPE_TAG, pt.getTranslation()); } } } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index bee84a5e68..5b9b9eb7ce 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -61,6 +61,7 @@ import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_C import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_OPEN_OSM_NOTE; import static net.osmand.aidlapi.OsmAndCustomizationConstants.OSM_EDITS; import static net.osmand.aidlapi.OsmAndCustomizationConstants.OSM_NOTES; +import static net.osmand.osm.edit.Entity.POI_TYPE_TAG; import static net.osmand.plus.ContextMenuAdapter.makeDeleteAction; @@ -554,7 +555,7 @@ public class OsmEditingPlugin extends OsmandPlugin { public static String getCategory(OsmPoint osmPoint, Context context) { String category = ""; if (osmPoint.getGroup() == OsmPoint.Group.POI) { - category = ((OpenstreetmapPoint) osmPoint).getEntity().getTag(EditPoiData.POI_TYPE_TAG); + category = ((OpenstreetmapPoint) osmPoint).getEntity().getTag(POI_TYPE_TAG); if (Algorithms.isEmpty(category)) { category = context.getString(R.string.shared_string_without_name); } diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java index 92159c49df..d4c2ad099f 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsAdapter.java @@ -17,6 +17,7 @@ import androidx.annotation.NonNull; import androidx.core.content.ContextCompat; import net.osmand.osm.PoiType; +import net.osmand.osm.edit.Entity; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.UiUtilities; @@ -244,7 +245,7 @@ public class OsmEditsAdapter extends ArrayAdapter { if (point.getGroup() == OsmPoint.Group.POI) { OpenstreetmapPoint osmPoint = (OpenstreetmapPoint) point; int iconResId = 0; - String poiTranslation = osmPoint.getEntity().getTag(EditPoiData.POI_TYPE_TAG); + String poiTranslation = osmPoint.getEntity().getTag(Entity.POI_TYPE_TAG); if (poiTranslation != null) { Map poiTypeMap = app.getPoiTypes().getAllTranslatedNames(false); PoiType poiType = poiTypeMap.get(poiTranslation.toLowerCase()); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsLayer.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsLayer.java index 99947c7de2..59c07afbaa 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsLayer.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditsLayer.java @@ -101,7 +101,7 @@ public class OsmEditsLayer extends OsmandMapLayer implements ContextMenuLayer.IC if (osmPoint.getGroup() == OsmPoint.Group.POI) { OpenstreetmapPoint osmP = (OpenstreetmapPoint) osmPoint; int iconResId = 0; - String poiTranslation = osmP.getEntity().getTag(EditPoiData.POI_TYPE_TAG); + String poiTranslation = osmP.getEntity().getTag(Entity.POI_TYPE_TAG); if (poiTranslation != null && activity != null) { Map poiTypeMap = activity.getMyApplication().getPoiTypes().getAllTranslatedNames(false); PoiType poiType = poiTypeMap.get(poiTranslation.toLowerCase()); diff --git a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiDialogFragment.java b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiDialogFragment.java index 7af0286ae4..d402cdfe49 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/dialogs/SendPoiDialogFragment.java @@ -16,13 +16,13 @@ import androidx.appcompat.widget.SwitchCompat; import androidx.fragment.app.DialogFragment; import net.osmand.osm.PoiType; +import net.osmand.osm.edit.Entity; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dialogs.ProgressDialogFragment; -import net.osmand.plus.osmedit.EditPoiData; import net.osmand.plus.osmedit.OpenstreetmapPoint; import net.osmand.plus.osmedit.OsmBugsLayer; import net.osmand.plus.osmedit.OsmEditingPlugin; @@ -152,7 +152,7 @@ public class SendPoiDialogFragment extends DialogFragment { for (OsmPoint p : poi) { if (p.getGroup() == OsmPoint.Group.POI) { OsmPoint.Action action = p.getAction(); - String type = ((OpenstreetmapPoint) p).getEntity().getTag(EditPoiData.POI_TYPE_TAG); + String type = ((OpenstreetmapPoint) p).getEntity().getTag(Entity.POI_TYPE_TAG); if (type == null) { continue; } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/FileSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/FileSettingsItem.java index 6afddc9664..097e64b0d2 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/FileSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/FileSettingsItem.java @@ -45,6 +45,10 @@ public class FileSettingsItem extends StreamSettingsItem { this.subtypeFolder = subtypeFolder; } + public boolean isMap() { + return this == OBF_MAP || this == WIKI_MAP || this == SRTM_MAP; + } + public String getSubtypeName() { return subtypeName; } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java index e2c06d14d6..03e1e39ad5 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/OsmEditsSettingsItem.java @@ -10,6 +10,7 @@ import com.google.gson.reflect.TypeToken; import net.osmand.osm.edit.Entity; import net.osmand.osm.edit.Node; +import net.osmand.osm.edit.Way; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; @@ -78,9 +79,8 @@ public class OsmEditsSettingsItem extends CollectionSettingsItem appliedItems.add(shouldReplace ? duplicate : renameItem(duplicate)); } OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class); - OsmBugsDbHelper db; if (osmEditingPlugin != null) { - db = osmEditingPlugin.getDBBug(); + OsmBugsDbHelper db = osmEditingPlugin.getDBBug(); for (OsmNotesPoint point : appliedItems) { db.addOsmbugs(point); } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsImporter.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsImporter.java index c9eb980b9d..a03f363542 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsImporter.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsImporter.java @@ -86,7 +86,7 @@ class SettingsImporter { Enumeration zipEnum = zipfile.entries(); while (zipEnum.hasMoreElements()) { ZipEntry zipEntry = zipEnum.nextElement(); - int size = (int) zipEntry.getSize(); + long size = zipEntry.getSize(); for (SettingsItem settingsItem : settingsItemList) { if (settingsItem instanceof FileSettingsItem && zipEntry.getName().equals(settingsItem.getFileName())) { diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java index d931e5a5c4..a513dc748c 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/SettingsItemType.java @@ -13,11 +13,6 @@ public enum SettingsItemType { AVOID_ROADS, SUGGESTED_DOWNLOADS, DOWNLOADS, - MARKERS, - FAVORITES, - TRACKS, - AUDIO_VIDEO_NOTES, OSM_NOTES, OSM_EDITS, - OFFLINE_MAPS } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java index ea702e8c85..9093c01c87 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ExportImportSettingsAdapter.java @@ -269,12 +269,20 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { setupIcon(icon, R.drawable.ic_action_info_dark, itemSelected); break; case OFFLINE_MAPS: - FileSettingsItem currentFileItem = (FileSettingsItem) currentItem; - file = currentFileItem.getFile(); + long size; + if (currentItem instanceof FileSettingsItem) { + FileSettingsItem currentFileItem = (FileSettingsItem) currentItem; + file = currentFileItem.getFile(); + size = currentFileItem.getSize(); + } else { + file = (File) currentItem; + size = file.length(); + } title.setText(FileNameTranslationHelper.getFileName(app, app.getResourceManager().getOsmandRegions(), file.getName())); - FileSubtype subtype = FileSubtype.getSubtypeByFileName(file.getPath().replace(app.getAppPath(null).getPath(), "")); + FileSubtype subtype = FileSubtype.getSubtypeByFileName(file.getPath().replace( + app.getAppPath(null).getPath(), "")); switch (subtype) { case SRTM_MAP: iconId = R.drawable.ic_plugin_srtm; @@ -286,7 +294,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter { iconId = R.drawable.ic_map; } setupIcon(icon, iconId, itemSelected); - subText.setText(AndroidUtils.formatSize(app, currentFileItem.getSize())); + subText.setText(AndroidUtils.formatSize(app, size)); subText.setVisibility(View.VISIBLE); break; default: diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java index 46752fd758..8250477d20 100644 --- a/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ImportSettingsFragment.java @@ -71,9 +71,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import static net.osmand.plus.settings.backend.backup.FileSettingsItem.FileSubtype.*; - - public class ImportSettingsFragment extends BaseOsmAndFragment implements View.OnClickListener { @@ -287,7 +284,7 @@ public class ImportSettingsFragment extends BaseOsmAndFragment private void reloadIndexes(@NonNull List items) { for (SettingsItem item : items) { - if (item instanceof FileSettingsItem && ((FileSettingsItem) item).getSubtype() == OBF_MAP) { + if (item instanceof FileSettingsItem && ((FileSettingsItem) item).getSubtype().isMap()) { Activity activity = getActivity(); if (activity instanceof MapActivity) { new ReloadIndexesTack((MapActivity) activity).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);