com.github.jdsjlzx.recyclerview.LRecyclerView Java Examples

The following examples show how to use com.github.jdsjlzx.recyclerview.LRecyclerView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GridItemDecoration.java    From LRecyclerView with Apache License 2.0 6 votes vote down vote up
public void drawHorizontal(Canvas c, RecyclerView parent) {
    int childCount = parent.getChildCount();
    LRecyclerView recyclerView = (LRecyclerView) parent;
    LRecyclerViewAdapter adapter = (LRecyclerViewAdapter) parent.getAdapter();
    for (int i = 0; i < childCount; i++) {
        if ((recyclerView.isOnTop() && (adapter.isHeader(i) || adapter.isRefreshHeader(i))) || adapter.isFooter(i)) {
            c.drawRect(0, 0, 0, 0, mPaint);
        } else {
            final View child = parent.getChildAt(i);
            final int top = child.getBottom();
            final int bottom = top + verticalSpace;
            int left = child.getLeft();
            int right = child.getRight();
            c.drawRect(left, top, right, bottom, mPaint);
        }
    }
}
 
Example #2
Source File: GridItemDecoration.java    From LRecyclerView with Apache License 2.0 6 votes vote down vote up
public void drawVertical(Canvas c, RecyclerView parent) {
    final int childCount = parent.getChildCount();
    LRecyclerView recyclerView = (LRecyclerView) parent;
    LRecyclerViewAdapter adapter = (LRecyclerViewAdapter) parent.getAdapter();
    for (int i = 0; i < childCount; i++) {
        if ((recyclerView.isOnTop() && (adapter.isHeader(i) || adapter.isRefreshHeader(i))) || adapter.isFooter(i)) {
            c.drawRect(0, 0, 0, 0, mPaint);
        } else {
            final View child = parent.getChildAt(i);
            final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
            final int top = child.getTop();
            final int bottom = child.getBottom() + verticalSpace;
            final int left = child.getRight() + params.rightMargin;
            final int right = left + horizontalSpace;
            c.drawRect(left, top, right, bottom, mPaint);
        }

    }
}
 
Example #3
Source File: BaseDecorationFragment.java    From LRecyclerView with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View view = inflater.inflate(R.layout.fragment_recycler, container, false);

    mList = (LRecyclerView) view.findViewById(R.id.list);
    mList.setPullRefreshEnabled(false);

    return view;
}
 
Example #4
Source File: CommentExpandAdapter.java    From LRecyclerView with Apache License 2.0 5 votes vote down vote up
public CommentViewHolder(View view, LRecyclerView recyclerView) {
    super(view, (ImageView) view.findViewById(R.id.item_arrow),recyclerView);

    tvName = (TextView) view.findViewById(R.id.tvname);
    tvComment = (TextView) view.findViewById(R.id.tvComment);
    tvTime = (TextView) view.findViewById(R.id.tvTime);
    tvReply = (TextView) view.findViewById(R.id.tvReply);
    imgAvatar = (ImageView) view.findViewById(R.id.avatacomment);

}
 
Example #5
Source File: ExpandableRecyclerAdapter.java    From LRecyclerView with Apache License 2.0 5 votes vote down vote up
public HeaderViewHolder(View view, final ImageView arrow, final LRecyclerView recyclerView) {
    super(view);

    this.arrow = arrow;
    this.recyclerView = recyclerView;

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            handleClick();
        }
    });
}
 
