Fix bugs with navigation menu & with banner image
This commit is contained in:
parent
94c25647c5
commit
821b68823d
2 changed files with 35 additions and 28 deletions
|
@ -1,10 +1,12 @@
|
||||||
package net.osmand.plus.wikivoyage.data;
|
package net.osmand.plus.wikivoyage.data;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLDecoder;
|
||||||
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.Size;
|
import android.support.annotation.Size;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Hex;
|
import org.apache.commons.codec.binary.Hex;
|
||||||
|
@ -103,6 +105,11 @@ public class TravelArticle {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public static String getImageUrl(@NonNull String imageTitle, boolean thumbnail) {
|
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[] hash = getHash(imageTitle);
|
||||||
String prefix = thumbnail ? THUMB_PREFIX : REGULAR_PREFIX;
|
String prefix = thumbnail ? THUMB_PREFIX : REGULAR_PREFIX;
|
||||||
return IMAGE_ROOT_URL + "thumb/" + hash[0] + "/" + hash[1] + "/" + imageTitle + "/" + prefix + imageTitle;
|
return IMAGE_ROOT_URL + "thumb/" + hash[0] + "/" + hash[1] + "/" + imageTitle + "/" + prefix + imageTitle;
|
||||||
|
|
|
@ -34,6 +34,7 @@ import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
@ -417,7 +418,8 @@ public class TravelDbHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public LinkedHashMap<WikivoyageSearchResult, List<WikivoyageSearchResult>> getNavigationMap(final TravelArticle article) {
|
public LinkedHashMap<WikivoyageSearchResult, List<WikivoyageSearchResult>> getNavigationMap(
|
||||||
|
final TravelArticle article) {
|
||||||
String lang = article.getLang();
|
String lang = article.getLang();
|
||||||
String title = article.getTitle();
|
String title = article.getTitle();
|
||||||
if (TextUtils.isEmpty(lang) || TextUtils.isEmpty(title)) {
|
if (TextUtils.isEmpty(lang) || TextUtils.isEmpty(title)) {
|
||||||
|
@ -437,24 +439,24 @@ public class TravelDbHelper {
|
||||||
}
|
}
|
||||||
Map<String, List<WikivoyageSearchResult>> navMap = new HashMap<>();
|
Map<String, List<WikivoyageSearchResult>> navMap = new HashMap<>();
|
||||||
SQLiteConnection conn = openConnection();
|
SQLiteConnection conn = openConnection();
|
||||||
Set<String> headers = null;
|
Set<String> headers = new LinkedHashSet<String>();
|
||||||
Map<String, WikivoyageSearchResult> headerObjs = new HashMap<>();
|
Map<String, WikivoyageSearchResult> headerObjs = new HashMap<>();
|
||||||
if (conn != null) {
|
if (conn != null) {
|
||||||
List<String> params = new ArrayList<>();
|
List<String> params = new ArrayList<>();
|
||||||
StringBuilder query = new StringBuilder("SELECT a.trip_id, a.title, a.lang, a.is_part_of " +
|
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 = ? ");
|
+ "FROM travel_articles a WHERE is_part_of = ? and lang = ? ");
|
||||||
params.add(title);
|
params.add(title);
|
||||||
params.add(lang);
|
params.add(lang);
|
||||||
|
headers.add(title);
|
||||||
if (parts != null && parts.length > 0) {
|
if (parts != null && parts.length > 0) {
|
||||||
headers = new HashSet<>(Arrays.asList(parts));
|
headers.addAll(Arrays.asList(parts));
|
||||||
headers.add(title);
|
query.append("UNION SELECT a.trip_id, a.title, a.lang, a.is_part_of "
|
||||||
query.append("UNION SELECT a.trip_id, a.title, a.lang, a.is_part_of " +
|
+ "FROM travel_articles a WHERE title = ? and lang = ? ");
|
||||||
"FROM travel_articles a WHERE title = ? and lang = ? ");
|
|
||||||
params.add(parts[0]);
|
params.add(parts[0]);
|
||||||
params.add(lang);
|
params.add(lang);
|
||||||
for (String part : parts) {
|
for (String part : parts) {
|
||||||
query.append("UNION SELECT a.trip_id, a.title, a.lang, a.is_part_of " +
|
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 = ? ");
|
+ "FROM travel_articles a WHERE is_part_of = ? and lang = ? ");
|
||||||
params.add(part);
|
params.add(part);
|
||||||
params.add(lang);
|
params.add(lang);
|
||||||
}
|
}
|
||||||
|
@ -482,23 +484,21 @@ public class TravelDbHelper {
|
||||||
cursor.close();
|
cursor.close();
|
||||||
}
|
}
|
||||||
LinkedHashMap<WikivoyageSearchResult, List<WikivoyageSearchResult>> res = new LinkedHashMap<>();
|
LinkedHashMap<WikivoyageSearchResult, List<WikivoyageSearchResult>> res = new LinkedHashMap<>();
|
||||||
if (parts != null) {
|
for (String header : headers) {
|
||||||
for (String header : parts) {
|
WikivoyageSearchResult searchResult = headerObjs.get(header);
|
||||||
WikivoyageSearchResult searchResult = headerObjs.get(header);
|
List<WikivoyageSearchResult> results = navMap.get(header);
|
||||||
List<WikivoyageSearchResult> results = navMap.get(header);
|
if (results != null) {
|
||||||
if (results != null) {
|
Collections.sort(results, new Comparator<WikivoyageSearchResult>() {
|
||||||
Collections.sort(results, new Comparator<WikivoyageSearchResult>() {
|
@Override
|
||||||
@Override
|
public int compare(WikivoyageSearchResult o1, WikivoyageSearchResult o2) {
|
||||||
public int compare(WikivoyageSearchResult o1, WikivoyageSearchResult o2) {
|
return collator.compare(o1.articleTitles.get(0), o2.articleTitles.get(0));
|
||||||
return collator.compare(o1.articleTitles.get(0), o2.articleTitles.get(0));
|
}
|
||||||
}
|
});
|
||||||
});
|
WikivoyageSearchResult emptyResult = new WikivoyageSearchResult();
|
||||||
WikivoyageSearchResult emptyResult = new WikivoyageSearchResult();
|
emptyResult.articleTitles.add(header);
|
||||||
emptyResult.articleTitles.add(header);
|
emptyResult.tripId = -1;
|
||||||
emptyResult.tripId = -1;
|
searchResult = searchResult != null ? searchResult : emptyResult;
|
||||||
searchResult = searchResult != null ? searchResult : emptyResult;
|
res.put(searchResult, results);
|
||||||
res.put(searchResult, results);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|
Loading…
Reference in a new issue