Search in sources :

Example 1 with OnUserInfoListener

use of com.example.jingbin.cloudreader.data.OnUserInfoListener in project CloudReader by youlookwhat.

the class MainViewModel method getUserInfo.

public void getUserInfo() {
    UserUtil.getUserInfo(new OnUserInfoListener() {

        @Override
        public void onSuccess(User user) {
            if (user != null) {
                execute(HttpClient.Builder.getWanAndroidServer().getCoinUserInfo(), new Observer<BaseResultBean<CoinUserInfoBean>>() {

                    @Override
                    public void onSubscribe(Disposable d) {
                        addDisposable(d);
                    }

                    @Override
                    public void onNext(BaseResultBean<CoinUserInfoBean> bean) {
                        if (bean != null && bean.getData() != null) {
                            CoinUserInfoBean infoBean = bean.getData();
                            infoBean.setUsername(user.getUsername());
                            coin.setValue(infoBean);
                            UserUtil.getUserInfo(new OnUserInfoListener() {

                                @Override
                                public void onSuccess(User user) {
                                    if (user != null) {
                                        user.setCoinCount(infoBean.getCoinCount());
                                        user.setRank(infoBean.getRank());
                                        UserUtil.setUserInfo(user);
                                    }
                                }
                            });
                        }
                    }

                    @Override
                    public void onError(Throwable e) {
                        coin.setValue(null);
                    }

                    @Override
                    public void onComplete() {
                    }
                });
            } else {
                coin.setValue(null);
            }
        }
    });
}
Also used : Disposable(io.reactivex.disposables.Disposable) BaseResultBean(com.example.jingbin.cloudreader.bean.wanandroid.BaseResultBean) OnUserInfoListener(com.example.jingbin.cloudreader.data.OnUserInfoListener) User(me.jingbin.bymvvm.room.User) Observer(io.reactivex.Observer) CoinUserInfoBean(com.example.jingbin.cloudreader.bean.wanandroid.CoinUserInfoBean)

Example 2 with OnUserInfoListener

use of com.example.jingbin.cloudreader.data.OnUserInfoListener in project CloudReader by youlookwhat.

the class CoinDetailFragment method initRefreshView.

private void initRefreshView() {
    headerBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.header_coin_detail, (ViewGroup) bindingView.xrvWan.getParent(), false);
    RefreshHelper.initLinear(bindingView.xrvWan, true, 1);
    RefreshHelper.setSwipeRefreshView(bindingView.srlWan);
    mAdapter = new CoinAdapter(activity, false);
    bindingView.xrvWan.setAdapter(mAdapter);
    bindingView.xrvWan.addHeaderView(headerBinding.getRoot());
    headerBinding.tvHeaderCoin.setVisibility(View.INVISIBLE);
    bindingView.srlWan.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

        @Override
        public void onRefresh() {
            bindingView.xrvWan.postDelayed(new Runnable() {

                @Override
                public void run() {
                    viewModel.setPage(1);
                    getCoinLog();
                }
            }, 150);
        }
    });
    bindingView.xrvWan.setOnLoadMoreListener(new ByRecyclerView.OnLoadMoreListener() {

        @Override
        public void onLoadMore() {
            if (!bindingView.srlWan.isRefreshing()) {
                int page = viewModel.getPage();
                viewModel.setPage(++page);
                getCoinLog();
            } else {
                bindingView.xrvWan.loadMoreComplete();
            }
        }
    });
    UserUtil.getUserInfo(new OnUserInfoListener() {

        @Override
        public void onSuccess(User user) {
            if (user != null) {
                headerBinding.tvHeaderCoin.setText(String.valueOf(user.getCoinCount()));
            }
        }
    });
}
Also used : ByRecyclerView(me.jingbin.library.ByRecyclerView) OnUserInfoListener(com.example.jingbin.cloudreader.data.OnUserInfoListener) User(me.jingbin.bymvvm.room.User) CoinAdapter(com.example.jingbin.cloudreader.adapter.CoinAdapter) ViewGroup(android.view.ViewGroup) SwipeRefreshLayout(androidx.swiperefreshlayout.widget.SwipeRefreshLayout)

Aggregations

OnUserInfoListener (com.example.jingbin.cloudreader.data.OnUserInfoListener)2 User (me.jingbin.bymvvm.room.User)2 ViewGroup (android.view.ViewGroup)1 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)1 CoinAdapter (com.example.jingbin.cloudreader.adapter.CoinAdapter)1 BaseResultBean (com.example.jingbin.cloudreader.bean.wanandroid.BaseResultBean)1 CoinUserInfoBean (com.example.jingbin.cloudreader.bean.wanandroid.CoinUserInfoBean)1 Observer (io.reactivex.Observer)1 Disposable (io.reactivex.disposables.Disposable)1 ByRecyclerView (me.jingbin.library.ByRecyclerView)1