diff --git a/OsmAnd-java/src/net/osmand/map/MapTileDownloader.java b/OsmAnd-java/src/net/osmand/map/MapTileDownloader.java index 07bcd3715d..fa8c3a334d 100644 --- a/OsmAnd-java/src/net/osmand/map/MapTileDownloader.java +++ b/OsmAnd-java/src/net/osmand/map/MapTileDownloader.java @@ -40,6 +40,7 @@ public class MapTileDownloader { private ThreadPoolExecutor threadPoolExecutor; private List callbacks = new ArrayList(); + private Set pendingToDownload; private Set currentlyDownloaded; private int currentErrors = 0; @@ -109,6 +110,7 @@ public class MapTileDownloader { TimeUnit.SECONDS, new LIFOBlockingDeque()); // 1.6 method but very useful to kill non-running threads // threadPoolExecutor.allowCoreThreadTimeOut(true); + pendingToDownload = Collections.synchronizedSet(new HashSet()); currentlyDownloaded = Collections.synchronizedSet(new HashSet()); } @@ -125,6 +127,10 @@ public class MapTileDownloader { return callbacks; } + public boolean isFilePendingToDownload(File f){ + return pendingToDownload.contains(f); + } + public boolean isFileCurrentlyDownloaded(File f){ return currentlyDownloaded.contains(f); } @@ -157,7 +163,9 @@ public class MapTileDownloader { return; } - if (!isFileCurrentlyDownloaded(request.fileToSave)) { + if (!isFileCurrentlyDownloaded(request.fileToSave) + && !isFilePendingToDownload(request.fileToSave)) { + pendingToDownload.add(request.fileToSave); threadPoolExecutor.execute(new DownloadMapWorker(request)); } } @@ -179,6 +187,7 @@ public class MapTileDownloader { } currentlyDownloaded.add(request.fileToSave); + pendingToDownload.remove(request.fileToSave); if(log.isDebugEnabled()){ log.debug("Start downloading tile : " + request.url); //$NON-NLS-1$ } diff --git a/OsmAnd/.project b/OsmAnd/.project index 3ac8329491..81f09b6a09 100644 --- a/OsmAnd/.project +++ b/OsmAnd/.project @@ -3,6 +3,7 @@ OsmAnd + SherlockBar diff --git a/OsmAnd/src/net/osmand/plus/resources/AsyncLoadingThread.java b/OsmAnd/src/net/osmand/plus/resources/AsyncLoadingThread.java index a9a3320dda..411e302bc0 100644 --- a/OsmAnd/src/net/osmand/plus/resources/AsyncLoadingThread.java +++ b/OsmAnd/src/net/osmand/plus/resources/AsyncLoadingThread.java @@ -141,6 +141,10 @@ public class AsyncLoadingThread extends Thread { requests.push(req); } + public boolean isFilePendingToDownload(File fileToSave) { + return resourceManger.getMapTileDownloader().isFilePendingToDownload(fileToSave); + } + public boolean isFileCurrentlyDownloaded(File fileToSave) { return resourceManger.getMapTileDownloader().isFileCurrentlyDownloaded(fileToSave); } diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index f751d70d9f..87123c6daa 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -351,7 +351,8 @@ public class ResourceManager { if (cacheOfImages.size() > maxImgCacheSize) { clearTiles(); } - if (req.dirWithTiles.canRead() && !asyncLoadingThread.isFileCurrentlyDownloaded(req.fileToSave)) { + if (req.dirWithTiles.canRead() && !asyncLoadingThread.isFileCurrentlyDownloaded(req.fileToSave) + && !asyncLoadingThread.isFilePendingToDownload(req.fileToSave)) { long time = System.currentTimeMillis(); if (log.isDebugEnabled()) { log.debug("Start loaded file : " + req.tileId + " " + Thread.currentThread().getName()); //$NON-NLS-1$ //$NON-NLS-2$