use of me.jingbin.library.stickyview.StickyGridLayoutManager 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