use of com.example.jingbin.cloudreader.bean.wanandroid.ArticlesBean in project CloudReader by youlookwhat.
the class NavigationViewModel method getNavigationJson.
public void getNavigationJson() {
Disposable subscribe = HttpClient.Builder.getWanAndroidServer().getNaviJson().subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(new Consumer<NaviJsonBean>() {
@Override
public void accept(NaviJsonBean naviJsonBean) throws Exception {
if (naviJsonBean != null && naviJsonBean.getData() != null && naviJsonBean.getData().size() > 0) {
// title
dataTitle.setValue(naviJsonBean.getData());
// content
ArrayList<ArticlesBean> list = new ArrayList<>();
// content部分对应分类的position
ArrayList<Integer> positions = new ArrayList<>();
for (int i = 0; i < naviJsonBean.getData().size(); i++) {
NaviJsonBean.DataBean dataBean = naviJsonBean.getData().get(i);
ArticlesBean bean = new ArticlesBean();
bean.setNavigationName(dataBean.getName());
positions.add(list.size());
if (i != 0) {
// 最后一个item可能有一个或两个
hashMap.put(list.size() - 1, i - 1);
hashMap.put(list.size() - 2, i - 1);
}
hashMap.put(list.size(), i);
list.add(bean);
list.addAll(dataBean.getArticles());
}
data.setValue(list);
titlePositions.setValue(positions);
} else {
data.setValue(null);
dataTitle.setValue(null);
}
}
}, new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
data.setValue(null);
dataTitle.setValue(null);
}
});
addDisposable(subscribe);
}
use of com.example.jingbin.cloudreader.bean.wanandroid.ArticlesBean in project CloudReader by youlookwhat.
the class NavigationFragment method initRefreshView.
private void initRefreshView() {
mNaviAdapter = new NavigationAdapter();
layoutManager = new LinearLayoutManager(activity);
bindingView.xrvNavi.setLayoutManager(layoutManager);
bindingView.xrvNavi.setAdapter(mNaviAdapter);
mContentAdapter = new NavigationContentAdapter();
StickyGridLayoutManager gridLayoutManager = new StickyGridLayoutManager(activity, 6, GridLayoutManager.VERTICAL, mContentAdapter);
bindingView.xrvNaviDetail.setLayoutManager(gridLayoutManager);
bindingView.xrvNaviDetail.setAdapter(mContentAdapter);
mNaviAdapter.setOnSelectListener(new NavigationAdapter.OnSelectListener() {
@Override
public void onSelected(int position) {
selectItem(position);
moveToCenter(position);
Integer titlePosition = viewModel.getTitlePositions().getValue().get(position);
gridLayoutManager.scrollToPositionWithOffset(titlePosition, 0);
}
});
bindingView.xrvNaviDetail.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int itemPosition = gridLayoutManager.findFirstVisibleItemPosition();
Integer integer = viewModel.getHashMap().get(itemPosition);
if (integer != null && currentPosition != integer) {
selectItem(integer);
moveToCenter(integer);
}
}
});
bindingView.xrvNaviDetail.setOnItemClickListener(new OnItemFilterClickListener() {
@Override
public void onSingleClick(View v, int position) {
ArticlesBean itemData = mContentAdapter.getItemData(position);
if (!TextUtils.isEmpty(itemData.getLink())) {
WebViewActivity.loadUrl(v.getContext(), itemData.getLink(), itemData.getTitle());
}
}
});
onObserveViewModel();
}
Aggregations