Search in sources :

Example 1 with OsmEditingPlugin

use of net.osmand.plus.plugins.osmedit.OsmEditingPlugin in project Osmand by osmandapp.

the class OsmEditsSettingsItem method init.

@Override
protected void init() {
    super.init();
    OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
    if (osmEditingPlugin != null) {
        existingItems = osmEditingPlugin.getDBPOI().getOpenstreetmapPoints();
    }
}
Also used : OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin)

Example 2 with OsmEditingPlugin

use of net.osmand.plus.plugins.osmedit.OsmEditingPlugin in project Osmand by osmandapp.

the class OsmEditsSettingsItem method apply.

@Override
public void apply() {
    List<OpenstreetmapPoint> newItems = getNewItems();
    if (!newItems.isEmpty() || !duplicateItems.isEmpty()) {
        appliedItems = new ArrayList<>(newItems);
        OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
        if (osmEditingPlugin != null) {
            OpenstreetmapsDbHelper db = osmEditingPlugin.getDBPOI();
            for (OpenstreetmapPoint duplicate : duplicateItems) {
                db.deletePOI(duplicate);
                db.addOpenstreetmap(duplicate);
            }
            for (OpenstreetmapPoint point : appliedItems) {
                db.addOpenstreetmap(point);
            }
        }
    }
}
Also used : OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) OpenstreetmapsDbHelper(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapsDbHelper) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin)

Example 3 with OsmEditingPlugin

use of net.osmand.plus.plugins.osmedit.OsmEditingPlugin in project Osmand by osmandapp.

the class OsmNotesSettingsItem method readItemsFromJson.

@Override
void readItemsFromJson(@NonNull JSONObject json) throws IllegalArgumentException {
    try {
        if (!json.has("items")) {
            return;
        }
        OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
        long minId = osmEditingPlugin != null ? osmEditingPlugin.getDBBug().getMinID() - 1 : -2;
        int idOffset = 0;
        JSONArray jsonArray = json.getJSONArray("items");
        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject object = jsonArray.getJSONObject(i);
            String text = object.optString(TEXT_KEY);
            double lat = object.getDouble(LAT_KEY);
            double lon = object.getDouble(LON_KEY);
            String author = object.optString(AUTHOR_KEY);
            author = author.isEmpty() ? null : author;
            String action = object.getString(ACTION_KEY);
            OsmNotesPoint point = new OsmNotesPoint();
            point.setId(Math.min(-2, minId - idOffset));
            point.setText(text);
            point.setLatitude(lat);
            point.setLongitude(lon);
            point.setAuthor(author);
            point.setAction(action);
            items.add(point);
            idOffset++;
        }
    } catch (JSONException e) {
        warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType())));
        throw new IllegalArgumentException("Json parse error", e);
    }
}
Also used : JSONObject(org.json.JSONObject) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin)

Example 4 with OsmEditingPlugin

use of net.osmand.plus.plugins.osmedit.OsmEditingPlugin in project Osmand by osmandapp.

the class SettingsHelper method getMyPlacesItems.

