diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java index 92859744f6..d5b38c5e99 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/WikivoyageDbHelper.java @@ -71,6 +71,12 @@ public class WikivoyageDbHelper { collator = OsmAndCollator.primaryCollator(); } + @Nullable + private SQLiteConnection openConnection() { + String path = getDbFile(application).getAbsolutePath(); + return application.getSQLiteAPI().openByAbsolutePath(path, true); + } + @NonNull public List search(final String searchQuery) { List res = new ArrayList<>(); @@ -188,10 +194,38 @@ public class WikivoyageDbHelper { return res; } - @Nullable - private SQLiteConnection openConnection() { - String path = getDbFile(application).getAbsolutePath(); - return application.getSQLiteAPI().openByAbsolutePath(path, true); + @NonNull + public ArrayList getArticleLangs(long cityId) { + ArrayList res = new ArrayList<>(); + SQLiteConnection conn = openConnection(); + if (conn != null) { + try { + SQLiteCursor cursor = conn.rawQuery("SELECT " + ARTICLES_COL_LANG + + " FROM " + ARTICLES_TABLE_NAME + + " WHERE " + ARTICLES_COL_CITY_ID + " = ?", + new String[]{String.valueOf(cityId)}); + if (cursor.moveToFirst()) { + String baseLang = application.getLanguage(); + do { + String lang = cursor.getString(0); + if (lang.equals(baseLang)) { + res.add(0, lang); + } else if (lang.equals("en")) { + if (res.size() > 0 && res.get(0).equals(baseLang)) { + res.add(1, lang); + } else { + res.add(0, lang); + } + } else { + res.add(lang); + } + } while (cursor.moveToNext()); + } + } finally { + conn.close(); + } + } + return res; } @NonNull diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchDialogFragment.java index 180d1a5eba..4d96b3b4ee 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/search/WikivoyageSearchDialogFragment.java @@ -22,6 +22,7 @@ import net.osmand.plus.R; import net.osmand.plus.wikivoyage.WikivoyageArticleDialogFragment; import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment; import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper; +import net.osmand.plus.wikivoyage.data.WikivoyageSearchHistoryItem; import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult; import java.util.ArrayList; @@ -106,6 +107,16 @@ public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment WikivoyageSearchResult res = (WikivoyageSearchResult) item; WikivoyageArticleDialogFragment.showInstance(getFragmentManager(), res.getCityId(), new ArrayList<>(res.getLangs())); + } else if (item instanceof WikivoyageSearchHistoryItem) { + WikivoyageSearchHistoryItem historyItem = (WikivoyageSearchHistoryItem) item; + ArrayList langs = getMyApplication().getWikivoyageDbHelper() + .getArticleLangs(historyItem.getCityId()); + boolean selectedLangExists = langs.remove(historyItem.getLang()); + if (selectedLangExists) { + langs.add(0, historyItem.getLang()); + } + WikivoyageArticleDialogFragment.showInstance(getFragmentManager(), + historyItem.getCityId(), langs); } } }