@Override
public Response load(Uri uri, int networkPolicy) throws IOException {
final AtomicReference<Object> notifier = new AtomicReference<>();
serverId = "https://" + Utils.API_SERVER_HTTP + "/download/" + serverId;
fileDownloader = new FileDownloader(serverId, outPath, true, new FileDownloader.IFileDownloaderListener() {
@Override
public void onProgress(int progress) {
}
@Override
public void onSuccess() {
synchronized (notifier) {
try {
notifier.set(new Response(decodeBitmap(outPath), false));
} catch (Exception ex) {
ex.printStackTrace();
notifier.set(new Exception());
} finally {
notifier.notify();
}
}
}
@Override
public void onError() {
synchronized (notifier) {
notifier.set(new Exception());
notifier.notify();
}
}
}, staticHandler);
fileDownloader.execute();
synchronized (notifier) {
try {
while (notifier.get() == null)
notifier.wait();
} catch (Exception ex) {
ex.printStackTrace();
}
}
if (notifier.get() instanceof Exception)
{
throw new ResponseException("File cannot be downloaded", 0, 404);
}
return (Response) notifier.get();
}