Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Mono2Clean - HomePresenter example
public class HomePresenter implements IHomePresenter{
private IHomeView mView;
private IPostService mService;
private IMapper<Post,PostView> mPostMapper;
private IMapper<Comment,CommentView> mCommentMapper;
public HomePresenter(IHomeView mView, IPostService mService, IMapper<Post, PostView> mPostMapper, IMapper<Comment, CommentView> mCommentMapper) {
this.mView = mView;
this.mService = mService;
this.mPostMapper = mPostMapper;
this.mCommentMapper = mCommentMapper;
}
public void loadPost(final int postId){
mService.getPostById(postId)
.subscribeOn(Schedulers.io())
.map(new Func1<Post, PostView>() {
@Override
public PostView call(Post post) {
return mPostMapper.transform(post);
}
})
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Subscriber<PostView>() {
@Override
public void onCompleted() {}
@Override
public void onError(Throwable e) {
mView.onError(e.getLocalizedMessage());
}
@Override
public void onNext(PostView postView) {
mView.onPostLoaded(postView);
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment