From 4acb04c4eb72525cbabf1f3925c5fd4e663baccf Mon Sep 17 00:00:00 2001 From: esensar Date: Tue, 4 Oct 2016 01:38:29 +0200 Subject: [PATCH] Add filter for failed get users requests --- .../reactivegithubsample/views/MainActivity.java | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/ensarsarajcic/reactivegithubsample/views/MainActivity.java b/app/src/main/java/com/ensarsarajcic/reactivegithubsample/views/MainActivity.java index ff2575a..15ba953 100644 --- a/app/src/main/java/com/ensarsarajcic/reactivegithubsample/views/MainActivity.java +++ b/app/src/main/java/com/ensarsarajcic/reactivegithubsample/views/MainActivity.java @@ -107,10 +107,16 @@ public class MainActivity extends AppCompatActivity { return RestClient.getGitHubApi().getUsers(new Random().nextInt(1000)).execute().body(); } catch (IOException ioException) { ioException.printStackTrace(); - return new ArrayList(); + return null; } } }) + .filter(new Func1, Boolean>() { + @Override + public Boolean call(List gitHubUsers) { + return gitHubUsers != null; + } + }) .subscribeOn(Schedulers.io()). observeOn(AndroidSchedulers.mainThread()); @@ -121,12 +127,10 @@ public class MainActivity extends AppCompatActivity { public void onCompleted() { } - @Override public void onError(Throwable e) { e.printStackTrace(); } - @Override public void onNext(List gitHubUsers) { adapter.setItems(gitHubUsers);