diff --git a/OsmAnd/src/net/osmand/plus/importfiles/FavoritesImportTask.java b/OsmAnd/src/net/osmand/plus/importfiles/FavoritesImportTask.java index 9047baeb59..beb3534a46 100644 --- a/OsmAnd/src/net/osmand/plus/importfiles/FavoritesImportTask.java +++ b/OsmAnd/src/net/osmand/plus/importfiles/FavoritesImportTask.java @@ -34,6 +34,7 @@ class FavoritesImportTask extends BaseImportAsyncTask { protected GPXFile doInBackground(Void... nothing) { List 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 { return null; } + public void checkDuplicateNames(List 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();