Search in sources :

Example 6 with SettingsItemReader

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);
                }
            }
        }
    };
}
Also used : SettingsItemReader(net.osmand.plus.settings.backend.backup.SettingsItemReader) FavouritePoint(net.osmand.data.FavouritePoint) InputStream(java.io.InputStream) FavoriteGroup(net.osmand.plus.myplaces.FavoriteGroup) NonNull(androidx.annotation.NonNull) GPXFile(net.osmand.GPXUtilities.GPXFile) LinkedHashMap(java.util.LinkedHashMap) Nullable(androidx.annotation.Nullable)

Aggregations

NonNull (androidx.annotation.NonNull)6 SettingsItemReader (net.osmand.plus.settings.backend.backup.SettingsItemReader)6 InputStream (java.io.InputStream)5 Nullable (androidx.annotation.Nullable)4 GPXFile (net.osmand.GPXUtilities.GPXFile)4 MapMarker (net.osmand.plus.mapmarkers.MapMarker)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 JSONException (org.json.JSONException)2 JSONObject (org.json.JSONObject)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 InputStreamReader (java.io.InputStreamReader)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 TreeSet (java.util.TreeSet)1 OperationLog (net.osmand.OperationLog)1 FavouritePoint (net.osmand.data.FavouritePoint)1