2016-10-17 1 views
0

レトロフィット:は、受信を使用して応答をフィルタリングして、私はそうのような受信中のコールを持って

rxHelper.manageSubscription(HavocService.getInstance().getHavocAPI().getAllTasks(userId) 
       .subscribeOn(Schedulers.io()) 
       .observeOn(AndroidSchedulers.mainThread()) 
       .compose(RxTiPresenterUtils.deliverLatestToView(this)) 
       .subscribe(response -> { 
        this.mStandardTaskResponse = response; 
        mListOfTasks = mStandardTaskResponse.getTasks(); 
        getView().setTaskList(mListOfTasks); 
        getView().setLoading(false); 
       }, throwable -> { 
        getView().setLoading(false); 
        throwable.printStackTrace(); 
       }) 
     ); 

responseは、次のタイプIは、応答者のタスクリストをフィルタリングしたい

public class StandardTaskResponse { 

    /** 
    * Whether or not there was an error with the response 
    */ 
    public boolean status; 

    /** 
    * List of Tasks 
    */ 
    @SerializedName("doc") 
    public List<Task> tasks; 

    /** 
    * Gets the array of Tasks from the response 
    * 
    * @return the List of Tasks 
    */ 
    public List<Task> getTasks() { 
     return tasks; 
    } 
} 

です。たとえば、リストには、たとえばTaskFromList.getStatus() == 2という項目を含めるだけです。

Rxでこれを行うにはどうすればよいですか?

答えて

2

これは私が

rxHelper.manageSubscription(HavocService.getInstance().getHavocAPI().getAllTasks(USER) 
       .flatMap(response -> Observable.from(response.getTasks())) 
       //filter out Tasks that are ARCHIVED or DONE 
       .filter(task -> task.getStatus() == TaskStatusEnum.INCOMPLETE) 
       .toList() 
       .subscribeOn(Schedulers.io()) 
       .observeOn(AndroidSchedulers.mainThread()) 
       .compose(RxTiPresenterUtils.deliverLatestToView(this)) 
       .subscribe(list -> { 
        mListOfTasks = list; 
        getView().setTaskList(mListOfTasks); 
        getView().setLoading(false); 
       }, throwable -> { 
        getView().setLoading(false); 
        throwable.printStackTrace(); 
       }) 
     ); 
をやってしまったものです
関連する問題