commit
04da7e28c7
1 changed files with 22 additions and 0 deletions
|
@ -34,6 +34,7 @@ class FavoritesImportTask extends BaseImportAsyncTask<Void, Void, GPXFile> {
|
|||
protected GPXFile doInBackground(Void... nothing) {
|
||||
List<FavouritePoint> favourites = asFavourites(app, gpxFile.getPoints(), fileName, forceImportFavourites);
|
||||
FavouritesDbHelper favoritesHelper = app.getFavorites();
|
||||
checkDuplicateNames(favourites);
|
||||
for (FavouritePoint favourite : favourites) {
|
||||
favoritesHelper.deleteFavourite(favourite, false);
|
||||
favoritesHelper.addFavourite(favourite, false);
|
||||
|
@ -43,6 +44,27 @@ class FavoritesImportTask extends BaseImportAsyncTask<Void, Void, GPXFile> {
|
|||
return null;
|
||||
}
|
||||
|
||||
public void checkDuplicateNames(List<FavouritePoint> favourites) {
|
||||
for (FavouritePoint fp : favourites) {
|
||||
int number = 1;
|
||||
String index;
|
||||
String name = fp.getName();
|
||||
boolean duplicatesFound = false;
|
||||
for (FavouritePoint fp2 : favourites) {
|
||||
if (name.equals(fp2.getName()) && fp.getCategory().equals(fp2.getCategory()) && !fp.equals(fp2)) {
|
||||
if (!duplicatesFound) {
|
||||
index = " (" + number + ")";
|
||||
fp.setName(name + index);
|
||||
}
|
||||
duplicatesFound = true;
|
||||
number++;
|
||||
index = " (" + number + ")";
|
||||
fp2.setName(fp2.getName() + index);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(GPXFile result) {
|
||||
hideProgress();
|
||||
|
|
Loading…
Reference in a new issue