Fix local issues
This commit is contained in:
parent
0f29a38d0e
commit
33ebf5822b
5 changed files with 83 additions and 95 deletions
|
@ -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$
|
||||||
|
|
|
@ -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),
|
||||||
|
|
|
@ -183,7 +183,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (info.getType() == LocalIndexType.MAP_DATA || info.getType() == LocalIndexType.SRTM_DATA ||
|
if (info.getType() == LocalIndexType.MAP_DATA || info.getType() == LocalIndexType.SRTM_DATA ||
|
||||||
info.getType() == LocalIndexType.WIKI_DATA) {
|
info.getType() == LocalIndexType.WIKI_DATA ) {
|
||||||
if (!info.isBackupedData()) {
|
if (!info.isBackupedData()) {
|
||||||
adapter.addItem(new ContextMenuItem.ItemBuilder()
|
adapter.addItem(new ContextMenuItem.ItemBuilder()
|
||||||
.setTitleId(R.string.local_index_mi_backup, getContext())
|
.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);
|
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) {
|
||||||
|
|
|
@ -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;
|
||||||
|
|
|
@ -122,42 +122,39 @@ 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) {
|
// don't explode the query search much
|
||||||
// don't explode the query search much
|
break;
|
||||||
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() + "%");
|
|
||||||
}
|
}
|
||||||
}
|
if (params.size() > 0) {
|
||||||
query += ") ";
|
query += " AND city_id IN (SELECT city_id FROM wikivoyage_search WHERE search_term LIKE ?) ";
|
||||||
if (params.size() > 0) {
|
} else {
|
||||||
SQLiteCursor cursor = conn.rawQuery(query, params.toArray(new String[params.size()]));
|
query += "?";
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
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;
|
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 " +
|
if (cursor.moveToFirst()) {
|
||||||
ARTICLES_COL_LANG + " = ?",
|
res = readArticle(cursor);
|
||||||
new String[]{String.valueOf(cityId), lang});
|
|
||||||
if (cursor.moveToFirst()) {
|
|
||||||
res = readArticle(cursor);
|
|
||||||
}
|
|
||||||
cursor.close();
|
|
||||||
} finally {
|
|
||||||
conn.close();
|
|
||||||
}
|
}
|
||||||
|
cursor.close();
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -238,31 +229,27 @@ 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 +
|
if (cursor.moveToFirst()) {
|
||||||
" WHERE " + ARTICLES_COL_CITY_ID + " = ?",
|
String baseLang = application.getLanguage();
|
||||||
new String[]{String.valueOf(cityId)});
|
do {
|
||||||
if (cursor.moveToFirst()) {
|
String lang = cursor.getString(0);
|
||||||
String baseLang = application.getLanguage();
|
if (lang.equals(baseLang)) {
|
||||||
do {
|
res.add(0, lang);
|
||||||
String lang = cursor.getString(0);
|
} else if (lang.equals("en")) {
|
||||||
if (lang.equals(baseLang)) {
|
if (res.size() > 0 && res.get(0).equals(baseLang)) {
|
||||||
res.add(0, lang);
|
res.add(1, 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 {
|
} else {
|
||||||
res.add(lang);
|
res.add(0, lang);
|
||||||
}
|
}
|
||||||
} while (cursor.moveToNext());
|
} else {
|
||||||
}
|
res.add(lang);
|
||||||
} finally {
|
}
|
||||||
conn.close();
|
} while (cursor.moveToNext());
|
||||||
}
|
}
|
||||||
|
cursor.close();
|
||||||
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue