Search in sources :

Example 36 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class FavouritesDbHelper method delete.

public void delete(Set<FavoriteGroup> groupsToDelete, Set<FavouritePoint> favoritesSelected) {
    if (favoritesSelected != null) {
        Set<FavoriteGroup> groupsToSync = new HashSet<>();
        for (FavouritePoint p : favoritesSelected) {
            FavoriteGroup group = flatGroups.get(p.getCategory());
            if (group != null) {
                group.points.remove(p);
                groupsToSync.add(group);
            }
            cachedFavoritePoints.remove(p);
        }
        for (FavoriteGroup gr : groupsToSync) {
            runSyncWithMarkers(gr);
        }
    }
    if (groupsToDelete != null) {
        for (FavoriteGroup g : groupsToDelete) {
            flatGroups.remove(g.name);
            favoriteGroups.remove(g);
            cachedFavoritePoints.removeAll(g.points);
            removeFromMarkers(g);
        }
    }
    saveCurrentPointsIntoFile();
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) HashSet(java.util.HashSet)

Example 37 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class FavouritesDbHelper method loadFavorites.

public void loadFavorites() {
    flatGroups.clear();
    favoriteGroups.clear();
    File internalFile = getInternalFile();
    if (!internalFile.exists()) {
        File dbPath = context.getDatabasePath(FAVOURITE_DB_NAME);
        if (dbPath.exists()) {
            loadAndCheckDatabasePoints();
            saveCurrentPointsIntoFile();
        }
    // createDefaultCategories();
    }
    Map<String, FavouritePoint> points = new LinkedHashMap<String, FavouritePoint>();
    Map<String, FavouritePoint> extPoints = new LinkedHashMap<String, FavouritePoint>();
    loadGPXFile(internalFile, points);
    loadGPXFile(getExternalFile(), extPoints);
    boolean changed = merge(extPoints, points);
    for (FavouritePoint pns : points.values()) {
        FavoriteGroup group = getOrCreateGroup(pns, 0);
        group.points.add(pns);
    }
    sortAll();
    recalculateCachedFavPoints();
    if (changed) {
        saveCurrentPointsIntoFile();
    }
    favouritesUpdated();
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap)

Example 38 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class FavouritesDbHelper method editFavouriteGroup.

public void editFavouriteGroup(FavoriteGroup group, String newName, int color, boolean visible) {
    if (color != 0 && group.color != color) {
        FavoriteGroup gr = flatGroups.get(group.name);
        group.color = color;
        for (FavouritePoint p : gr.points) {
            p.setColor(color);
        }
        runSyncWithMarkers(gr);
    }
    if (group.visible != visible) {
        FavoriteGroup gr = flatGroups.get(group.name);
        group.visible = visible;
        for (FavouritePoint p : gr.points) {
            p.setVisible(visible);
        }
        runSyncWithMarkers(gr);
    }
    if (!group.name.equals(newName)) {
        FavoriteGroup gr = flatGroups.remove(group.name);
        removeFromMarkers(gr);
        gr.name = newName;
        FavoriteGroup renamedGroup = flatGroups.get(gr.name);
        boolean existing = renamedGroup != null;
        if (renamedGroup == null) {
            renamedGroup = gr;
            flatGroups.put(gr.name, gr);
        } else {
            favoriteGroups.remove(gr);
        }
        for (FavouritePoint p : gr.points) {
            p.setCategory(newName);
            if (existing) {
                renamedGroup.points.add(p);
            }
        }
        addToMarkers(renamedGroup);
    }
    saveCurrentPointsIntoFile();
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint)

Example 39 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class FavouritesDbHelper method getComparator.

public static Comparator<FavouritePoint> getComparator() {
    final Collator collator = Collator.getInstance();
    collator.setStrength(Collator.SECONDARY);
    Comparator<FavouritePoint> favoritesComparator = new Comparator<FavouritePoint>() {

        @Override
        public int compare(FavouritePoint o1, FavouritePoint o2) {
            String s1 = o1.getName();
            String s2 = o2.getName();
            int i1 = Algorithms.extractIntegerNumber(s1);
            int i2 = Algorithms.extractIntegerNumber(s2);
            String ot1 = Algorithms.extractIntegerPrefix(s1);
            String ot2 = Algorithms.extractIntegerPrefix(s2);
            // Next 6 lines needed for correct comparison of names with and without digits
            if (ot1.length() == 0) {
                ot1 = s1;
            }
            if (ot2.length() == 0) {
                ot2 = s2;
            }
            int res = collator.compare(ot1, ot2);
            if (res == 0) {
                res = i1 - i2;
            }
            if (res == 0) {
                res = collator.compare(s1, s2);
            }
            return res;
        }
    };
    return favoritesComparator;
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) FavouritePoint(net.osmand.data.FavouritePoint) Collator(java.text.Collator) Comparator(java.util.Comparator)

Example 40 with FavouritePoint

use of net.osmand.data.FavouritePoint in project Osmand by osmandapp.

the class FavouritesDbHelper method loadGPXFile.

private boolean loadGPXFile(File file, Map<String, FavouritePoint> points) {
    if (!file.exists()) {
        return false;
    }
    GPXFile res = GPXUtilities.loadGPXFile(context, file);
    if (res.warning != null) {
        return false;
    }
    for (WptPt p : res.getPoints()) {
        int c;
        String name = p.name;
        String categoryName = p.category != null ? p.category : "";
        if (name == null) {
            name = "";
        }
        // old way to store the category, in name.
        if ("".equals(categoryName.trim()) && (c = name.lastIndexOf('_')) != -1) {
            categoryName = name.substring(c + 1);
            name = name.substring(0, c);
        }
        FavouritePoint fp = new FavouritePoint(p.lat, p.lon, name, categoryName);
        fp.setDescription(p.desc);
        if (p.comment != null) {
            fp.setOriginObjectName(p.comment);
        }
        fp.setColor(p.getColor(0));
        fp.setVisible(!p.getExtensionsToRead().containsKey(HIDDEN));
        points.put(getKey(fp), fp);
    }
    return true;
}
Also used : WptPt(net.osmand.plus.GPXUtilities.WptPt) FavouritePoint(net.osmand.data.FavouritePoint) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) FavouritePoint(net.osmand.data.FavouritePoint)

Aggregations

FavouritePoint (net.osmand.data.FavouritePoint)51 LatLon (net.osmand.data.LatLon)16 PointDescription (net.osmand.data.PointDescription)10 FavouritesDbHelper (net.osmand.plus.FavouritesDbHelper)10 View (android.view.View)9 ArrayList (java.util.ArrayList)9 AlertDialog (android.support.v7.app.AlertDialog)8 OsmandApplication (net.osmand.plus.OsmandApplication)8 TextView (android.widget.TextView)7 WptPt (net.osmand.plus.GPXUtilities.WptPt)7 MapActivity (net.osmand.plus.activities.MapActivity)7 DialogInterface (android.content.DialogInterface)6 ImageView (android.widget.ImageView)6 Amenity (net.osmand.data.Amenity)6 Paint (android.graphics.Paint)5 AdapterView (android.widget.AdapterView)5 ListView (android.widget.ListView)5 FavoriteGroup (net.osmand.plus.FavouritesDbHelper.FavoriteGroup)5 GPXFile (net.osmand.plus.GPXUtilities.GPXFile)5 Collator (java.text.Collator)4