package vn.tale.rxmvvm_sample.model;

import java.util.List;

import rx.Observable;
import vn.tale.rxmvvm_sample.api.GitHubService;

/**
 * Created by Giang Nguyen at Tiki on 6/9/16.
 */
public class UserModel {

    private final GitHubService gitHubService;
    private int count = 0;

    public UserModel(GitHubService gitHubService) {
        this.gitHubService = gitHubService;
    }

    public Observable<List<User>> getUsers() {
        count++;
        if (count % 3 == 0) {
            return Observable.just(null);
        } else if (count % 3 == 1) {
            return Observable.error(new RuntimeException("Error"));
        }
        return gitHubService.getUsers();
    }
}

@@ -77,16 +77,43 @@
 rvable;%0A
+import rx.functions.Func0;%0A
 import v
@@ -232,19 +232,16 @@
 Model %7B%0A
-%0A  
   privat
@@ -277,18 +277,16 @@
 ervice;%0A
-  
   privat
@@ -303,16 +303,15 @@
 t = 
-0
+-1
 ;%0A%0A  
- 
- 
 publ
@@ -350,28 +350,24 @@
 bService) %7B%0A
-    
     this.git
@@ -398,17 +398,13 @@
 ce;%0A
-  
   %7D%0A%0A
-  
   pu
@@ -440,24 +440,145 @@
 etUsers() %7B%0A
+    return Observable.defer(new Func0%3CObservable%3CList%3CUser%3E%3E%3E() %7B%0A      @Override public Observable%3CList%3CUser%3E%3E call() %7B%0A
         coun
@@ -608,26 +608,24 @@
 %25 3 == 0) %7B%0A
-  
           re
@@ -685,26 +685,24 @@
 %25 3 == 1) %7B%0A
-  
           re
@@ -808,14 +808,28 @@
 rs();%0A  
+    %7D%0A    %7D);%0A
   %7D%0A%7D%0A

implement to flexible return