diff --git a/OsmAnd-java/src/net/osmand/util/Algorithms.java b/OsmAnd-java/src/net/osmand/util/Algorithms.java index 5cc68b39d6..55393cc2ed 100644 --- a/OsmAnd-java/src/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/net/osmand/util/Algorithms.java @@ -125,6 +125,7 @@ public class Algorithms { throw new IllegalArgumentException("Unknown color " + colorString); //$NON-NLS-1$ } + public static int extractFirstIntegerNumber(String s) { int i = 0; for (int k = 0; k < s.length(); k++) { @@ -137,6 +138,16 @@ public class Algorithms { return i; } + public static String extractIntegerPrefix(String s) { + int k = 0; + for (; k < s.length(); k++) { + if (Character.isDigit(s.charAt(k))) { + return s.substring(0, k); + } + } + return ""; + } + public static String extractIntegerSuffix(String s) { int k = 0; for (; k < s.length(); k++) { diff --git a/OsmAnd/src/net/osmand/data/FavouritePoint.java b/OsmAnd/src/net/osmand/data/FavouritePoint.java index 2cd37511b7..69b33c5a4c 100644 --- a/OsmAnd/src/net/osmand/data/FavouritePoint.java +++ b/OsmAnd/src/net/osmand/data/FavouritePoint.java @@ -6,7 +6,7 @@ import android.content.Context; public class FavouritePoint implements Serializable, LocationPoint { private static final long serialVersionUID = 729654300829771466L; - private String name; + private String name = ""; private String description; private String category = ""; private double latitude; @@ -21,6 +21,9 @@ public class FavouritePoint implements Serializable, LocationPoint { this.latitude = latitude; this.longitude = longitude; this.category = category; + if(name == null) { + name = ""; + } this.name = name; } diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 6a97df9d75..0ee0c5ce6b 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -455,14 +455,24 @@ public class FavouritesDbHelper { Comparator favoritesComparator = new Comparator() { @Override - public int compare(FavouritePoint object1, FavouritePoint object2) { - return collator.compare(object1.getName(), object2.getName()); + public int compare(FavouritePoint o1, FavouritePoint o2) { + String s1 = o1.getName(); + String s2 = o2.getName(); + int i1 = Algorithms.extractFirstIntegerNumber(s1); + int i2 = Algorithms.extractFirstIntegerNumber(s2); + if(i1 == i2) { + String ot1 = Algorithms.extractIntegerPrefix(s1); + String ot2 = Algorithms.extractIntegerPrefix(s2); + return collator.compare(ot1, ot2); + } + + return i1 - i2; } }; - for(FavoriteGroup g : favoriteGroups) { + for (FavoriteGroup g : favoriteGroups) { Collections.sort(g.points, favoritesComparator); } - if(cachedFavoritePoints != null) { + if (cachedFavoritePoints != null) { Collections.sort(cachedFavoritePoints, favoritesComparator); } } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java index d32bd90aa6..adcc5167c5 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/SelectedGPXFragment.java @@ -227,11 +227,12 @@ public class SelectedGPXFragment extends OsmAndListFragment { FavouritesDbHelper fdb = app.getFavorites(); for(GpxDisplayItem i : modifiableList) { if (i.locationStart != null) { - FavouritePoint fp = new FavouritePoint(i.locationStart.lat, i.locationStart.lon, i.locationStart.name, + FavouritePoint fp = new FavouritePoint(i.locationStart.lat, i.locationStart.lon, i.name, category); - fdb.addFavourite(fp); + fdb.addFavourite(fp, false); } } + fdb.saveCurrentPointsIntoFile(); } @Override