diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java index 823cb4b740..a24859fa30 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesTreeFragment.java @@ -89,7 +89,7 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen public static final int IMPORT_FAVOURITES_ID = 7; public static final String GROUP_EXPANDED_POSTFIX = "_group_expanded"; - private static final int MAX_POINTS_IN_DESCRIPTION = 100; + private static final int MAX_CHARS_IN_DESCRIPTION = 100000; private FavouritesAdapter favouritesAdapter; private FavouritesDbHelper helper; @@ -611,37 +611,53 @@ public class FavoritesTreeFragment extends OsmandExpandableListFragment implemen private String generateHtmlPrint(List groups) { StringBuilder html = new StringBuilder(); + StringBuilder buffer = new StringBuilder(); html.append("

My Favorites

"); - int addedPoints = 0; for (FavoriteGroup group : groups) { - html.append("

").append(group.getDisplayName(app)).append("

"); - for (FavouritePoint fp : group.getPoints()) { - if (addedPoints >= MAX_POINTS_IN_DESCRIPTION) { - break; - } - - float lat = (float) fp.getLatitude(); - float lon = (float) fp.getLongitude(); - String url = "geo:" + lat + "," + lon + "?m=" + fp.getName(); - html.append("

") - .append(fp.getDisplayName(app)) - .append(" - geo:") - .append(lat).append(",").append(lon) - .append("

"); - addedPoints++; + buffer.setLength(0); + buffer.append("

").append(group.getDisplayName(app)).append("

"); + if (buffer.length() + html.length() > MAX_CHARS_IN_DESCRIPTION) { + return html.append("

...

").toString(); } - if (addedPoints >= MAX_POINTS_IN_DESCRIPTION) { - html.append("

...

"); - break; + html.append(buffer); + boolean reachedLimit = generateHtmlForGroup(group.getPoints(), html); + if (reachedLimit) { + return html.append("

...

").toString(); } } + return html.toString(); } + private boolean generateHtmlForGroup(List points, StringBuilder html) { + StringBuilder buffer = new StringBuilder(); + + for (FavouritePoint fp : points) { + buffer.setLength(0); + + float lat = (float) fp.getLatitude(); + float lon = (float) fp.getLongitude(); + String url = "geo:" + lat + "," + lon + "?m=" + fp.getName(); + buffer.append("

") + .append(fp.getDisplayName(app)) + .append(" - geo:") + .append(lat).append(",").append(lon) + .append("

"); + + if (buffer.length() + html.length() > MAX_CHARS_IN_DESCRIPTION) { + return true; + } + + html.append(buffer); + } + + return false; + } + private void shareFavourites() { if (favouritesAdapter.isEmpty()) { Toast.makeText(getActivity(), R.string.no_fav_to_save, Toast.LENGTH_LONG).show();