Use lambdas in CacheManager

This commit is contained in:
inorichi 2015-10-09 22:28:32 +02:00
parent 36265472f8
commit a6a05fbb7f

View File

@ -49,9 +49,7 @@ public class CacheManager {
} }
public Observable<File> cacheImagesFromUrls(final List<String> imageUrls) { public Observable<File> cacheImagesFromUrls(final List<String> imageUrls) {
return Observable.create(new Observable.OnSubscribe<File>() { return Observable.create(subscriber -> {
@Override
public void call(Subscriber<? super File> subscriber) {
try { try {
for (String imageUrl : imageUrls) { for (String imageUrl : imageUrls) {
if (!subscriber.isUnsubscribed()) { if (!subscriber.isUnsubscribed()) {
@ -62,7 +60,6 @@ public class CacheManager {
} catch (Throwable e) { } catch (Throwable e) {
subscriber.onError(e); subscriber.onError(e);
} }
}
}); });
} }
@ -75,16 +72,13 @@ public class CacheManager {
} }
public Observable<Boolean> clearImageCache() { public Observable<Boolean> clearImageCache() {
return Observable.create(new Observable.OnSubscribe<Boolean>() { return Observable.create(subscriber -> {
@Override
public void call(Subscriber<? super Boolean> subscriber) {
try { try {
subscriber.onNext(clearImageCacheImpl()); subscriber.onNext(clearImageCacheImpl());
subscriber.onCompleted(); subscriber.onCompleted();
} catch (Throwable e) { } catch (Throwable e) {
subscriber.onError(e); subscriber.onError(e);
} }
}
}); });
} }
@ -117,9 +111,7 @@ public class CacheManager {
} }
public Observable<String> getImageUrlsFromDiskCache(final String chapterUrl) { public Observable<String> getImageUrlsFromDiskCache(final String chapterUrl) {
return Observable.create(new Observable.OnSubscribe<String>() { return Observable.create(subscriber -> {
@Override
public void call(Subscriber<? super String> subscriber) {
try { try {
String[] imageUrls = getImageUrlsFromDiskCacheImpl(chapterUrl); String[] imageUrls = getImageUrlsFromDiskCacheImpl(chapterUrl);
@ -132,7 +124,6 @@ public class CacheManager {
} catch (Throwable e) { } catch (Throwable e) {
subscriber.onError(e); subscriber.onError(e);
} }
}
}); });
} }
@ -154,15 +145,12 @@ public class CacheManager {
} }
public Action0 putImageUrlsToDiskCache(final String chapterUrl, final List<String> imageUrls) { public Action0 putImageUrlsToDiskCache(final String chapterUrl, final List<String> imageUrls) {
return new Action0() { return () -> {
@Override
public void call() {
try { try {
putImageUrlsToDiskCacheImpl(chapterUrl, imageUrls); putImageUrlsToDiskCacheImpl(chapterUrl, imageUrls);
} catch (IOException e) { } catch (IOException e) {
// Do Nothing. // Do Nothing.
} }
}
}; };
} }