diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java index b067031273..687f99bd38 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelArticle.java @@ -1,10 +1,12 @@ package net.osmand.plus.wikivoyage.data; +import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; + import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.Size; import android.text.TextUtils; - import net.osmand.plus.GPXUtilities.GPXFile; import org.apache.commons.codec.binary.Hex; @@ -103,6 +105,11 @@ public class TravelArticle { @NonNull public static String getImageUrl(@NonNull String imageTitle, boolean thumbnail) { + try { + imageTitle = URLDecoder.decode(imageTitle, "UTF-8"); + } catch (UnsupportedEncodingException e) { + System.err.println(e.getMessage()); + } String[] hash = getHash(imageTitle); String prefix = thumbnail ? THUMB_PREFIX : REGULAR_PREFIX; return IMAGE_ROOT_URL + "thumb/" + hash[0] + "/" + hash[1] + "/" + imageTitle + "/" + prefix + imageTitle; diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java index ab8b849d6b..5c3a8148a7 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelDbHelper.java @@ -34,6 +34,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Random; @@ -417,7 +418,8 @@ public class TravelDbHelper { } @NonNull - public LinkedHashMap> getNavigationMap(final TravelArticle article) { + public LinkedHashMap> getNavigationMap( + final TravelArticle article) { String lang = article.getLang(); String title = article.getTitle(); if (TextUtils.isEmpty(lang) || TextUtils.isEmpty(title)) { @@ -437,24 +439,24 @@ public class TravelDbHelper { } Map> navMap = new HashMap<>(); SQLiteConnection conn = openConnection(); - Set headers = null; + Set headers = new LinkedHashSet(); Map headerObjs = new HashMap<>(); if (conn != null) { List params = new ArrayList<>(); - StringBuilder query = new StringBuilder("SELECT a.trip_id, a.title, a.lang, a.is_part_of " + - "FROM travel_articles a WHERE is_part_of = ? and lang = ? "); + StringBuilder query = new StringBuilder("SELECT a.trip_id, a.title, a.lang, a.is_part_of " + + "FROM travel_articles a WHERE is_part_of = ? and lang = ? "); params.add(title); params.add(lang); + headers.add(title); if (parts != null && parts.length > 0) { - headers = new HashSet<>(Arrays.asList(parts)); - headers.add(title); - query.append("UNION SELECT a.trip_id, a.title, a.lang, a.is_part_of " + - "FROM travel_articles a WHERE title = ? and lang = ? "); + headers.addAll(Arrays.asList(parts)); + query.append("UNION SELECT a.trip_id, a.title, a.lang, a.is_part_of " + + "FROM travel_articles a WHERE title = ? and lang = ? "); params.add(parts[0]); params.add(lang); for (String part : parts) { - query.append("UNION SELECT a.trip_id, a.title, a.lang, a.is_part_of " + - "FROM travel_articles a WHERE is_part_of = ? and lang = ? "); + query.append("UNION SELECT a.trip_id, a.title, a.lang, a.is_part_of " + + "FROM travel_articles a WHERE is_part_of = ? and lang = ? "); params.add(part); params.add(lang); } @@ -482,23 +484,21 @@ public class TravelDbHelper { cursor.close(); } LinkedHashMap> res = new LinkedHashMap<>(); - if (parts != null) { - for (String header : parts) { - WikivoyageSearchResult searchResult = headerObjs.get(header); - List results = navMap.get(header); - if (results != null) { - Collections.sort(results, new Comparator() { - @Override - public int compare(WikivoyageSearchResult o1, WikivoyageSearchResult o2) { - return collator.compare(o1.articleTitles.get(0), o2.articleTitles.get(0)); - } - }); - WikivoyageSearchResult emptyResult = new WikivoyageSearchResult(); - emptyResult.articleTitles.add(header); - emptyResult.tripId = -1; - searchResult = searchResult != null ? searchResult : emptyResult; - res.put(searchResult, results); - } + for (String header : headers) { + WikivoyageSearchResult searchResult = headerObjs.get(header); + List results = navMap.get(header); + if (results != null) { + Collections.sort(results, new Comparator() { + @Override + public int compare(WikivoyageSearchResult o1, WikivoyageSearchResult o2) { + return collator.compare(o1.articleTitles.get(0), o2.articleTitles.get(0)); + } + }); + WikivoyageSearchResult emptyResult = new WikivoyageSearchResult(); + emptyResult.articleTitles.add(header); + emptyResult.tripId = -1; + searchResult = searchResult != null ? searchResult : emptyResult; + res.put(searchResult, results); } } return res;