Search in sources :

Example 1 with TreeAdapter

use of com.example.jingbin.cloudreader.adapter.TreeAdapter 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)

Aggregations

View (android.view.View)1 GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 TreeAdapter (com.example.jingbin.cloudreader.adapter.TreeAdapter)1 HeaderItemTreeBinding (com.example.jingbin.cloudreader.databinding.HeaderItemTreeBinding)1 SpacesItemDecoration (me.jingbin.library.decoration.SpacesItemDecoration)1 OnItemFilterClickListener (me.jingbin.library.view.OnItemFilterClickListener)1