Fixed scrolling through an online map ends up "downloading forever"
issue
This commit is contained in:
parent
ce86f05b68
commit
d1df74c273
4 changed files with 17 additions and 2 deletions
|
@ -40,6 +40,7 @@ public class MapTileDownloader {
|
||||||
private ThreadPoolExecutor threadPoolExecutor;
|
private ThreadPoolExecutor threadPoolExecutor;
|
||||||
private List<IMapDownloaderCallback> callbacks = new ArrayList<IMapDownloaderCallback>();
|
private List<IMapDownloaderCallback> callbacks = new ArrayList<IMapDownloaderCallback>();
|
||||||
|
|
||||||
|
private Set<File> pendingToDownload;
|
||||||
private Set<File> currentlyDownloaded;
|
private Set<File> currentlyDownloaded;
|
||||||
|
|
||||||
private int currentErrors = 0;
|
private int currentErrors = 0;
|
||||||
|
@ -109,6 +110,7 @@ public class MapTileDownloader {
|
||||||
TimeUnit.SECONDS, new LIFOBlockingDeque<Runnable>());
|
TimeUnit.SECONDS, new LIFOBlockingDeque<Runnable>());
|
||||||
// 1.6 method but very useful to kill non-running threads
|
// 1.6 method but very useful to kill non-running threads
|
||||||
// threadPoolExecutor.allowCoreThreadTimeOut(true);
|
// threadPoolExecutor.allowCoreThreadTimeOut(true);
|
||||||
|
pendingToDownload = Collections.synchronizedSet(new HashSet<File>());
|
||||||
currentlyDownloaded = Collections.synchronizedSet(new HashSet<File>());
|
currentlyDownloaded = Collections.synchronizedSet(new HashSet<File>());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -125,6 +127,10 @@ public class MapTileDownloader {
|
||||||
return callbacks;
|
return callbacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isFilePendingToDownload(File f){
|
||||||
|
return pendingToDownload.contains(f);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isFileCurrentlyDownloaded(File f){
|
public boolean isFileCurrentlyDownloaded(File f){
|
||||||
return currentlyDownloaded.contains(f);
|
return currentlyDownloaded.contains(f);
|
||||||
}
|
}
|
||||||
|
@ -157,7 +163,9 @@ public class MapTileDownloader {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isFileCurrentlyDownloaded(request.fileToSave)) {
|
if (!isFileCurrentlyDownloaded(request.fileToSave)
|
||||||
|
&& !isFilePendingToDownload(request.fileToSave)) {
|
||||||
|
pendingToDownload.add(request.fileToSave);
|
||||||
threadPoolExecutor.execute(new DownloadMapWorker(request));
|
threadPoolExecutor.execute(new DownloadMapWorker(request));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -179,6 +187,7 @@ public class MapTileDownloader {
|
||||||
}
|
}
|
||||||
|
|
||||||
currentlyDownloaded.add(request.fileToSave);
|
currentlyDownloaded.add(request.fileToSave);
|
||||||
|
pendingToDownload.remove(request.fileToSave);
|
||||||
if(log.isDebugEnabled()){
|
if(log.isDebugEnabled()){
|
||||||
log.debug("Start downloading tile : " + request.url); //$NON-NLS-1$
|
log.debug("Start downloading tile : " + request.url); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
<name>OsmAnd</name>
|
<name>OsmAnd</name>
|
||||||
<comment></comment>
|
<comment></comment>
|
||||||
<projects>
|
<projects>
|
||||||
|
<project>SherlockBar</project>
|
||||||
</projects>
|
</projects>
|
||||||
<buildSpec>
|
<buildSpec>
|
||||||
<buildCommand>
|
<buildCommand>
|
||||||
|
|
|
@ -141,6 +141,10 @@ public class AsyncLoadingThread extends Thread {
|
||||||
requests.push(req);
|
requests.push(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isFilePendingToDownload(File fileToSave) {
|
||||||
|
return resourceManger.getMapTileDownloader().isFilePendingToDownload(fileToSave);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isFileCurrentlyDownloaded(File fileToSave) {
|
public boolean isFileCurrentlyDownloaded(File fileToSave) {
|
||||||
return resourceManger.getMapTileDownloader().isFileCurrentlyDownloaded(fileToSave);
|
return resourceManger.getMapTileDownloader().isFileCurrentlyDownloaded(fileToSave);
|
||||||
}
|
}
|
||||||
|
|
|
@ -351,7 +351,8 @@ public class ResourceManager {
|
||||||
if (cacheOfImages.size() > maxImgCacheSize) {
|
if (cacheOfImages.size() > maxImgCacheSize) {
|
||||||
clearTiles();
|
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();
|
long time = System.currentTimeMillis();
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Start loaded file : " + req.tileId + " " + Thread.currentThread().getName()); //$NON-NLS-1$ //$NON-NLS-2$
|
log.debug("Start loaded file : " + req.tileId + " " + Thread.currentThread().getName()); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
Loading…
Reference in a new issue