Add the ability to open wikivoyage article from history
This commit is contained in:
parent
39e5fdf286
commit
9ef3f5144b
2 changed files with 49 additions and 4 deletions
|
@ -71,6 +71,12 @@ public class WikivoyageDbHelper {
|
||||||
collator = OsmAndCollator.primaryCollator();
|
collator = OsmAndCollator.primaryCollator();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private SQLiteConnection openConnection() {
|
||||||
|
String path = getDbFile(application).getAbsolutePath();
|
||||||
|
return application.getSQLiteAPI().openByAbsolutePath(path, true);
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public List<WikivoyageSearchResult> search(final String searchQuery) {
|
public List<WikivoyageSearchResult> search(final String searchQuery) {
|
||||||
List<WikivoyageSearchResult> res = new ArrayList<>();
|
List<WikivoyageSearchResult> res = new ArrayList<>();
|
||||||
|
@ -188,10 +194,38 @@ public class WikivoyageDbHelper {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@NonNull
|
||||||
private SQLiteConnection openConnection() {
|
public ArrayList<String> getArticleLangs(long cityId) {
|
||||||
String path = getDbFile(application).getAbsolutePath();
|
ArrayList<String> res = new ArrayList<>();
|
||||||
return application.getSQLiteAPI().openByAbsolutePath(path, true);
|
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
|
@NonNull
|
||||||
|
|
|
@ -22,6 +22,7 @@ import net.osmand.plus.R;
|
||||||
import net.osmand.plus.wikivoyage.WikivoyageArticleDialogFragment;
|
import net.osmand.plus.wikivoyage.WikivoyageArticleDialogFragment;
|
||||||
import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment;
|
import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment;
|
||||||
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
|
import net.osmand.plus.wikivoyage.data.WikivoyageLocalDataHelper;
|
||||||
|
import net.osmand.plus.wikivoyage.data.WikivoyageSearchHistoryItem;
|
||||||
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
|
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -106,6 +107,16 @@ public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment
|
||||||
WikivoyageSearchResult res = (WikivoyageSearchResult) item;
|
WikivoyageSearchResult res = (WikivoyageSearchResult) item;
|
||||||
WikivoyageArticleDialogFragment.showInstance(getFragmentManager(),
|
WikivoyageArticleDialogFragment.showInstance(getFragmentManager(),
|
||||||
res.getCityId(), new ArrayList<>(res.getLangs()));
|
res.getCityId(), new ArrayList<>(res.getLangs()));
|
||||||
|
} else if (item instanceof WikivoyageSearchHistoryItem) {
|
||||||
|
WikivoyageSearchHistoryItem historyItem = (WikivoyageSearchHistoryItem) item;
|
||||||
|
ArrayList<String> 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue