Removed unnecessary null checks and improved error handling
This commit is contained in:
parent
949a44d061
commit
8b92f39039
3 changed files with 60 additions and 55 deletions
|
@ -694,25 +694,16 @@ public class OsmandRegions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<WorldRegion> getWoldRegions(LatLon latLon) {
|
public List<WorldRegion> getWoldRegions(LatLon latLon) throws IOException {
|
||||||
List<WorldRegion> result = new ArrayList<>();
|
List<WorldRegion> result = new ArrayList<>();
|
||||||
List<BinaryMapDataObject> mapDataObjects = null;
|
List<BinaryMapDataObject> mapDataObjects = getBinaryMapDataObjects(latLon);
|
||||||
try {
|
for (BinaryMapDataObject obj : mapDataObjects) {
|
||||||
mapDataObjects = getBinaryMapDataObjects(latLon);
|
String fullName = getFullName(obj);
|
||||||
} catch (IOException e) {
|
if (fullName != null) {
|
||||||
e.printStackTrace();
|
WorldRegion reg = getRegionData(fullName);
|
||||||
}
|
if (reg != null) {
|
||||||
if (mapDataObjects != null) {
|
result.add(reg);
|
||||||
for (BinaryMapDataObject obj : mapDataObjects) {
|
|
||||||
if (obj != null) {
|
|
||||||
String fullName = getFullName(obj);
|
|
||||||
WorldRegion reg = getRegionData(fullName);
|
|
||||||
if (reg != null) {
|
|
||||||
result.add(reg);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
@ -722,16 +713,14 @@ public class OsmandRegions {
|
||||||
List<BinaryMapDataObject> mapDataObjects = getBinaryMapDataObjects(latLon);
|
List<BinaryMapDataObject> mapDataObjects = getBinaryMapDataObjects(latLon);
|
||||||
BinaryMapDataObject res = null;
|
BinaryMapDataObject res = null;
|
||||||
double smallestArea = -1;
|
double smallestArea = -1;
|
||||||
if (mapDataObjects != null) {
|
for (BinaryMapDataObject o : mapDataObjects) {
|
||||||
for (BinaryMapDataObject o : mapDataObjects) {
|
double area = OsmandRegions.getArea(o);
|
||||||
double area = OsmandRegions.getArea(o);
|
if (smallestArea == -1) {
|
||||||
if (smallestArea == -1) {
|
smallestArea = area;
|
||||||
smallestArea = area;
|
res = o;
|
||||||
res = o;
|
} else if (area < smallestArea) {
|
||||||
} else if (area < smallestArea) {
|
smallestArea = area;
|
||||||
smallestArea = area;
|
res = o;
|
||||||
res = o;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -30,6 +30,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class DownloadResources extends DownloadResourceGroup {
|
public class DownloadResources extends DownloadResourceGroup {
|
||||||
|
private static final String TAG = DownloadResources.class.getSimpleName();
|
||||||
|
|
||||||
public boolean isDownloadedFromInternet = false;
|
public boolean isDownloadedFromInternet = false;
|
||||||
public boolean downloadFromInternetFailed = false;
|
public boolean downloadFromInternetFailed = false;
|
||||||
public boolean mapVersionIsIncreased = false;
|
public boolean mapVersionIsIncreased = false;
|
||||||
|
@ -463,11 +465,18 @@ public class DownloadResources extends DownloadResourceGroup {
|
||||||
List<IndexItem> res = new ArrayList<>();
|
List<IndexItem> res = new ArrayList<>();
|
||||||
OsmandRegions regions = app.getRegions();
|
OsmandRegions regions = app.getRegions();
|
||||||
DownloadIndexesThread downloadThread = app.getDownloadThread();
|
DownloadIndexesThread downloadThread = app.getDownloadThread();
|
||||||
List<WorldRegion> downloadRegions = regions.getWoldRegions(latLon);
|
List<WorldRegion> downloadRegions = null;
|
||||||
for (WorldRegion downloadRegion : downloadRegions) {
|
try {
|
||||||
if (downloadRegion != null) {
|
downloadRegions = regions.getWoldRegions(latLon);
|
||||||
if (includeDownloaded || !isIndexItemDownloaded(downloadThread, type, downloadRegion, res)) {
|
} catch (IOException e) {
|
||||||
addIndexItem(downloadThread, type, downloadRegion, res);
|
android.util.Log.e(TAG, e.getMessage(), e);
|
||||||
|
}
|
||||||
|
if (downloadRegions != null) {
|
||||||
|
for (WorldRegion downloadRegion : downloadRegions) {
|
||||||
|
if (downloadRegion != null) {
|
||||||
|
if (includeDownloaded || !isIndexItemDownloaded(downloadThread, type, downloadRegion, res)) {
|
||||||
|
addIndexItem(downloadThread, type, downloadRegion, res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,7 @@ import android.text.Html;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
|
import net.osmand.ResultMatcher;
|
||||||
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;
|
||||||
|
@ -93,43 +94,49 @@ public class WikiArticleHelper {
|
||||||
protected List<Amenity> doInBackground(Void... voids) {
|
protected List<Amenity> doInBackground(Void... voids) {
|
||||||
MapActivity activity = weakMapActivity.get();
|
MapActivity activity = weakMapActivity.get();
|
||||||
OsmandApplication application = activity.getMyApplication();
|
OsmandApplication application = activity.getMyApplication();
|
||||||
List<Amenity> results = new ArrayList<>();
|
final List<Amenity> results = new ArrayList<>();
|
||||||
if (application != null && !isCancelled()) {
|
if (application != null && !isCancelled()) {
|
||||||
List<WorldRegion> regions;
|
List<WorldRegion> regions = null;
|
||||||
if (articleLatLon != null) {
|
if (articleLatLon != null) {
|
||||||
regions = application.getRegions().getWoldRegions(articleLatLon);
|
try {
|
||||||
|
regions = application.getRegions().getWoldRegions(articleLatLon);
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e(TAG, e.getMessage(), e);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
AmenityIndexRepositoryBinary repository = getAmenityRepositoryByRegion(regions, application);
|
if (regions != null) {
|
||||||
if (repository == null) {
|
AmenityIndexRepositoryBinary repository = getWikiRepositoryByRegions(regions, application);
|
||||||
if (regionName == null || regionName.isEmpty()) {
|
if (repository == null) {
|
||||||
IndexItem item = null;
|
if (regionName == null || regionName.isEmpty()) {
|
||||||
try {
|
IndexItem item = null;
|
||||||
item = DownloadResources.findSmallestIndexItemAt(application, articleLatLon,
|
try {
|
||||||
DownloadActivityType.WIKIPEDIA_FILE);
|
item = DownloadResources.findSmallestIndexItemAt(application, articleLatLon,
|
||||||
} catch (IOException e) {
|
DownloadActivityType.WIKIPEDIA_FILE);
|
||||||
Log.e(TAG, e.getMessage(), e);
|
} catch (IOException e) {
|
||||||
|
Log.e(TAG, e.getMessage(), e);
|
||||||
|
}
|
||||||
|
if (item != null) {
|
||||||
|
regionName = (getRegionName(item.getFileName(), application.getRegions()));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
if (item != null) {
|
|
||||||
regionName = (getRegionName(item.getFileName(), application.getRegions()));
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (isCancelled()) {
|
if (isCancelled()) {
|
||||||
return null;
|
return null;
|
||||||
|
}
|
||||||
|
results.addAll(repository.searchAmenitiesByName(0, 0, 0, 0,
|
||||||
|
Integer.MAX_VALUE, Integer.MAX_VALUE, name, null));
|
||||||
}
|
}
|
||||||
results.addAll(repository.searchAmenitiesByName(0, 0, 0, 0,
|
|
||||||
Integer.MAX_VALUE, Integer.MAX_VALUE, name, null));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private AmenityIndexRepositoryBinary getAmenityRepositoryByRegion(@NonNull List<WorldRegion> regions, @NonNull OsmandApplication app) {
|
private AmenityIndexRepositoryBinary getWikiRepositoryByRegions(@NonNull List<WorldRegion> regions, @NonNull OsmandApplication app) {
|
||||||
AmenityIndexRepositoryBinary repo = null;
|
AmenityIndexRepositoryBinary repo = null;
|
||||||
for (WorldRegion reg : regions) {
|
for (WorldRegion reg : regions) {
|
||||||
if (reg != null) {
|
if (reg != null) {
|
||||||
|
|
Loading…
Reference in a new issue