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;
|
package net.osmand.map;
|
||||||
|
|
||||||
|
|
||||||
import net.osmand.OsmAndCollator;
|
import net.osmand.OsmAndCollator;
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.ResultMatcher;
|
import net.osmand.ResultMatcher;
|
||||||
|
@ -705,19 +704,22 @@ public class OsmandRegions {
|
||||||
}
|
}
|
||||||
if (mapDataObjects != null) {
|
if (mapDataObjects != null) {
|
||||||
for (BinaryMapDataObject obj : mapDataObjects) {
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BinaryMapDataObject findBinaryMapDataObject(LatLon latLon) {
|
public BinaryMapDataObject findBinaryMapDataObject(LatLon latLon) throws IOException {
|
||||||
List<BinaryMapDataObject> mapDataObjects = null;
|
List<BinaryMapDataObject> mapDataObjects = getBinaryMapDataObjects(latLon);
|
||||||
try {
|
|
||||||
mapDataObjects = getBinaryMapDataObjects(latLon);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
BinaryMapDataObject res = null;
|
BinaryMapDataObject res = null;
|
||||||
double smallestArea = -1;
|
double smallestArea = -1;
|
||||||
if (mapDataObjects != null) {
|
if (mapDataObjects != null) {
|
||||||
|
@ -732,7 +734,6 @@ public class OsmandRegions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ import net.osmand.IndexConstants;
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.map.OsmandRegions;
|
import net.osmand.map.OsmandRegions;
|
||||||
|
import net.osmand.map.WorldRegion;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
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.download.IndexItem;
|
||||||
import net.osmand.plus.resources.AmenityIndexRepositoryBinary;
|
import net.osmand.plus.resources.AmenityIndexRepositoryBinary;
|
||||||
import net.osmand.plus.wikivoyage.article.WikivoyageArticleWikiLinkFragment;
|
import net.osmand.plus.wikivoyage.article.WikivoyageArticleWikiLinkFragment;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
|
@ -93,26 +95,28 @@ public class WikiArticleHelper {
|
||||||
OsmandApplication application = activity.getMyApplication();
|
OsmandApplication application = activity.getMyApplication();
|
||||||
List<Amenity> results = new ArrayList<>();
|
List<Amenity> results = new ArrayList<>();
|
||||||
if (application != null && !isCancelled()) {
|
if (application != null && !isCancelled()) {
|
||||||
IndexItem item = null;
|
List<WorldRegion> regions;
|
||||||
try {
|
if (articleLatLon != null) {
|
||||||
if (articleLatLon != null) {
|
regions = application.getRegions().getWoldRegions(articleLatLon);
|
||||||
item = DownloadResources.findSmallestIndexItemAt(application,
|
} else {
|
||||||
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) {
|
|
||||||
regionName = (getRegionName(item.getFileName(), application.getRegions()));
|
|
||||||
}
|
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
AmenityIndexRepositoryBinary repository = getAmenityRepositoryByRegion(regions, application);
|
||||||
|
if (repository == null) {
|
||||||
|
if (regionName == null || regionName.isEmpty()) {
|
||||||
|
IndexItem item = null;
|
||||||
|
try {
|
||||||
|
item = DownloadResources.findSmallestIndexItemAt(application, articleLatLon,
|
||||||
|
DownloadActivityType.WIKIPEDIA_FILE);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(TAG, e.getMessage(), e);
|
||||||
|
}
|
||||||
|
if (item != null) {
|
||||||
|
regionName = (getRegionName(item.getFileName(), application.getRegions()));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (isCancelled()) {
|
if (isCancelled()) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -124,6 +128,23 @@ public class WikiArticleHelper {
|
||||||
return results;
|
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
|
@Override
|
||||||
protected void onCancelled() {
|
protected void onCancelled() {
|
||||||
MapActivity activity = weakMapActivity.get();
|
MapActivity activity = weakMapActivity.get();
|
||||||
|
|
Loading…
Reference in a new issue