Download executor

This commit is contained in:
M66B
2022-12-28 10:32:41 +01:00
parent fe42eba34d
commit c8fe17b296
5 changed files with 38 additions and 33 deletions

View File

@@ -79,6 +79,7 @@ import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Semaphore;
class ImageHelper {
static final int DOWNLOAD_TIMEOUT = 15; // seconds
@@ -470,11 +471,10 @@ class ImageHelper {
lld.setLevel(1);
Integer kbps = ConnectionHelper.getLinkDownstreamBandwidthKbps(context);
ExecutorService executor = (kbps != null && kbps < SLOW_CONNECTION
? Helper.getSerialExecutor()
: Helper.getParallelExecutor());
boolean slow = (kbps != null && kbps < SLOW_CONNECTION);
Semaphore semaphore = new Semaphore(1);
executor.submit(new Runnable() {
Helper.getDownloadTaskExecutor().submit(new Runnable() {
@Override
public void run() {
try {
@@ -487,7 +487,16 @@ class ImageHelper {
}
// Download image
Drawable d = downloadImage(context, id, source, null);
Drawable d;
try {
if (slow)
semaphore.acquire();
d = downloadImage(context, id, source, null);
} finally {
if (slow)
semaphore.release();
}
fitDrawable(d, aw, ah, scale, view);
post(d, source);
} catch (Throwable ex) {