Example #6
Source File: BilibiliActivity.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_ll_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mRecyclerView = (LRecyclerView) findViewById(R.id.list);
    mRecyclerView.setLayoutManager(new GridLayoutManager(this,2));

    mVisitables = getData();
    mMainAdapter = new MainAdapter(new ListTypeFactory(), mVisitables);
    mLRecyclerViewAdapter = new LRecyclerViewAdapter(mMainAdapter);
    mRecyclerView.setAdapter(mLRecyclerViewAdapter);

    mLRecyclerViewAdapter.setSpanSizeLookup(new LRecyclerViewAdapter.SpanSizeLookup() {
        @Override
        public int getSpanSize(GridLayoutManager gridLayoutManager, int position) {
            Object item = mVisitables.get(position);
            return (item instanceof HotList || item instanceof ProductList || item instanceof Category) ? gridLayoutManager.getSpanCount() : 1;
        }
    });

    mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this));

    mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    mRecyclerView.refreshComplete(10);
                }
            },1000);
        }
    });

    mRecyclerView.refresh();
    mRecyclerView.setLoadMoreEnabled(false);
    //是否允许嵌套滑动
    mRecyclerView.setNestedScrollingEnabled(false);

}
 
Example #7
Source File: ExpandableActivity.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_ll_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mRecyclerView = (LRecyclerView) findViewById(R.id.list);


    mDataAdapter = new ExpandableItemAdapter(this);
    mDataAdapter.setDataList(generateData());

    mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter);
    mRecyclerView.setAdapter(mLRecyclerViewAdapter);

    DividerDecoration divider = new DividerDecoration.Builder(this)
            .setHeight(R.dimen.default_divider_height)
            .setPadding(R.dimen.default_divider_padding)
            .setColorResource(R.color.split)
            .build();
    //mRecyclerView.setHasFixedSize(true);
    mRecyclerView.addItemDecoration(divider);

    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    //add a HeaderView
    View header = LayoutInflater.from(this).inflate(R.layout.sample_header,(ViewGroup)findViewById(android.R.id.content), false);

    mLRecyclerViewAdapter.addHeaderView(header);
    mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this));

    //禁用下拉刷新功能
    mRecyclerView.setPullRefreshEnabled(false);

    //禁用自动加载更多功能
    //mRecyclerView.setLoadMoreEnabled(false);

    //add a FooterView
    //mLRecyclerViewAdapter.addFooterView(sampleFooter);

}
 
Example #8
Source File: CommentExpandAdapter.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
public CommentExpandAdapter(Context context, LRecyclerView recyclerView) {
    super(context);
    this.recyclerView = recyclerView;
    //setItems(getSampleItems());
}
 
Example #9
Source File: ExpandableRecyclerViewOneActivity.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_ll_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mRecyclerView = (LRecyclerView) findViewById(R.id.list);


    mDataAdapter = new CommentExpandAdapter(this,mRecyclerView);
    mDataAdapter.setMode(ExpandableRecyclerAdapter.MODE_ACCORDION);
    mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter);
    mRecyclerView.setAdapter(mLRecyclerViewAdapter);

    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    mRecyclerView.setRefreshProgressStyle(ProgressStyle.BallSpinFadeLoader);
    mRecyclerView.setArrowImageView(R.drawable.ic_pulltorefresh_arrow);

    mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this));

    mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            mCurrentCounter = 0;
            isRefresh = true;
            requestData();
        }
    });

    mRecyclerView.refresh();

    //不要在调用下面代码
    /*mLRecyclerViewAdapter.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            //ItemModel item = mDataAdapter.getDataList().get(position);
            //AppToast.showShortText(ExpandableRecyclerViewOneActivity.this, item.title);
        }

        @Override
        public void onItemLongClick(View view, int position) {
            //ItemModel item = mDataAdapter.getDataList().get(position);
            //AppToast.showShortText(ExpandableRecyclerViewOneActivity.this, "onItemLongClick - " + item.title);
        }
    });*/

}
 
