Search in sources :

Example 1 with CoinUserInfoBean

use of com.example.jingbin.cloudreader.bean.wanandroid.CoinUserInfoBean 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 CoinUserInfoBean

use of com.example.jingbin.cloudreader.bean.wanandroid.CoinUserInfoBean in project CloudReader by youlookwhat.

the class MainActivity method initDrawerLayout.

/**
 * inflateHeaderView 进来的布局要宽一些
 */
private void initDrawerLayout() {
    bindingView.navView.inflateHeaderView(R.layout.nav_header_main);
    View headerView = bindingView.navView.getHeaderView(0);
    bind = DataBindingUtil.bind(headerView);
    bind.setViewModel(viewModel);
    viewModel.isReadOk.set(SPUtils.isRead());
    viewModel.isReadOkNight.set(SPUtils.isReadNight());
    GlideUtil.displayCircle(bind.ivAvatar, ConstantsImageUrl.IC_AVATAR);
    bind.llNavExit.setOnClickListener(this);
    bind.ivAvatar.setOnClickListener(this);
    bind.llNavHomepage.setOnClickListener(listener);
    bind.llNavScanDownload.setOnClickListener(listener);
    bind.llNavDeedback.setOnClickListener(listener);
    bind.llNavAbout.setOnClickListener(listener);
    bind.llNavLogin.setOnClickListener(listener);
    bind.llNavCollect.setOnClickListener(listener);
    bind.llNavShare.setOnClickListener(listener);
    bind.llInfo.setOnClickListener(listener);
    bind.llNavCoin.setOnClickListener(listener);
    bind.llNavAdmire.setOnClickListener(listener);
    bind.tvRank.setOnClickListener(listener);
    bind.llNavNightMode.setOnClickListener(listener);
    viewModel.getUserInfo();
    viewModel.coin.observe(this, new Observer<CoinUserInfoBean>() {

        @Override
        public void onChanged(@Nullable CoinUserInfoBean coinUserInfoBean) {
            if (coinUserInfoBean != null) {
                bind.tvUsername.setText(coinUserInfoBean.getUsername());
                bind.tvLevel.setText(String.format("Lv.%s", UserUtil.getLevel(coinUserInfoBean.getCoinCount())));
                bind.tvRank.setText(String.format("排名 %s", coinUserInfoBean.getRank()));
            } else {
                bind.tvUsername.setText("玩安卓登录");
                bind.tvLevel.setText("Lv.1");
                bind.tvRank.setText("");
            }
        }
    });
}
Also used : CoinUserInfoBean(com.example.jingbin.cloudreader.bean.wanandroid.CoinUserInfoBean) ImageView(android.widget.ImageView) View(android.view.View)

Aggregations

CoinUserInfoBean (com.example.jingbin.cloudreader.bean.wanandroid.CoinUserInfoBean)2 View (android.view.View)1 ImageView (android.widget.ImageView)1 BaseResultBean (com.example.jingbin.cloudreader.bean.wanandroid.BaseResultBean)1 OnUserInfoListener (com.example.jingbin.cloudreader.data.OnUserInfoListener)1 Observer (io.reactivex.Observer)1 Disposable (io.reactivex.disposables.Disposable)1 User (me.jingbin.bymvvm.room.User)1