mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-31 06:08:31 +02:00
Download executor
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user