Example #10
Source File: ListDragMenuActivity.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_ll_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mRecyclerView = (LRecyclerView) findViewById(R.id.list);

    //setLayoutManager must before setAdapter
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    //init data
    ArrayList<ItemModel> dataList = new ArrayList<>();
    for (int i = 0; i < 16; i++) {
        ItemModel itemModel = new ItemModel();
        itemModel.title = "item" + i;
        dataList.add(itemModel);
    }

    mItemTouchHelper = new ItemTouchHelper(mCallback);
    mItemTouchHelper.attachToRecyclerView(mRecyclerView);

    mDataAdapter = new DataAdapter(this);
    mDataAdapter.setDataList(dataList);
    mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter);
    mRecyclerView.setAdapter(mLRecyclerViewAdapter);

    DividerDecoration divider = new DividerDecoration.Builder(this)
            .setHeight(R.dimen.default_divider_height)
            .setPadding(R.dimen.default_divider_padding)
            .setColorResource(R.color.split)
            .build();
    mRecyclerView.addItemDecoration(divider);
    mRecyclerView.setHasFixedSize(true);


    mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this));

    //add a FooterView
    mLRecyclerViewAdapter.addFooterView(new SampleFooter(this));

    //禁用下拉刷新功能
    mRecyclerView.setPullRefreshEnabled(false);

    //禁用自动加载更多功能
    mRecyclerView.setLoadMoreEnabled(false);

}
 
Example #11
Source File: Nest2RecyclerViewActivity.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_ll_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mRecyclerView = (LRecyclerView) findViewById(R.id.list);
    mRecyclerView.setNestedScrollingEnabled(false);

    mShopAdapter = new ShopAdapterBase(this,mGoodsList);

    //setLayoutManager must before setAdapter
    GridLayoutManager layoutManager = new GridLayoutManager(this, 2);
    mRecyclerView.setLayoutManager(layoutManager);

    initData();

    mLRecyclerViewAdapter = new LRecyclerViewAdapter(mShopAdapter);
    mRecyclerView.setAdapter(mLRecyclerViewAdapter);
    mShopAdapter.addAll(mItemModels);

    DividerDecoration divider = new DividerDecoration.Builder(this)
            .setHeight(R.dimen.default_divider_height)
            .setPadding(R.dimen.default_divider_padding)
            .setColorResource(R.color.split)
            .build();

    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.addItemDecoration(divider);

    mLRecyclerViewAdapter.setSpanSizeLookup(new LRecyclerViewAdapter.SpanSizeLookup() {
        @Override
        public int getSpanSize(GridLayoutManager gridLayoutManager, int position) {
            MultipleItem item = mShopAdapter.getDataList().get(position);
            if (item.getItemType() == MultipleItem.LIST) {
                return gridLayoutManager.getSpanCount();
            } else {
                return 1;
            }

        }
    });

    mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this));

    mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    mRecyclerView.refreshComplete(10);
                }
            },1000);
        }
    });

    mRecyclerView.refresh();

    //是否允许嵌套滑动
    mRecyclerView.setNestedScrollingEnabled(false);

}
 
