Fix bugs with navigation menu & with banner image

This commit is contained in:
Victor Shcherb 2018-05-16 15:43:07 +02:00
parent 94c25647c5
commit 821b68823d
2 changed files with 35 additions and 28 deletions

View file

@ -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;

View file

@ -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<WikivoyageSearchResult, List<WikivoyageSearchResult>> getNavigationMap(final TravelArticle article) {
public LinkedHashMap<WikivoyageSearchResult, List<WikivoyageSearchResult>> 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<String, List<WikivoyageSearchResult>> navMap = new HashMap<>();
SQLiteConnection conn = openConnection();
Set<String> headers = null;
Set<String> headers = new LinkedHashSet<String>();
Map<String, WikivoyageSearchResult> headerObjs = new HashMap<>();
if (conn != null) {
List<String> 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);
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 = ? ");
if (parts != null && parts.length > 0) {
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,8 +484,7 @@ public class TravelDbHelper {
cursor.close();
}
LinkedHashMap<WikivoyageSearchResult, List<WikivoyageSearchResult>> res = new LinkedHashMap<>();
if (parts != null) {
for (String header : parts) {
for (String header : headers) {
WikivoyageSearchResult searchResult = headerObjs.get(header);
List<WikivoyageSearchResult> results = navMap.get(header);
if (results != null) {
@ -500,7 +501,6 @@ public class TravelDbHelper {
res.put(searchResult, results);
}
}
}
return res;
}