Update favorites sorting algorithm / fix saving favorites
This commit is contained in:
parent
d5d80daa02
commit
ddae62466c
4 changed files with 32 additions and 7 deletions
|
@ -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++) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -455,14 +455,24 @@ public class FavouritesDbHelper {
|
|||
Comparator<FavouritePoint> favoritesComparator = new Comparator<FavouritePoint>() {
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue