Use lambdas in CacheManager
This commit is contained in:
parent
36265472f8
commit
a6a05fbb7f
1 changed files with 28 additions and 40 deletions
|
@ -49,19 +49,16 @@ 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
|
try {
|
||||||
public void call(Subscriber<? super File> subscriber) {
|
for (String imageUrl : imageUrls) {
|
||||||
try {
|
if (!subscriber.isUnsubscribed()) {
|
||||||
for (String imageUrl : imageUrls) {
|
subscriber.onNext(cacheImageFromUrl(imageUrl));
|
||||||
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<Boolean> clearImageCache() {
|
public Observable<Boolean> clearImageCache() {
|
||||||
return Observable.create(new Observable.OnSubscribe<Boolean>() {
|
return Observable.create(subscriber -> {
|
||||||
@Override
|
try {
|
||||||
public void call(Subscriber<? super Boolean> subscriber) {
|
subscriber.onNext(clearImageCacheImpl());
|
||||||
try {
|
subscriber.onCompleted();
|
||||||
subscriber.onNext(clearImageCacheImpl());
|
} catch (Throwable e) {
|
||||||
subscriber.onCompleted();
|
subscriber.onError(e);
|
||||||
} catch (Throwable e) {
|
|
||||||
subscriber.onError(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -117,21 +111,18 @@ 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
|
try {
|
||||||
public void call(Subscriber<? super String> subscriber) {
|
String[] imageUrls = getImageUrlsFromDiskCacheImpl(chapterUrl);
|
||||||
try {
|
|
||||||
String[] imageUrls = getImageUrlsFromDiskCacheImpl(chapterUrl);
|
|
||||||
|
|
||||||
for (String imageUrl : imageUrls) {
|
for (String imageUrl : imageUrls) {
|
||||||
if (!subscriber.isUnsubscribed()) {
|
if (!subscriber.isUnsubscribed()) {
|
||||||
subscriber.onNext(imageUrl);
|
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<String> imageUrls) {
|
public Action0 putImageUrlsToDiskCache(final String chapterUrl, final List<String> imageUrls) {
|
||||||
return new Action0() {
|
return () -> {
|
||||||
@Override
|
try {
|
||||||
public void call() {
|
putImageUrlsToDiskCacheImpl(chapterUrl, imageUrls);
|
||||||
try {
|
} catch (IOException e) {
|
||||||
putImageUrlsToDiskCacheImpl(chapterUrl, imageUrls);
|
// Do Nothing.
|
||||||
} catch (IOException e) {
|
|
||||||
// Do Nothing.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue