Fixed wiki maps not being detected offline
This commit is contained in:
parent
ecb25c835d
commit
949a44d061
2 changed files with 51 additions and 29 deletions
|
@ -1,6 +1,5 @@
|
|||
package net.osmand.map;
|
||||
|
||||
|
||||
import net.osmand.OsmAndCollator;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.ResultMatcher;
|
||||
|
@ -705,19 +704,22 @@ public class OsmandRegions {
|
|||
}
|
||||
if (mapDataObjects != null) {
|
||||
for (BinaryMapDataObject obj : mapDataObjects) {
|
||||
result.add(getRegionData(getFullName(obj)));
|
||||
if (obj != null) {
|
||||
String fullName = getFullName(obj);
|
||||
WorldRegion reg = getRegionData(fullName);
|
||||
if (reg != null) {
|
||||
result.add(reg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public BinaryMapDataObject findBinaryMapDataObject(LatLon latLon) {
|
||||
List<BinaryMapDataObject> mapDataObjects = null;
|
||||
try {
|
||||
mapDataObjects = getBinaryMapDataObjects(latLon);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
public BinaryMapDataObject findBinaryMapDataObject(LatLon latLon) throws IOException {
|
||||
List<BinaryMapDataObject> mapDataObjects = getBinaryMapDataObjects(latLon);
|
||||
BinaryMapDataObject res = null;
|
||||
double smallestArea = -1;
|
||||
if (mapDataObjects != null) {
|
||||
|
@ -732,7 +734,6 @@ public class OsmandRegions {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import net.osmand.IndexConstants;
|
|||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.map.WorldRegion;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -23,6 +24,7 @@ import net.osmand.plus.download.DownloadResources;
|
|||
import net.osmand.plus.download.IndexItem;
|
||||
import net.osmand.plus.resources.AmenityIndexRepositoryBinary;
|
||||
import net.osmand.plus.wikivoyage.article.WikivoyageArticleWikiLinkFragment;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
@ -93,26 +95,28 @@ public class WikiArticleHelper {
|
|||
OsmandApplication application = activity.getMyApplication();
|
||||
List<Amenity> results = new ArrayList<>();
|
||||
if (application != null && !isCancelled()) {
|
||||
List<WorldRegion> regions;
|
||||
if (articleLatLon != null) {
|
||||
regions = application.getRegions().getWoldRegions(articleLatLon);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
AmenityIndexRepositoryBinary repository = getAmenityRepositoryByRegion(regions, application);
|
||||
if (repository == null) {
|
||||
if (regionName == null || regionName.isEmpty()) {
|
||||
IndexItem item = null;
|
||||
try {
|
||||
if (articleLatLon != null) {
|
||||
item = DownloadResources.findSmallestIndexItemAt(application,
|
||||
articleLatLon, DownloadActivityType.WIKIPEDIA_FILE);
|
||||
}
|
||||
item = DownloadResources.findSmallestIndexItemAt(application, articleLatLon,
|
||||
DownloadActivityType.WIKIPEDIA_FILE);
|
||||
} catch (IOException e) {
|
||||
Log.e(TAG, e.getMessage(), e);
|
||||
}
|
||||
String filename = null;
|
||||
if (item != null && item.isDownloaded()) {
|
||||
filename = getFilenameFromIndex(item.getFileName());
|
||||
}
|
||||
AmenityIndexRepositoryBinary repository = application.getResourceManager()
|
||||
.getAmenityRepositoryByFileName(filename == null ? "" : filename);
|
||||
if (repository == null) {
|
||||
if ((regionName == null || regionName.isEmpty()) && item != null) {
|
||||
if (item != null) {
|
||||
regionName = (getRegionName(item.getFileName(), application.getRegions()));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (isCancelled()) {
|
||||
return null;
|
||||
|
@ -124,6 +128,23 @@ public class WikiArticleHelper {
|
|||
return results;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private AmenityIndexRepositoryBinary getAmenityRepositoryByRegion(@NonNull List<WorldRegion> regions, @NonNull OsmandApplication app) {
|
||||
AmenityIndexRepositoryBinary repo = null;
|
||||
for (WorldRegion reg : regions) {
|
||||
if (reg != null) {
|
||||
if (repo != null) {
|
||||
break;
|
||||
}
|
||||
repo = app.getResourceManager()
|
||||
.getAmenityRepositoryByFileName(Algorithms
|
||||
.capitalizeFirstLetterAndLowercase(reg.getRegionDownloadName()) +
|
||||
IndexConstants.BINARY_WIKI_MAP_INDEX_EXT);
|
||||
}
|
||||
}
|
||||
return repo;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
MapActivity activity = weakMapActivity.get();
|
||||
|
|
Loading…
Reference in a new issue