use of la.xiong.androidquick.network.RetrofitManager in project AndroidQuick by ddnosh.
the class Network2Fragment method initViewsAndEvents.
@Override
protected void initViewsAndEvents() {
DialogUtil.showLoadingDialog(mContext, "加载中...");
mTestBeanList = new ArrayList<>();
mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
mRecyclerView.setHasFixedSize(true);
mCommonAdapter = new CommonAdapter<TestBean>(getActivity(), R.layout.item_common_adapter_2, mTestBeanList) {
@Override
public void convert(CommonViewHolder holder, final TestBean bean) {
holder.setText(R.id.tv_login, bean.getLogin());
holder.setText(R.id.tv_id, bean.getId() + "");
holder.setImageResourceWithGlide(R.id.iv_avatar, bean.getAvatar_url());
holder.setOnClickListener(R.id.ll_rv_common_adapter_item, new View.OnClickListener() {
@Override
public void onClick(View v) {
LogUtil.d(TAG, "onItemClick");
ToastUtil.showToast(bean.getLogin() + " clicked!");
bean.setLogin(bean.getLogin() + " clicked!");
notifyDataSetChanged();
}
});
}
};
mRecyclerView.setAdapter(mCommonAdapter);
mCompositeSubscription = new CompositeSubscription();
mRetrofitManager = new RetrofitManager();
Subscription subscription = mRetrofitManager.createApi(MyApplication.getInstance().getApplicationContext(), TestApis.class).getOctocat("https://api.github.com/repos/octocat/Hello-World/contributors").subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new BaseSubscriber<List<TestBean>>() {
@Override
public void onNext(List<TestBean> list) {
DialogUtil.dismissLoadingDialog(mContext);
LogUtil.i(TAG, list.toString());
// 不能这样赋值:mTestBeanList = list;
// 方法一
// mTestBeanList.clear();
// mTestBeanList.addAll(list);
// mCommonAdapter.notifyDataSetChanged();
// 方法二
mCommonAdapter.update(list);
}
@Override
public void onError(Throwable e) {
super.onError(e);
DialogUtil.dismissLoadingDialog(mContext);
}
});
mCompositeSubscription.add(subscription);
}
Aggregations