private Map<ExportSettingsType, List<?>> getMyPlacesItems(@Nullable List<ExportSettingsType> settingsTypes, boolean addEmptyItems) {
    Map<ExportSettingsType, List<?>> myPlacesItems = new LinkedHashMap<>();
    List<FavoriteGroup> favoriteGroups = settingsTypes == null || settingsTypes.contains(ExportSettingsType.FAVORITES) ? app.getFavoritesHelper().getFavoriteGroups() : Collections.emptyList();
    if (!favoriteGroups.isEmpty() || addEmptyItems) {
        myPlacesItems.put(ExportSettingsType.FAVORITES, favoriteGroups);
    }
    List<GpxDataItem> gpxItems = settingsTypes == null || settingsTypes.contains(ExportSettingsType.TRACKS) ? app.getGpxDbHelper().getItems() : Collections.emptyList();
    if (!gpxItems.isEmpty() || addEmptyItems) {
        List<File> files = new ArrayList<>();
        for (GpxDataItem gpxItem : gpxItems) {
            File file = gpxItem.getFile();
            if (file.exists() && !file.isDirectory()) {
                files.add(file);
            }
        }
        if (!files.isEmpty() || addEmptyItems) {
            myPlacesItems.put(ExportSettingsType.TRACKS, files);
        }
    }
    OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getActivePlugin(OsmEditingPlugin.class);
    if (osmEditingPlugin != null) {
        List<OsmNotesPoint> notesPointList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.OSM_NOTES) ? osmEditingPlugin.getDBBug().getOsmbugsPoints() : Collections.emptyList();
        if (!notesPointList.isEmpty() || addEmptyItems) {
            myPlacesItems.put(ExportSettingsType.OSM_NOTES, notesPointList);
        }
        List<OpenstreetmapPoint> editsPointList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.OSM_EDITS) ? osmEditingPlugin.getDBPOI().getOpenstreetmapPoints() : Collections.emptyList();
        if (!editsPointList.isEmpty() || addEmptyItems) {
            myPlacesItems.put(ExportSettingsType.OSM_EDITS, editsPointList);
        }
    }
    AudioVideoNotesPlugin avNotesPlugin = OsmandPlugin.getActivePlugin(AudioVideoNotesPlugin.class);
    if (avNotesPlugin != null) {
        List<File> files = new ArrayList<>();
        if (settingsTypes == null || settingsTypes.contains(ExportSettingsType.MULTIMEDIA_NOTES)) {
            for (Recording rec : avNotesPlugin.getAllRecordings()) {
                File file = rec.getFile();
                if (file != null && file.exists()) {
                    files.add(file);
                }
            }
        }
        if (!files.isEmpty() || addEmptyItems) {
            myPlacesItems.put(ExportSettingsType.MULTIMEDIA_NOTES, files);
        }
    }
    List<MapMarker> mapMarkers = settingsTypes == null || settingsTypes.contains(ExportSettingsType.ACTIVE_MARKERS) ? app.getMapMarkersHelper().getMapMarkers() : Collections.emptyList();
    if (!mapMarkers.isEmpty() || addEmptyItems) {
        String name = app.getString(R.string.map_markers);
        String groupId = ExportSettingsType.ACTIVE_MARKERS.name();
        MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
        markersGroup.setMarkers(mapMarkers);
        myPlacesItems.put(ExportSettingsType.ACTIVE_MARKERS, Collections.singletonList(markersGroup));
    }
    List<MapMarker> markersHistory = settingsTypes == null || settingsTypes.contains(ExportSettingsType.HISTORY_MARKERS) ? app.getMapMarkersHelper().getMapMarkersHistory() : Collections.emptyList();
    if (!markersHistory.isEmpty() || addEmptyItems) {
        String name = app.getString(R.string.shared_string_history);
        String groupId = ExportSettingsType.HISTORY_MARKERS.name();
        MapMarkersGroup markersGroup = new MapMarkersGroup(groupId, name, ItineraryType.MARKERS);
        markersGroup.setMarkers(markersHistory);
        myPlacesItems.put(ExportSettingsType.HISTORY_MARKERS, Collections.singletonList(markersGroup));
    }
    List<HistoryEntry> historyEntries = settingsTypes == null || settingsTypes.contains(ExportSettingsType.SEARCH_HISTORY) ? SearchHistoryHelper.getInstance(app).getHistoryEntries(false) : Collections.emptyList();
    if (!historyEntries.isEmpty() || addEmptyItems) {
        myPlacesItems.put(ExportSettingsType.SEARCH_HISTORY, historyEntries);
    }
    List<MapMarkersGroup> markersGroups = settingsTypes == null || settingsTypes.contains(ExportSettingsType.ITINERARY_GROUPS) ? app.getMapMarkersHelper().getVisibleMapMarkersGroups() : Collections.emptyList();
    if (!markersGroups.isEmpty() || addEmptyItems) {
        myPlacesItems.put(ExportSettingsType.ITINERARY_GROUPS, markersGroups);
    }
    return myPlacesItems;
}
Also used : AudioVideoNotesPlugin(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin) MapMarker(net.osmand.plus.mapmarkers.MapMarker) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) GpxDataItem(net.osmand.plus.track.helpers.GPXDatabase.GpxDataItem) List(java.util.List) ArrayList(java.util.ArrayList) MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup) ExportSettingsType(net.osmand.plus.settings.backend.ExportSettingsType) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) Recording(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin.Recording) File(java.io.File)

Example 5 with OsmEditingPlugin

use of net.osmand.plus.plugins.osmedit.OsmEditingPlugin in project Osmand by osmandapp.

the class ValidateOsmLoginDetailsTask method onPostExecute.

@Override
protected void onPostExecute(OsmBugResult osmBugResult) {
    OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
    if (plugin != null) {
        if (osmBugResult.warning != null) {
            plugin.OSM_USER_NAME_OR_EMAIL.resetToDefault();
            plugin.OSM_USER_DISPLAY_NAME.resetToDefault();
            plugin.OSM_USER_PASSWORD.resetToDefault();
            app.getSettings().MAPPER_LIVE_UPDATES_EXPIRE_TIME.resetToDefault();
            app.showToastMessage(osmBugResult.warning);
        } else {
            plugin.OSM_USER_DISPLAY_NAME.set(osmBugResult.userName);
            app.showToastMessage(R.string.osm_authorization_success);
        }
    }
    if (listener != null) {
        listener.loginValidationFinished(osmBugResult.warning);
    }
}
Also used : OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin)

Aggregations

OsmEditingPlugin (net.osmand.plus.plugins.osmedit.OsmEditingPlugin)20 OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)5 Entity (net.osmand.osm.edit.Entity)4 OsmandApplication (net.osmand.plus.OsmandApplication)4 MapActivity (net.osmand.plus.activities.MapActivity)4 AlertDialog (androidx.appcompat.app.AlertDialog)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 OsmPoint (net.osmand.plus.plugins.osmedit.data.OsmPoint)3 DialogInterface (android.content.DialogInterface)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 LatLon (net.osmand.data.LatLon)2 PoiCategory (net.osmand.osm.PoiCategory)2 PoiType (net.osmand.osm.PoiType)2 Node (net.osmand.osm.edit.Node)2 ProgressDialogFragment (net.osmand.plus.dialogs.ProgressDialogFragment)2 UploadOpenstreetmapPointAsyncTask (net.osmand.plus.plugins.osmedit.asynctasks.UploadOpenstreetmapPointAsyncTask)2