From a6a05fbb7f6d1c228a34dc032268466f85194675 Mon Sep 17 00:00:00 2001 From: inorichi Date: Fri, 9 Oct 2015 22:28:32 +0200 Subject: [PATCH] Use lambdas in CacheManager --- .../mangafeed/data/caches/CacheManager.java | 68 ++++++++----------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/eu/kanade/mangafeed/data/caches/CacheManager.java b/app/src/main/java/eu/kanade/mangafeed/data/caches/CacheManager.java index ef28865ec8..49ddde865f 100644 --- a/app/src/main/java/eu/kanade/mangafeed/data/caches/CacheManager.java +++ b/app/src/main/java/eu/kanade/mangafeed/data/caches/CacheManager.java @@ -49,19 +49,16 @@ public class CacheManager { } public Observable cacheImagesFromUrls(final List imageUrls) { - return Observable.create(new Observable.OnSubscribe() { - @Override - public void call(Subscriber subscriber) { - try { - for (String imageUrl : imageUrls) { - if (!subscriber.isUnsubscribed()) { - subscriber.onNext(cacheImageFromUrl(imageUrl)); - } + return Observable.create(subscriber -> { + try { + for (String imageUrl : imageUrls) { + if (!subscriber.isUnsubscribed()) { + subscriber.onNext(cacheImageFromUrl(imageUrl)); } - subscriber.onCompleted(); - } catch (Throwable e) { - subscriber.onError(e); } + subscriber.onCompleted(); + } catch (Throwable e) { + subscriber.onError(e); } }); } @@ -75,15 +72,12 @@ public class CacheManager { } public Observable clearImageCache() { - return Observable.create(new Observable.OnSubscribe() { - @Override - public void call(Subscriber subscriber) { - try { - subscriber.onNext(clearImageCacheImpl()); - subscriber.onCompleted(); - } catch (Throwable e) { - subscriber.onError(e); - } + return Observable.create(subscriber -> { + try { + subscriber.onNext(clearImageCacheImpl()); + subscriber.onCompleted(); + } catch (Throwable e) { + subscriber.onError(e); } }); } @@ -117,21 +111,18 @@ public class CacheManager { } public Observable getImageUrlsFromDiskCache(final String chapterUrl) { - return Observable.create(new Observable.OnSubscribe() { - @Override - public void call(Subscriber subscriber) { - try { - String[] imageUrls = getImageUrlsFromDiskCacheImpl(chapterUrl); + return Observable.create(subscriber -> { + try { + String[] imageUrls = getImageUrlsFromDiskCacheImpl(chapterUrl); - for (String imageUrl : imageUrls) { - if (!subscriber.isUnsubscribed()) { - subscriber.onNext(imageUrl); - } + for (String imageUrl : imageUrls) { + if (!subscriber.isUnsubscribed()) { + subscriber.onNext(imageUrl); } - subscriber.onCompleted(); - } catch (Throwable e) { - subscriber.onError(e); } + subscriber.onCompleted(); + } catch (Throwable e) { + subscriber.onError(e); } }); } @@ -154,14 +145,11 @@ public class CacheManager { } public Action0 putImageUrlsToDiskCache(final String chapterUrl, final List imageUrls) { - return new Action0() { - @Override - public void call() { - try { - putImageUrlsToDiskCacheImpl(chapterUrl, imageUrls); - } catch (IOException e) { - // Do Nothing. - } + return () -> { + try { + putImageUrlsToDiskCacheImpl(chapterUrl, imageUrls); + } catch (IOException e) { + // Do Nothing. } }; }