use of net.osmand.plus.settings.backend.backup.SettingsItemReader in project Osmand by osmandapp.
the class FavoritesSettingsItem method getReader.
@Nullable
@Override
public SettingsItemReader<FavoritesSettingsItem> getReader() {
return new SettingsItemReader<FavoritesSettingsItem>(this) {
@Override
public void readFromStream(@NonNull InputStream inputStream, String entryName) throws IllegalArgumentException {
GPXFile gpxFile = GPXUtilities.loadGPXFile(inputStream);
if (gpxFile.error != null) {
warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType())));
SettingsHelper.LOG.error("Failed read gpx file", gpxFile.error);
} else {
Map<String, FavoriteGroup> flatGroups = new LinkedHashMap<>();
List<FavouritePoint> favourites = asFavourites(app, gpxFile.getPoints(), fileName, false);
for (FavouritePoint point : favourites) {
FavoriteGroup group = flatGroups.get(point.getCategory());
if (group == null) {
group = new FavoriteGroup(point.getCategory(), point.isVisible(), point.getColor());
flatGroups.put(group.getName(), group);
items.add(group);
}
group.getPoints().add(point);
}
}
}
};
}
Aggregations