Fixed scrolling through an online map ends up "downloading forever"

issue
This commit is contained in:
Taranenko Roman 2014-10-08 22:50:49 +03:00
parent ce86f05b68
commit d1df74c273
4 changed files with 17 additions and 2 deletions

View file

@ -40,6 +40,7 @@ public class MapTileDownloader {
private ThreadPoolExecutor threadPoolExecutor;
private List<IMapDownloaderCallback> callbacks = new ArrayList<IMapDownloaderCallback>();
private Set<File> pendingToDownload;
private Set<File> currentlyDownloaded;
private int currentErrors = 0;
@ -109,6 +110,7 @@ public class MapTileDownloader {
TimeUnit.SECONDS, new LIFOBlockingDeque<Runnable>());
// 1.6 method but very useful to kill non-running threads
// threadPoolExecutor.allowCoreThreadTimeOut(true);
pendingToDownload = Collections.synchronizedSet(new HashSet<File>());
currentlyDownloaded = Collections.synchronizedSet(new HashSet<File>());
}
@ -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$
}

View file

@ -3,6 +3,7 @@
<name>OsmAnd</name>
<comment></comment>
<projects>
<project>SherlockBar</project>
</projects>
<buildSpec>
<buildCommand>

View file

@ -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);
}

View file

@ -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$