Search code examples
androidrx-javarx-java2rx-android

How to listen change and then perform the action in RxAndroid?


 public Flowable<ViewModel> perform(
            Flowable<PaginationParam> paginationSource) {
        return Flowable.combineLatest(
                        mConnectionState.getConnectionState(),
                        mSessionInfo,
                        paginationSource,
                        Holder::combine)
                .flatMap(this::toViewModel); 
}

Now I want to start perform() when I am on the second page so my point is listen Pagination change and when it is not the first page(0) then call call perform().

final Flowable<PaginationParam > paginationSource =
                mPagination.observe(this).filter(it -> it.getOffset() != 0);

I don't know how can I combine these.?


Solution

  • you can change you perform function:

    public Flowable<ViewModel> perform(PaginationParam paginationParam) {
        return Flowable.combineLatest(
                        mConnectionState.getConnectionState(),
                        mSessionInfo,
                        {state, info -> Holder.combine(state, info, paginationParam)})
                .flatMap(this::toViewModel); 
    

    }

    and than use it:

    paginationSource.flatMap( it -> perform(it))
                .subscribe(...)