Fix local issues

This commit is contained in:
Victor Shcherb 2018-04-12 01:59:39 +02:00
parent 0f29a38d0e
commit 33ebf5822b
5 changed files with 83 additions and 95 deletions

View file

@ -58,7 +58,7 @@ public class IndexConstants {
public static final String SRTM_INDEX_DIR = "srtm/"; //$NON-NLS-1$
public static final String ROADS_INDEX_DIR = "roads/"; //$NON-NLS-1$
public static final String WIKI_INDEX_DIR = "wiki/"; //$NON-NLS-1$
public static final String WIKIVOYAGE_INDEX_DIR = "wikivoyage/";
public static final String WIKIVOYAGE_INDEX_DIR = "travel/";
public static final String AV_INDEX_DIR = "avnotes/"; //$NON-NLS-1$
public static final String FONT_INDEX_DIR = "fonts/"; //$NON-NLS-1$
public static final String VOICE_INDEX_DIR = "voice/"; //$NON-NLS-1$

View file

@ -83,6 +83,8 @@ public class LocalIndexHelper {
info.setDescription(app.getString(R.string.download_srtm_maps));
} else if (info.getType() == LocalIndexType.WIKI_DATA) {
info.setDescription(getInstalledDate(f));
} else if (info.getType() == LocalIndexType.TRAVEL_DATA) {
info.setDescription(getInstalledDate(f));
} else if (info.getType() == LocalIndexType.TTS_VOICE_DATA) {
info.setDescription(getInstalledDate(f));
} else if (info.getType() == LocalIndexType.DEACTIVATED) {
@ -117,6 +119,10 @@ public class LocalIndexHelper {
fileDir = app.getAppPath(IndexConstants.WIKI_INDEX_DIR);
fileName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName)
+ IndexConstants.BINARY_WIKI_MAP_INDEX_EXT;
} else if (type == LocalIndexType.TRAVEL_DATA) {
fileDir = app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR);
fileName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName)
+ IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT;
}
if (backuped) {
@ -135,33 +141,7 @@ public class LocalIndexHelper {
return null;
}
public LocalIndexInfo getLocalIndexInfo(String downloadName) {
LocalIndexInfo info = getLocalIndexInfo(LocalIndexType.MAP_DATA, downloadName, false, false);
if (info == null) {
info = getLocalIndexInfo(LocalIndexType.MAP_DATA, downloadName, true, false);
}
if (info == null) {
info = getLocalIndexInfo(LocalIndexType.SRTM_DATA, downloadName, false, false);
}
if (info == null) {
info = getLocalIndexInfo(LocalIndexType.WIKI_DATA, downloadName, false, false);
}
if (info == null) {
info = getLocalIndexInfo(LocalIndexType.MAP_DATA, downloadName, false, true);
}
if (info == null) {
info = getLocalIndexInfo(LocalIndexType.MAP_DATA, downloadName, true, true);
}
if (info == null) {
info = getLocalIndexInfo(LocalIndexType.SRTM_DATA, downloadName, false, true);
}
if (info == null) {
info = getLocalIndexInfo(LocalIndexType.WIKI_DATA, downloadName, false, true);
}
return info;
}
public List<LocalIndexInfo> getLocalIndexInfos(String downloadName) {
List<LocalIndexInfo> list = new ArrayList<>();
@ -210,6 +190,7 @@ public class LocalIndexHelper {
loadTilesData(app.getAppPath(IndexConstants.TILES_INDEX_DIR), result, false, loadTask);
loadSrtmData(app.getAppPath(IndexConstants.SRTM_INDEX_DIR), result, loadTask);
loadWikiData(app.getAppPath(IndexConstants.WIKI_INDEX_DIR), result, loadTask);
loadTravelData(app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), result, loadTask);
//loadVoiceData(app.getAppPath(IndexConstants.TTSVOICE_INDEX_EXT_ZIP), result, true, loadTask);
loadVoiceData(app.getAppPath(IndexConstants.VOICE_INDEX_DIR), result, false, loadTask);
loadFontData(app.getAppPath(IndexConstants.FONT_INDEX_DIR), result, false, loadTask);
@ -329,6 +310,19 @@ public class LocalIndexHelper {
}
}
}
private void loadTravelData(File mapPath, List<LocalIndexInfo> result, AbstractLoadLocalIndexTask loadTask) {
if (mapPath.canRead()) {
for (File mapFile : listFilesSorted(mapPath)) {
if (mapFile.isFile() && mapFile.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT)) {
LocalIndexInfo info = new LocalIndexInfo(LocalIndexType.TRAVEL_DATA, mapFile, false, app);
updateDescription(info);
result.add(info);
loadTask.loadFile(info);
}
}
}
}
private void loadObfData(File mapPath, List<LocalIndexInfo> result, boolean backup, AbstractLoadLocalIndexTask loadTask, Map<String, String> loadedMaps) {
if (mapPath.canRead()) {
@ -357,6 +351,7 @@ public class LocalIndexHelper {
TILES_DATA(R.string.local_indexes_cat_tile, R.drawable.ic_map, 60),
SRTM_DATA(R.string.local_indexes_cat_srtm, R.drawable.ic_plugin_srtm, 40),
WIKI_DATA(R.string.local_indexes_cat_wiki, R.drawable.ic_plugin_wikipedia, 50),
TRAVEL_DATA(R.string.download_maps_travel, R.drawable.ic_plugin_wikipedia, 60),
TTS_VOICE_DATA(R.string.local_indexes_cat_tts, R.drawable.ic_action_volume_up, 20),
VOICE_DATA(R.string.local_indexes_cat_voice, R.drawable.ic_action_volume_up, 30),
FONT_DATA(R.string.fonts_header, R.drawable.ic_action_map_language, 35),

View file

@ -183,7 +183,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
}
};
if (info.getType() == LocalIndexType.MAP_DATA || info.getType() == LocalIndexType.SRTM_DATA ||
info.getType() == LocalIndexType.WIKI_DATA) {
info.getType() == LocalIndexType.WIKI_DATA ) {
if (!info.isBackupedData()) {
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.local_index_mi_backup, getContext())
@ -444,6 +444,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
parent = getMyApplication().getAppPath(IndexConstants.SRTM_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.WIKI_DATA) {
parent = getMyApplication().getAppPath(IndexConstants.WIKI_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.TRAVEL_DATA) {
parent = getMyApplication().getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.TTS_VOICE_DATA) {
parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.VOICE_DATA) {

View file

@ -537,6 +537,8 @@ public class MapDataMenuController extends MenuController {
parent = app.getAppPath(IndexConstants.SRTM_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.WIKI_DATA) {
parent = app.getAppPath(IndexConstants.WIKI_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.TRAVEL_DATA) {
parent = app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.TTS_VOICE_DATA) {
parent = app.getAppPath(IndexConstants.VOICE_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.VOICE_DATA) {
@ -561,6 +563,8 @@ public class MapDataMenuController extends MenuController {
return DownloadActivityType.SRTM_COUNTRY_FILE;
} else if (localIndexInfo.getOriginalType() == LocalIndexType.WIKI_DATA) {
return DownloadActivityType.WIKIPEDIA_FILE;
} else if (localIndexInfo.getOriginalType() == LocalIndexType.TRAVEL_DATA) {
return DownloadActivityType.WIKIVOYAGE_FILE;
} else if (localIndexInfo.getOriginalType() == LocalIndexType.TTS_VOICE_DATA
|| localIndexInfo.getOriginalType() == LocalIndexType.VOICE_DATA) {
return DownloadActivityType.VOICE_FILE;

View file

@ -122,42 +122,39 @@ public class WikivoyageDbHelper {
SQLiteConnection conn = openConnection();
String[] queries = searchQuery.replace('_', ' ').replace('/', ' ').split(" ");
if (conn != null) {
try {
List<String> params = new ArrayList<>();
String query = "SELECT distinct wa.city_id, wa.title, wa.lang, wa.is_part_of, wa.image_title " +
"FROM wikivoyage_articles wa WHERE wa.city_id in " +
" (SELECT city_id FROM wikivoyage_search WHERE search_term LIKE";
for (String q : queries) {
if (q.trim().length() > 0) {
if (params.size() > 5) {
// don't explode the query search much
break;
}
if (params.size() > 0) {
query += " AND city_id IN (SELECT city_id FROM wikivoyage_search WHERE search_term LIKE ?) ";
} else {
query += "?";
}
params.add(q.trim() + "%");
List<String> params = new ArrayList<>();
String query = "SELECT distinct wa.city_id, wa.title, wa.lang, wa.is_part_of, wa.image_title "
+ "FROM wikivoyage_articles wa WHERE wa.city_id in "
+ " (SELECT city_id FROM wikivoyage_search WHERE search_term LIKE";
for (String q : queries) {
if (q.trim().length() > 0) {
if (params.size() > 5) {
// don't explode the query search much
break;
}
}
query += ") ";
if (params.size() > 0) {
SQLiteCursor cursor = conn.rawQuery(query, params.toArray(new String[params.size()]));
if (cursor.moveToFirst()) {
do {
WikivoyageSearchResult rs = new WikivoyageSearchResult();
rs.cityId = cursor.getLong(0);
rs.articleTitles.add(cursor.getString(1));
rs.langs.add(cursor.getString(2));
rs.isPartOf = cursor.getString(3);
rs.imageTitle = cursor.getString(4);
res.add(rs);
} while (cursor.moveToNext());
if (params.size() > 0) {
query += " AND city_id IN (SELECT city_id FROM wikivoyage_search WHERE search_term LIKE ?) ";
} else {
query += "?";
}
params.add(q.trim() + "%");
}
} finally {
conn.close();
}
query += ") ";
if (params.size() > 0) {
SQLiteCursor cursor = conn.rawQuery(query, params.toArray(new String[params.size()]));
if (cursor.moveToFirst()) {
do {
WikivoyageSearchResult rs = new WikivoyageSearchResult();
rs.cityId = cursor.getLong(0);
rs.articleTitles.add(cursor.getString(1));
rs.langs.add(cursor.getString(2));
rs.isPartOf = cursor.getString(3);
rs.imageTitle = cursor.getString(4);
res.add(rs);
} while (cursor.moveToNext());
}
cursor.close();
}
}
@ -217,18 +214,12 @@ public class WikivoyageDbHelper {
WikivoyageArticle res = null;
SQLiteConnection conn = openConnection();
if (conn != null) {
try {
SQLiteCursor cursor = conn.rawQuery(ARTICLES_TABLE_SELECT + " WHERE " +
ARTICLES_COL_CITY_ID + " = ? AND " +
ARTICLES_COL_LANG + " = ?",
new String[]{String.valueOf(cityId), lang});
if (cursor.moveToFirst()) {
res = readArticle(cursor);
}
cursor.close();
} finally {
conn.close();
SQLiteCursor cursor = conn.rawQuery(ARTICLES_TABLE_SELECT + " WHERE " + ARTICLES_COL_CITY_ID + " = ? AND "
+ ARTICLES_COL_LANG + " = ?", new String[] { String.valueOf(cityId), lang });
if (cursor.moveToFirst()) {
res = readArticle(cursor);
}
cursor.close();
}
return res;
}
@ -238,31 +229,27 @@ public class WikivoyageDbHelper {
ArrayList<String> 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);
}
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(lang);
res.add(0, lang);
}
} while (cursor.moveToNext());
}
} finally {
conn.close();
} else {
res.add(lang);
}
} while (cursor.moveToNext());
}
cursor.close();
}
return res;
}