Search in sources :

Example 1 with SpacesItemDecoration

use of me.jingbin.library.decoration.SpacesItemDecoration in project CloudReader by youlookwhat.

the class CategoryArticleFragment method initRefreshView.

private void initRefreshView() {
    mAdapter = new CategoryArticleAdapter(activity);
    bindingView.recyclerView.setLayoutManager(new LinearLayoutManager(activity));
    bindingView.recyclerView.setItemAnimator(null);
    bindingView.recyclerView.addItemDecoration(new SpacesItemDecoration(activity).setHeaderNoShowDivider(isRefresh ? 1 : 0));
    bindingView.recyclerView.setRefreshHeaderView(new NeteaseRefreshHeaderView(activity));
    bindingView.recyclerView.setLoadingMoreView(new NeteaseLoadMoreView(activity));
    bindingView.recyclerView.setAdapter(mAdapter);
    bindingView.recyclerView.setOnLoadMoreListener(new ByRecyclerView.OnLoadMoreListener() {

        @Override
        public void onLoadMore() {
            int page = viewModel.getPage();
            viewModel.setPage(++page);
            getHomeList();
        }
    });
    if (isRefresh) {
        bindingView.recyclerView.setOnRefreshListener(new ByRecyclerView.OnRefreshListener() {

            @Override
            public void onRefresh() {
                viewModel.setPage(0);
                getHomeList();
            }
        });
    }
}
Also used : ByRecyclerView(me.jingbin.library.ByRecyclerView) NeteaseRefreshHeaderView(com.example.jingbin.cloudreader.view.byview.NeteaseRefreshHeaderView) CategoryArticleAdapter(com.example.jingbin.cloudreader.adapter.CategoryArticleAdapter) SpacesItemDecoration(me.jingbin.library.decoration.SpacesItemDecoration) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) NeteaseLoadMoreView(com.example.jingbin.cloudreader.view.byview.NeteaseLoadMoreView)

Example 2 with SpacesItemDecoration

use of me.jingbin.library.decoration.SpacesItemDecoration in project CloudReader by youlookwhat.

the class TreeFragment method initRefreshView.

private void initRefreshView() {
    RefreshHelper.setSwipeRefreshView(bindingView.srlWan);
    bindingView.srlWan.setOnRefreshListener(() -> bindingView.srlWan.postDelayed(this::getTree, 150));
    LinearLayoutManager layoutManager = new LinearLayoutManager(activity);
    bindingView.xrvWan.setLayoutManager(layoutManager);
    mTreeAdapter = new TreeAdapter(activity);
    bindingView.xrvWan.setAdapter(mTreeAdapter);
    HeaderItemTreeBinding oneBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.header_item_tree, null, false);
    bindingView.xrvWan.addHeaderView(oneBinding.getRoot());
    oneBinding.tvPosition.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!mTreeAdapter.isSelect()) {
                GridLayoutManager layoutManager = new GridLayoutManager(activity, 2);
                bindingView.xrvWan.setLayoutManager(layoutManager);
                oneBinding.tvPosition.setText("选择类别");
                mTreeAdapter.setSelect(true);
                mTreeAdapter.notifyDataSetChanged();
                bindingView.xrvWan.addItemDecoration(new SpacesItemDecoration(activity).setNoShowDivider(1, 0).setDrawable(R.drawable.shape_line));
            } else {
                LinearLayoutManager layoutManager = new LinearLayoutManager(activity);
                bindingView.xrvWan.setLayoutManager(layoutManager);
                oneBinding.tvPosition.setText("发现页内容订制");
                mTreeAdapter.setSelect(false);
                mTreeAdapter.notifyDataSetChanged();
                if (bindingView.xrvWan.getItemDecorationCount() > 0) {
                    bindingView.xrvWan.removeItemDecorationAt(0);
                }
            }
        }
    });
    bindingView.xrvWan.setOnItemClickListener(new OnItemFilterClickListener() {

        @Override
        public void onSingleClick(View v, int position) {
            if (mTreeAdapter.isSelect()) {
                if (mTreeAdapter.getSelectedPosition() == position) {
                    ToastUtil.showToastLong("当前已经是\"" + mTreeAdapter.getData().get(position).getName() + "\"");
                    return;
                }
                LinearLayoutManager layoutManager = new LinearLayoutManager(activity);
                bindingView.xrvWan.setLayoutManager(layoutManager);
                oneBinding.tvPosition.setText("发现页内容订制");
                mTreeAdapter.setSelect(false);
                mTreeAdapter.notifyDataSetChanged();
                if (bindingView.xrvWan.getItemDecorationCount() > 0) {
                    bindingView.xrvWan.removeItemDecorationAt(0);
                }
                layoutManager.scrollToPositionWithOffset(position + bindingView.xrvWan.getCustomTopItemViewCount(), 0);
                RxBus.getDefault().post(RxCodeConstants.FIND_CUSTOM, position);
            }
        }
    });
}
Also used : HeaderItemTreeBinding(com.example.jingbin.cloudreader.databinding.HeaderItemTreeBinding) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) OnItemFilterClickListener(me.jingbin.library.view.OnItemFilterClickListener) TreeAdapter(com.example.jingbin.cloudreader.adapter.TreeAdapter) SpacesItemDecoration(me.jingbin.library.decoration.SpacesItemDecoration) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View)

