use of com.bumptech.glide.request.FutureTarget in project Shuttle by timusus.
the class ArtworkDownloadService method onCreate.
@Override
public void onCreate() {
super.onCreate();
notificationHelper = new NotificationHelper(this);
if (!ShuttleUtils.isOnline(false)) {
Toast toast = Toast.makeText(this, getResources().getString(R.string.connection_unavailable), Toast.LENGTH_SHORT);
toast.show();
stopSelf();
return;
}
notificationHelper.notify(NOTIFICATION_ID, getNotificationBuilder().build());
Single<List<ArtworkProvider>> sharedItemsSingle = DataManager.getInstance().getAlbumArtistsRelay().first(Collections.emptyList()).<ArtworkProvider>flatMapObservable(Observable::fromIterable).mergeWith(DataManager.getInstance().getAlbumsRelay().first(Collections.emptyList()).flatMapObservable(Observable::fromIterable)).toList();
disposables.add(sharedItemsSingle.observeOn(AndroidSchedulers.mainThread()).subscribe(list -> {
max = list.size();
updateProgress();
}, error -> LogUtils.logException(TAG, "Error determining max", error)));
disposables.add(sharedItemsSingle.flatMapObservable(Observable::fromIterable).flatMap(artworkProvider -> Observable.just(artworkProvider).map(artwork -> {
FutureTarget<File> futureTarget = Glide.with(ArtworkDownloadService.this).using(new ArtworkModelLoader(true), InputStream.class).load(artwork).as(InputStream.class).downloadOnly(SimpleTarget.SIZE_ORIGINAL, SimpleTarget.SIZE_ORIGINAL);
try {
futureTarget.get(30, TimeUnit.SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
Log.e(TAG, "Error downloading artworkProvider: " + e);
}
Glide.clear(futureTarget);
return artwork;
})).subscribeOn(Schedulers.computation()).observeOn(AndroidSchedulers.mainThread()).subscribe(item -> updateProgress(), error -> LogUtils.logException(TAG, "Error downloading artwork", error)));
}
Aggregations