From 2c56dd4ca403f95fa92f590d23e4f449dfc015a6 Mon Sep 17 00:00:00 2001 From: Gavriil Sitnikov Date: Tue, 24 May 2016 15:29:05 +0300 Subject: [PATCH] static fixes --- .../observables/collections/ObservableList.java | 2 ++ .../collections/loadable/LoadingGrowingList.java | 13 +++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/touchin/roboswag/core/observables/collections/ObservableList.java b/src/main/java/ru/touchin/roboswag/core/observables/collections/ObservableList.java index ee63531..0d968d0 100644 --- a/src/main/java/ru/touchin/roboswag/core/observables/collections/ObservableList.java +++ b/src/main/java/ru/touchin/roboswag/core/observables/collections/ObservableList.java @@ -37,10 +37,12 @@ public class ObservableList extends ObservableCollection { private final List items; public ObservableList() { + super(); items = new ArrayList<>(); } public ObservableList(@NonNull final Collection initialItems) { + super(); items = new ArrayList<>(initialItems); } diff --git a/src/main/java/ru/touchin/roboswag/core/observables/collections/loadable/LoadingGrowingList.java b/src/main/java/ru/touchin/roboswag/core/observables/collections/loadable/LoadingGrowingList.java index 591d910..1efb353 100644 --- a/src/main/java/ru/touchin/roboswag/core/observables/collections/loadable/LoadingGrowingList.java +++ b/src/main/java/ru/touchin/roboswag/core/observables/collections/loadable/LoadingGrowingList.java @@ -52,6 +52,7 @@ public class LoadingGrowingList> private final ObservableList innerList = new ObservableList<>(); public LoadingGrowingList(@NonNull final LoadingRequestCreator loadingMoreRequestCreator) { + super(); this.loadingMoreRequestCreator = loadingMoreRequestCreator; innerList.observeChanges().subscribe(change -> { //do not change - bug of RetroLambda @@ -64,6 +65,11 @@ public class LoadingGrowingList> return innerList; } + @NonNull + public Observable observeHaveMoreItems() { + return haveMoreItems.distinctUntilChanged(); + } + @NonNull private Observable getLoadMoreObservable() { return Observable @@ -75,12 +81,11 @@ public class LoadingGrowingList> .subscribeOn(Schedulers.io()) .observeOn(scheduler) .single() - .onErrorResumeNext(throwable -> { + .doOnError(throwable -> { if ((throwable instanceof IllegalArgumentException) || (throwable instanceof NoSuchElementException)) { Lc.assertion("Updates during loading not supported. LoadingRequestCreator should emit only one result."); } - return Observable.error(throwable); }) .doOnNext(loadedItems -> { loadingMoreConcreteObservable = null; @@ -123,8 +128,8 @@ public class LoadingGrowingList> subscriber.onCompleted(); }) .subscribeOn(scheduler)) - .retryWhen(attempts -> - attempts.map(throwable -> throwable instanceof DoRetryException ? Observable.just(null) : Observable.error(throwable))); + .retryWhen(attempts -> attempts + .switchMap(throwable -> throwable instanceof DoRetryException ? Observable.just(null) : Observable.error(throwable))); } private static class DoRetryException extends Exception {