Search in sources :

Example 1 with StickyGridLayoutManager

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();
}
Also used : NavigationAdapter(com.example.jingbin.cloudreader.adapter.NavigationAdapter) StickyGridLayoutManager(me.jingbin.library.stickyview.StickyGridLayoutManager) ArticlesBean(com.example.jingbin.cloudreader.bean.wanandroid.ArticlesBean) OnItemFilterClickListener(me.jingbin.library.view.OnItemFilterClickListener) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) ByRecyclerView(me.jingbin.library.ByRecyclerView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) NavigationContentAdapter(com.example.jingbin.cloudreader.adapter.NavigationContentAdapter) ByRecyclerView(me.jingbin.library.ByRecyclerView) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Aggregations

View (android.view.View)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 NavigationAdapter (com.example.jingbin.cloudreader.adapter.NavigationAdapter)1 NavigationContentAdapter (com.example.jingbin.cloudreader.adapter.NavigationContentAdapter)1 ArticlesBean (com.example.jingbin.cloudreader.bean.wanandroid.ArticlesBean)1 ByRecyclerView (me.jingbin.library.ByRecyclerView)1 StickyGridLayoutManager (me.jingbin.library.stickyview.StickyGridLayoutManager)1 OnItemFilterClickListener (me.jingbin.library.view.OnItemFilterClickListener)1