Example 3 with SpacesItemDecoration

use of me.jingbin.library.decoration.SpacesItemDecoration in project CloudReader by youlookwhat.

the class SearchActivity method initViewModel.

private void initViewModel() {
    mAdapter = new CategoryArticleAdapter(this);
    if (binding.recyclerView.getItemDecorationCount() > 0) {
        binding.recyclerView.removeItemDecorationAt(0);
    }
    binding.recyclerView.addItemDecoration(new SpacesItemDecoration(this, SpacesItemDecoration.VERTICAL));
    binding.recyclerView.setAdapter(mAdapter);
    binding.recyclerView.setItemAnimator(null);
    binding.recyclerView.setOnLoadMoreListener(new ByRecyclerView.OnLoadMoreListener() {

        @Override
        public void onLoadMore() {
            int page = viewModel.getPage();
            viewModel.setPage(++page);
            loadWanData();
        }
    });
    if (!TextUtils.isEmpty(keyWord)) {
        viewModel.setPage(0);
        loadWanData();
    }
}
Also used : ByRecyclerView(me.jingbin.library.ByRecyclerView) CategoryArticleAdapter(com.example.jingbin.cloudreader.adapter.CategoryArticleAdapter) SpacesItemDecoration(me.jingbin.library.decoration.SpacesItemDecoration)

Example 4 with SpacesItemDecoration

use of me.jingbin.library.decoration.SpacesItemDecoration in project CloudReader by youlookwhat.

the class RefreshHelper method initLinear.

public static ByRecyclerView initLinear(ByRecyclerView recyclerView, boolean isDivider, int headerNoShowSize) {
    recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
    // recyclerView.setItemAnimator(null);
    if (isDivider) {
        recyclerView.addItemDecoration(new SpacesItemDecoration(recyclerView.getContext(), SpacesItemDecoration.VERTICAL, headerNoShowSize).setDrawable(R.drawable.shape_line));
    }
    recyclerView.setRefreshHeaderView(new NeteaseRefreshHeaderView(recyclerView.getContext()));
    recyclerView.setLoadingMoreView(new NeteaseLoadMoreView(recyclerView.getContext()));
    return recyclerView;
}
Also used : NeteaseRefreshHeaderView(com.example.jingbin.cloudreader.view.byview.NeteaseRefreshHeaderView) SpacesItemDecoration(me.jingbin.library.decoration.SpacesItemDecoration) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) NeteaseLoadMoreView(com.example.jingbin.cloudreader.view.byview.NeteaseLoadMoreView)

Example 5 with SpacesItemDecoration

use of me.jingbin.library.decoration.SpacesItemDecoration in project CloudReader by youlookwhat.

the class AndroidFragment method initRecyclerView.

private void initRecyclerView() {
    adapter = new GankAndroidAdapter();
    // 加了分割线,滚动条才会置顶
    SpacesItemDecoration itemDecoration = new SpacesItemDecoration(activity, SpacesItemDecoration.VERTICAL, 1);
    itemDecoration.setDrawable(R.drawable.shape_transparent);
    RefreshHelper.initLinear(bindingView.xrvAndroid, false).addItemDecoration(itemDecoration);
    bindingView.xrvAndroid.setAdapter(adapter);
    bindingView.xrvAndroid.setOnRefreshListener(new ByRecyclerView.OnRefreshListener() {

        @Override
        public void onRefresh() {
            viewModel.setPage(1);
            loadAndroidData();
        }
    });
    bindingView.xrvAndroid.setOnLoadMoreListener(new ByRecyclerView.OnLoadMoreListener() {

        @Override
        public void onLoadMore() {
            int page = viewModel.getPage();
            page++;
            viewModel.setPage(page);
            loadAndroidData();
        }
    });
}
Also used : ByRecyclerView(me.jingbin.library.ByRecyclerView) GankAndroidAdapter(com.example.jingbin.cloudreader.adapter.GankAndroidAdapter) SpacesItemDecoration(me.jingbin.library.decoration.SpacesItemDecoration)

Aggregations

SpacesItemDecoration (me.jingbin.library.decoration.SpacesItemDecoration)5 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)3 ByRecyclerView (me.jingbin.library.ByRecyclerView)3 CategoryArticleAdapter (com.example.jingbin.cloudreader.adapter.CategoryArticleAdapter)2 NeteaseLoadMoreView (com.example.jingbin.cloudreader.view.byview.NeteaseLoadMoreView)2 NeteaseRefreshHeaderView (com.example.jingbin.cloudreader.view.byview.NeteaseRefreshHeaderView)2 View (android.view.View)1 GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)1 GankAndroidAdapter (com.example.jingbin.cloudreader.adapter.GankAndroidAdapter)1 TreeAdapter (com.example.jingbin.cloudreader.adapter.TreeAdapter)1 HeaderItemTreeBinding (com.example.jingbin.cloudreader.databinding.HeaderItemTreeBinding)1 OnItemFilterClickListener (me.jingbin.library.view.OnItemFilterClickListener)1