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