Merge pull request #10366 from osmandapp/add_wikivoyage_obf_download

Add wikivoyage obf download
This commit is contained in:
vshcherb 2020-12-09 18:45:31 +01:00 committed by GitHub
commit 8b105a954a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 43 additions and 12 deletions

View file

@ -20,6 +20,8 @@ public class IndexConstants {
public static final String BINARY_MAP_INDEX_EXT_ZIP = ".obf.zip"; //$NON-NLS-1$
public static final String BINARY_WIKIVOYAGE_MAP_INDEX_EXT = ".sqlite"; //$NON-NLS-1$
public static final String BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT = ".travel.obf"; //$NON-NLS-1$
public static final String BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT_ZIP = ".travel.obf.zip"; //$NON-NLS-1$
public static final String BINARY_WIKI_MAP_INDEX_EXT = ".wiki.obf"; //$NON-NLS-1$
public static final String BINARY_WIKI_MAP_INDEX_EXT_ZIP = ".wiki.obf.zip"; //$NON-NLS-1$
public static final String BINARY_ROAD_MAP_INDEX_EXT = ".road.obf"; //$NON-NLS-1$

View file

@ -12,6 +12,7 @@ import net.osmand.map.TileSourceManager;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.SQLiteTileSource;
import net.osmand.plus.Version;
import net.osmand.plus.download.ui.AbstractLoadLocalIndexTask;
import net.osmand.plus.voice.JSMediaCommandPlayerImpl;
import net.osmand.plus.voice.JSTTSCommandPlayerImpl;
@ -316,7 +317,9 @@ 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)) {
if (mapFile.isFile() && mapFile.getName().endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT)
|| (mapFile.isFile() && mapFile.getName().endsWith(IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT)
&& Version.isDeveloperVersion(app))) { //todo remove when .travel.obf will be used in production
LocalIndexInfo info = new LocalIndexInfo(LocalIndexType.TRAVEL_DATA, mapFile, false, app);
updateDescription(info);
result.add(info);

View file

@ -49,6 +49,8 @@ public class DownloadActivityType {
new DownloadActivityType(R.string.download_wikipedia_maps, R.drawable.ic_plugin_wikipedia, "wikimap", 60);
public static final DownloadActivityType WIKIVOYAGE_FILE =
new DownloadActivityType(R.string.shared_string_wikivoyage, R.drawable.ic_plugin_wikipedia, "wikivoyage", 65);
public static final DownloadActivityType TRAVEL_FILE =
new DownloadActivityType(R.string.shared_string_wikivoyage, R.drawable.ic_plugin_wikipedia, "travel", 66);
public static final DownloadActivityType LIVE_UPDATES_FILE =
new DownloadActivityType(R.string.download_live_updates, "live_updates", 70);
public static final DownloadActivityType GPX_FILE =
@ -131,7 +133,10 @@ public class DownloadActivityType {
return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_WIKI_MAP_INDEX_EXT_ZIP,
IndexConstants.BINARY_MAP_VERSION));
} else if (WIKIVOYAGE_FILE == this) {
return fileName.endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT);
return fileName.endsWith(IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT);
} else if (TRAVEL_FILE == this) {
return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT_ZIP,
IndexConstants.BINARY_MAP_VERSION));
} else if (SRTM_COUNTRY_FILE == this) {
return fileName.endsWith(addVersionToExt(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT_ZIP,
IndexConstants.BINARY_MAP_VERSION));
@ -165,7 +170,7 @@ public class DownloadActivityType {
return ctx.getAppPath(IndexConstants.SRTM_INDEX_DIR);
} else if (WIKIPEDIA_FILE == this) {
return ctx.getAppPath(IndexConstants.WIKI_INDEX_DIR);
} else if (WIKIVOYAGE_FILE == this) {
} else if (WIKIVOYAGE_FILE == this || TRAVEL_FILE == this) {
return ctx.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR);
} else if (LIVE_UPDATES_FILE == this) {
return ctx.getAppPath(IndexConstants.LIVE_INDEX_DIR);
@ -220,6 +225,8 @@ public class DownloadActivityType {
return IndexConstants.BINARY_WIKI_MAP_INDEX_EXT;
} else if (WIKIVOYAGE_FILE == this) {
return IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT;
} else if (TRAVEL_FILE == this) {
return IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT;
} else if (LIVE_UPDATES_FILE == this) {
return BINARY_MAP_INDEX_EXT;
} else if (HILLSHADE_FILE == this) {
@ -247,6 +254,8 @@ public class DownloadActivityType {
return "&wiki=yes";
} else if (this == WIKIVOYAGE_FILE) {
return "&wikivoyage=yes";
} else if (this == TRAVEL_FILE) {
return "&wikivoyage=yes";
} else if (this == HILLSHADE_FILE) {
return "&hillshade=yes";
} else if (this == SLOPE_FILE) {
@ -282,9 +291,13 @@ public class DownloadActivityType {
}
public IndexItem parseIndexItem(Context ctx, XmlPullParser parser) {
public IndexItem parseIndexItem(OsmandApplication ctx, XmlPullParser parser) {
if (TRAVEL_FILE == this && !Version.isDeveloperVersion(ctx)) {
//todo remove "if" when .travel.obf will be used in production
return null;
}
String name = parser.getAttributeValue(null, "name"); //$NON-NLS-1$
if(!isAccepted(name)) {
if (!isAccepted(name)) {
return null;
}
String size = parser.getAttributeValue(null, "size"); //$NON-NLS-1$
@ -415,7 +428,9 @@ public class DownloadActivityType {
if (this == WIKIVOYAGE_FILE) {
return baseNameWithoutVersion + IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT;
}
if (this == TRAVEL_FILE) {
return baseNameWithoutVersion + IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT;
}
if (this == ROADS_FILE) {
return baseNameWithoutVersion + IndexConstants.BINARY_ROAD_MAP_INDEX_EXT;
}

View file

@ -130,14 +130,18 @@ public class DownloadResources extends DownloadResourceGroup {
java.text.DateFormat dateFormat = app.getResourceManager().getDateFormat();
Map<String, String> indexActivatedFileNames = app.getResourceManager().getIndexFileNames();
listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT, indexActivatedFileNames);
listWithAlternatives(dateFormat, app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT,
indexActivatedFileNames);
listWithAlternatives(dateFormat, app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR),
IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT, indexActivatedFileNames);
listWithAlternatives(dateFormat, app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR),
IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT, indexActivatedFileNames);
Map<String, String> indexFileNames = app.getResourceManager().getIndexFileNames();
listWithAlternatives(dateFormat, app.getAppPath(""), IndexConstants.EXTRA_EXT, indexFileNames);
listWithAlternatives(dateFormat, app.getAppPath(IndexConstants.TILES_INDEX_DIR), IndexConstants.SQLITE_EXT,
indexFileNames);
listWithAlternatives(dateFormat, app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR), IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT,
indexFileNames);
listWithAlternatives(dateFormat, app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR),
IndexConstants.BINARY_WIKIVOYAGE_MAP_INDEX_EXT, indexFileNames);
listWithAlternatives(dateFormat, app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR),
IndexConstants.BINARY_TRAVEL_GUIDE_MAP_INDEX_EXT, indexFileNames);
app.getResourceManager().getBackupIndexes(indexFileNames);
this.indexFileNames = indexFileNames;
this.indexActivatedFileNames = indexActivatedFileNames;
@ -179,7 +183,8 @@ public class DownloadResources extends DownloadResourceGroup {
|| item.getType() == DownloadActivityType.DEPTH_CONTOUR_FILE
|| item.getType() == DownloadActivityType.SRTM_COUNTRY_FILE) {
outdated = true;
} else if(item.getType() == DownloadActivityType.WIKIVOYAGE_FILE) {
} else if (item.getType() == DownloadActivityType.WIKIVOYAGE_FILE
|| item.getType() == DownloadActivityType.TRAVEL_FILE) {
long itemSize = item.getContentSize();
long oldItemSize = app.getAppPath(IndexConstants.WIKIVOYAGE_INDEX_DIR +
item.getTargetFileName()).length();
@ -343,7 +348,11 @@ public class DownloadResources extends DownloadResourceGroup {
}
continue;
}
if(ii.getType() == DownloadActivityType.WIKIVOYAGE_FILE) {
if (ii.getType() == DownloadActivityType.WIKIVOYAGE_FILE) {
wikivoyageMaps.addItem(ii);
continue;
}
if (ii.getType() == DownloadActivityType.TRAVEL_FILE) {
wikivoyageMaps.addItem(ii);
continue;
}

View file

@ -415,6 +415,8 @@ public class ItemViewHolder {
tp = LocalIndexType.MAP_DATA;
} else if (indexItem.getType() == DownloadActivityType.WIKIVOYAGE_FILE) {
tp = LocalIndexType.MAP_DATA;
} else if (indexItem.getType() == DownloadActivityType.TRAVEL_FILE) {
tp = LocalIndexType.MAP_DATA;
} else if (indexItem.getType() == DownloadActivityType.FONT_FILE) {
tp = LocalIndexType.FONT_DATA;
} else if (indexItem.getType() == DownloadActivityType.VOICE_FILE) {