Search in sources :

Example 1 with NotificationHelper

use of com.simplecity.amp_library.notifications.NotificationHelper 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)));
}
Also used : R(com.simplecity.amp_library.R) TimeoutException(java.util.concurrent.TimeoutException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) NotificationHelper(com.simplecity.amp_library.notifications.NotificationHelper) Single(io.reactivex.Single) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) IBinder(android.os.IBinder) FutureTarget(com.bumptech.glide.request.FutureTarget) Toast(android.widget.Toast) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) ShuttleUtils(com.simplecity.amp_library.utils.ShuttleUtils) Log(android.util.Log) ArtworkModelLoader(com.simplecity.amp_library.glide.loader.ArtworkModelLoader) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) LogUtils(com.simplecity.amp_library.utils.LogUtils) ComponentName(android.content.ComponentName) Service(android.app.Service) ArtworkProvider(com.simplecity.amp_library.model.ArtworkProvider) File(java.io.File) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Glide(com.bumptech.glide.Glide) NotificationCompat(android.support.v4.app.NotificationCompat) DataManager(com.simplecity.amp_library.utils.DataManager) Nullable(android.support.annotation.Nullable) Collections(java.util.Collections) InputStream(java.io.InputStream) ArtworkModelLoader(com.simplecity.amp_library.glide.loader.ArtworkModelLoader) FutureTarget(com.bumptech.glide.request.FutureTarget) Toast(android.widget.Toast) NotificationHelper(com.simplecity.amp_library.notifications.NotificationHelper) ArtworkProvider(com.simplecity.amp_library.model.ArtworkProvider) List(java.util.List) Observable(io.reactivex.Observable)

Aggregations

PendingIntent (android.app.PendingIntent)1 Service (android.app.Service)1 ComponentName (android.content.ComponentName)1 Intent (android.content.Intent)1 IBinder (android.os.IBinder)1 Nullable (android.support.annotation.Nullable)1 NotificationCompat (android.support.v4.app.NotificationCompat)1 Log (android.util.Log)1 Toast (android.widget.Toast)1 Glide (com.bumptech.glide.Glide)1 FutureTarget (com.bumptech.glide.request.FutureTarget)1 SimpleTarget (com.bumptech.glide.request.target.SimpleTarget)1 R (com.simplecity.amp_library.R)1 ArtworkModelLoader (com.simplecity.amp_library.glide.loader.ArtworkModelLoader)1 ArtworkProvider (com.simplecity.amp_library.model.ArtworkProvider)1 NotificationHelper (com.simplecity.amp_library.notifications.NotificationHelper)1 DataManager (com.simplecity.amp_library.utils.DataManager)1 LogUtils (com.simplecity.amp_library.utils.LogUtils)1 ShuttleUtils (com.simplecity.amp_library.utils.ShuttleUtils)1 Observable (io.reactivex.Observable)1