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();
}
}
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);
}
}
}
}
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);
}
}
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;
}
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);
}
}
Aggregations