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 SRTM_INDEX_DIR = "srtm/"; //$NON-NLS-1$
public static final String ROADS_INDEX_DIR = "roads/"; //$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 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 AV_INDEX_DIR = "avnotes/"; //$NON-NLS-1$
public static final String FONT_INDEX_DIR = "fonts/"; //$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$ 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)); info.setDescription(app.getString(R.string.download_srtm_maps));
} else if (info.getType() == LocalIndexType.WIKI_DATA) { } else if (info.getType() == LocalIndexType.WIKI_DATA) {
info.setDescription(getInstalledDate(f)); info.setDescription(getInstalledDate(f));
} else if (info.getType() == LocalIndexType.TRAVEL_DATA) {
info.setDescription(getInstalledDate(f));
} else if (info.getType() == LocalIndexType.TTS_VOICE_DATA) { } else if (info.getType() == LocalIndexType.TTS_VOICE_DATA) {
info.setDescription(getInstalledDate(f)); info.setDescription(getInstalledDate(f));
} else if (info.getType() == LocalIndexType.DEACTIVATED) { } else if (info.getType() == LocalIndexType.DEACTIVATED) {
@ -117,6 +119,10 @@ public class LocalIndexHelper {
fileDir = app.getAppPath(IndexConstants.WIKI_INDEX_DIR); fileDir = app.getAppPath(IndexConstants.WIKI_INDEX_DIR);
fileName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName) fileName = Algorithms.capitalizeFirstLetterAndLowercase(downloadName)
+ IndexConstants.BINARY_WIKI_MAP_INDEX_EXT; + 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) { if (backuped) {
@ -135,33 +141,7 @@ public class LocalIndexHelper {
return null; 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) { public List<LocalIndexInfo> getLocalIndexInfos(String downloadName) {
List<LocalIndexInfo> list = new ArrayList<>(); List<LocalIndexInfo> list = new ArrayList<>();
@ -210,6 +190,7 @@ public class LocalIndexHelper {
loadTilesData(app.getAppPath(IndexConstants.TILES_INDEX_DIR), result, false, loadTask); loadTilesData(app.getAppPath(IndexConstants.TILES_INDEX_DIR), result, false, loadTask);
loadSrtmData(app.getAppPath(IndexConstants.SRTM_INDEX_DIR), result, loadTask); loadSrtmData(app.getAppPath(IndexConstants.SRTM_INDEX_DIR), result, loadTask);
loadWikiData(app.getAppPath(IndexConstants.WIKI_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.TTSVOICE_INDEX_EXT_ZIP), result, true, loadTask);
loadVoiceData(app.getAppPath(IndexConstants.VOICE_INDEX_DIR), result, false, loadTask); loadVoiceData(app.getAppPath(IndexConstants.VOICE_INDEX_DIR), result, false, loadTask);
loadFontData(app.getAppPath(IndexConstants.FONT_INDEX_DIR), result, false, loadTask); loadFontData(app.getAppPath(IndexConstants.FONT_INDEX_DIR), result, false, loadTask);
@ -330,6 +311,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) { private void loadObfData(File mapPath, List<LocalIndexInfo> result, boolean backup, AbstractLoadLocalIndexTask loadTask, Map<String, String> loadedMaps) {
if (mapPath.canRead()) { if (mapPath.canRead()) {
for (File mapFile : listFilesSorted(mapPath)) { for (File mapFile : listFilesSorted(mapPath)) {
@ -357,6 +351,7 @@ public class LocalIndexHelper {
TILES_DATA(R.string.local_indexes_cat_tile, R.drawable.ic_map, 60), 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), 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), 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), 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), 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), FONT_DATA(R.string.fonts_header, R.drawable.ic_action_map_language, 35),

View file

@ -444,6 +444,8 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
parent = getMyApplication().getAppPath(IndexConstants.SRTM_INDEX_DIR); parent = getMyApplication().getAppPath(IndexConstants.SRTM_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.WIKI_DATA) { } else if (i.getOriginalType() == LocalIndexType.WIKI_DATA) {
parent = getMyApplication().getAppPath(IndexConstants.WIKI_INDEX_DIR); 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) { } else if (i.getOriginalType() == LocalIndexType.TTS_VOICE_DATA) {
parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR); parent = getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.VOICE_DATA) { } 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); parent = app.getAppPath(IndexConstants.SRTM_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.WIKI_DATA) { } else if (i.getOriginalType() == LocalIndexType.WIKI_DATA) {
parent = app.getAppPath(IndexConstants.WIKI_INDEX_DIR); 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) { } else if (i.getOriginalType() == LocalIndexType.TTS_VOICE_DATA) {
parent = app.getAppPath(IndexConstants.VOICE_INDEX_DIR); parent = app.getAppPath(IndexConstants.VOICE_INDEX_DIR);
} else if (i.getOriginalType() == LocalIndexType.VOICE_DATA) { } else if (i.getOriginalType() == LocalIndexType.VOICE_DATA) {
@ -561,6 +563,8 @@ public class MapDataMenuController extends MenuController {
return DownloadActivityType.SRTM_COUNTRY_FILE; return DownloadActivityType.SRTM_COUNTRY_FILE;
} else if (localIndexInfo.getOriginalType() == LocalIndexType.WIKI_DATA) { } else if (localIndexInfo.getOriginalType() == LocalIndexType.WIKI_DATA) {
return DownloadActivityType.WIKIPEDIA_FILE; return DownloadActivityType.WIKIPEDIA_FILE;
} else if (localIndexInfo.getOriginalType() == LocalIndexType.TRAVEL_DATA) {
return DownloadActivityType.WIKIVOYAGE_FILE;
} else if (localIndexInfo.getOriginalType() == LocalIndexType.TTS_VOICE_DATA } else if (localIndexInfo.getOriginalType() == LocalIndexType.TTS_VOICE_DATA
|| localIndexInfo.getOriginalType() == LocalIndexType.VOICE_DATA) { || localIndexInfo.getOriginalType() == LocalIndexType.VOICE_DATA) {
return DownloadActivityType.VOICE_FILE; return DownloadActivityType.VOICE_FILE;

View file

@ -122,11 +122,10 @@ public class WikivoyageDbHelper {
SQLiteConnection conn = openConnection(); SQLiteConnection conn = openConnection();
String[] queries = searchQuery.replace('_', ' ').replace('/', ' ').split(" "); String[] queries = searchQuery.replace('_', ' ').replace('/', ' ').split(" ");
if (conn != null) { if (conn != null) {
try {
List<String> params = new ArrayList<>(); List<String> params = new ArrayList<>();
String query = "SELECT distinct wa.city_id, wa.title, wa.lang, wa.is_part_of, wa.image_title " + 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 " + + "FROM wikivoyage_articles wa WHERE wa.city_id in "
" (SELECT city_id FROM wikivoyage_search WHERE search_term LIKE"; + " (SELECT city_id FROM wikivoyage_search WHERE search_term LIKE";
for (String q : queries) { for (String q : queries) {
if (q.trim().length() > 0) { if (q.trim().length() > 0) {
if (params.size() > 5) { if (params.size() > 5) {
@ -155,9 +154,7 @@ public class WikivoyageDbHelper {
res.add(rs); res.add(rs);
} while (cursor.moveToNext()); } while (cursor.moveToNext());
} }
} cursor.close();
} finally {
conn.close();
} }
} }
@ -217,18 +214,12 @@ public class WikivoyageDbHelper {
WikivoyageArticle res = null; WikivoyageArticle res = null;
SQLiteConnection conn = openConnection(); SQLiteConnection conn = openConnection();
if (conn != null) { if (conn != null) {
try { SQLiteCursor cursor = conn.rawQuery(ARTICLES_TABLE_SELECT + " WHERE " + ARTICLES_COL_CITY_ID + " = ? AND "
SQLiteCursor cursor = conn.rawQuery(ARTICLES_TABLE_SELECT + " WHERE " + + ARTICLES_COL_LANG + " = ?", new String[] { String.valueOf(cityId), lang });
ARTICLES_COL_CITY_ID + " = ? AND " +
ARTICLES_COL_LANG + " = ?",
new String[]{String.valueOf(cityId), lang});
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
res = readArticle(cursor); res = readArticle(cursor);
} }
cursor.close(); cursor.close();
} finally {
conn.close();
}
} }
return res; return res;
} }
@ -238,11 +229,8 @@ public class WikivoyageDbHelper {
ArrayList<String> res = new ArrayList<>(); ArrayList<String> res = new ArrayList<>();
SQLiteConnection conn = openConnection(); SQLiteConnection conn = openConnection();
if (conn != null) { if (conn != null) {
try { SQLiteCursor cursor = conn.rawQuery("SELECT " + ARTICLES_COL_LANG + " FROM " + ARTICLES_TABLE_NAME
SQLiteCursor cursor = conn.rawQuery("SELECT " + ARTICLES_COL_LANG + + " WHERE " + ARTICLES_COL_CITY_ID + " = ?", new String[] { String.valueOf(cityId) });
" FROM " + ARTICLES_TABLE_NAME +
" WHERE " + ARTICLES_COL_CITY_ID + " = ?",
new String[]{String.valueOf(cityId)});
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {
String baseLang = application.getLanguage(); String baseLang = application.getLanguage();
do { do {
@ -260,9 +248,8 @@ public class WikivoyageDbHelper {
} }
} while (cursor.moveToNext()); } while (cursor.moveToNext());
} }
} finally { cursor.close();
conn.close();
}
} }
return res; return res;
} }