use of com.simplecity.amp_library.glide.loader.ArtworkModelLoader in project Shuttle by timusus.
the class ArtworkDownloadService method onCreate.
@Override
public void onCreate() {
super.onCreate();
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
final ComponentName serviceName = new ComponentName(this, ArtworkDownloadService.class);
Intent intent = new Intent(ACTION_CANCEL);
intent.setComponent(serviceName);
PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, 0);
notificationBuilder = new NotificationCompat.Builder(this).setContentTitle(getResources().getString(R.string.notif_downloading_art)).setSmallIcon(android.R.drawable.stat_sys_download).setOngoing(true).setProgress(100, 0, true).addAction(new NotificationCompat.Action(R.drawable.ic_action_navigation_close, getString(R.string.cancel), pendingIntent));
if (!ShuttleUtils.isOnline(false)) {
Toast toast = Toast.makeText(this, getResources().getString(R.string.connection_unavailable), Toast.LENGTH_SHORT);
toast.show();
stopSelf();
return;
}
if (notificationBuilder != null) {
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}
subscription = new CompositeSubscription();
Observable<List<ArtworkProvider>> sharedItemsObservable = DataManager.getInstance().getAlbumArtistsRelay().first().<ArtworkProvider>flatMap(Observable::from).mergeWith(DataManager.getInstance().getAlbumsRelay().first().flatMap(Observable::from)).toList().share();
subscription.add(sharedItemsObservable.observeOn(AndroidSchedulers.mainThread()).subscribe(list -> {
max = list.size();
updateProgress();
}));
subscription.add(sharedItemsObservable.flatMap(Observable::from).flatMap(artworkProvider -> Observable.just(artworkProvider).subscribeOn(Schedulers.computation()).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 null;
})).observeOn(AndroidSchedulers.mainThread()).subscribe(item -> {
updateProgress();
}));
}
Aggregations