Example #12
Source File: EndlessGridLayoutActivity.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_ll_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);


    mRecyclerView = (LRecyclerView) findViewById(R.id.list);

    //setLayoutManager must before setAdapter
    GridLayoutManager manager = new GridLayoutManager(this, 2);
    mRecyclerView.setLayoutManager(manager);

    mDataAdapter = new DataAdapter(this);

    mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter);
    mRecyclerView.setAdapter(mLRecyclerViewAdapter);

    //设置头部加载颜色
    mRecyclerView.setHeaderViewColor(R.color.colorAccent, R.color.dark ,android.R.color.white);
    //设置底部加载颜色
    mRecyclerView.setFooterViewColor(R.color.colorAccent, R.color.dark ,android.R.color.white);
    //设置底部加载文字提示
    mRecyclerView.setFooterViewHint("拼命加载中","已经全部为你呈现了","网络不给力啊,点击再试一次吧");

    int spacing = getResources().getDimensionPixelSize(R.dimen.dp_4);
    mRecyclerView.addItemDecoration(SpacesItemDecoration.newInstance(spacing, spacing, manager.getSpanCount(), Color.GRAY));

    //根据需要选择使用GridItemDecoration还是SpacesItemDecoration
    GridItemDecoration divider = new GridItemDecoration.Builder(this)
            .setHorizontal(R.dimen.default_divider_padding)
            .setVertical(R.dimen.default_divider_padding)
            .setColorResource(R.color.split)
            .build();
    //mRecyclerView.addItemDecoration(divider);

    mRecyclerView.setHasFixedSize(true);

    mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this));

    //设置span,自己可以体验效果
    /*mLRecyclerViewAdapter.setSpanSizeLookup(new LRecyclerViewAdapter.SpanSizeLookup() {
        @Override
        public int getSpanSize(GridLayoutManager gridLayoutManager, int position) {
            if (position % 4 == 0) {
                return gridLayoutManager.getSpanCount();
            } else {
                return 1;
            }

        }
    });*/


    mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            mCurrentCounter = 0;
            mDataAdapter.clear();
            requestData();
        }
    });

    mRecyclerView.setOnLoadMoreListener(new OnLoadMoreListener() {
        @Override
        public void onLoadMore() {
            if (mCurrentCounter < TOTAL_COUNTER) {
                // loading more
                requestData();
            } else {
                //the end
                mRecyclerView.setNoMore(true);
            }
        }
    });

    mRecyclerView.refresh();

}
 
Example #13
Source File: CollapsingToolbarLayoutActivity.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_collapsing_toolbar_layout);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mRecyclerView = (LRecyclerView) findViewById(R.id.list);

    //init data
    ArrayList<ItemModel> dataList = new ArrayList<>();

    for (int i = 0; i < 10; i++) {

        ItemModel item = new ItemModel();
        item.id = i;
        item.title = "item" + i;
        dataList.add(item);
    }

    mCurrentCounter = dataList.size();

    mDataAdapter = new DataAdapter(this);
    mDataAdapter.addAll(dataList);

    mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter);
    mRecyclerView.setAdapter(mLRecyclerViewAdapter);

    DividerDecoration divider = new DividerDecoration.Builder(this)
            .setHeight(R.dimen.default_divider_height)
            .setPadding(R.dimen.default_divider_padding)
            .setColorResource(R.color.split)
            .build();

    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.addItemDecoration(divider);

    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            mCurrentCounter = 0;
            mDataAdapter.clear();
            requestData();
        }
    });

    mRecyclerView.setOnLoadMoreListener(new OnLoadMoreListener() {
        @Override
        public void onLoadMore() {
            if (mCurrentCounter < TOTAL_COUNTER) {
                // loading more
                requestData();
            } else {
                //the end
                mRecyclerView.setNoMore(true);
            }
        }
    });

}
 
Example #14
Source File: EndlessStaggeredGridLayoutActivity.java    From LRecyclerView with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sample_ll_activity);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mRecyclerView = (LRecyclerView) findViewById(R.id.list);

    mDataAdapter = new DataAdapter(this);

    mLRecyclerViewAdapter = new LRecyclerViewAdapter(mDataAdapter);
    mRecyclerView.setAdapter(mLRecyclerViewAdapter);

    //setLayoutManager
    StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager( 2, StaggeredGridLayoutManager.VERTICAL);
    layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
    //防止item位置互换
    layoutManager.setGapStrategy(StaggeredGridLayoutManager.GAP_HANDLING_NONE);
    mRecyclerView.setLayoutManager(layoutManager);

    mLRecyclerViewAdapter.addHeaderView(new SampleHeader(this));

    mRecyclerView.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh() {
            mCurrentCounter = 0;
            mDataAdapter.clear();
            requestData();
        }
    });

    mRecyclerView.setOnLoadMoreListener(new OnLoadMoreListener() {
        @Override
        public void onLoadMore() {
            if (mCurrentCounter < TOTAL_COUNTER) {
                // loading more
                requestData();
            } else {
                //the end
                mRecyclerView.setNoMore(true);
            }
        }
    });


    mRecyclerView.refresh();

}