use of com.github.rubensousa.gravitysnaphelper.GravityPagerSnapHelper in project RecyclerViewSnap by rubensousa.
the class SnapAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Snap snap = mSnaps.get(position);
holder.snapTextView.setText(snap.getText());
if (snap.getGravity() == Gravity.START || snap.getGravity() == Gravity.END) {
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
new GravitySnapHelper(snap.getGravity(), false, this).attachToRecyclerView(holder.recyclerView);
} else if (snap.getGravity() == Gravity.CENTER_HORIZONTAL || snap.getGravity() == Gravity.CENTER_VERTICAL) {
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder.recyclerView.getContext(), snap.getGravity() == Gravity.CENTER_HORIZONTAL ? LinearLayoutManager.HORIZONTAL : LinearLayoutManager.VERTICAL, false));
new LinearSnapHelper().attachToRecyclerView(holder.recyclerView);
} else if (snap.getGravity() == Gravity.CENTER) {
// Pager snap
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder.recyclerView.getContext(), LinearLayoutManager.HORIZONTAL, false));
new GravityPagerSnapHelper(Gravity.START).attachToRecyclerView(holder.recyclerView);
} else {
// Top / Bottom
holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder.recyclerView.getContext()));
new GravitySnapHelper(snap.getGravity()).attachToRecyclerView(holder.recyclerView);
}
holder.recyclerView.setAdapter(new Adapter(snap.getGravity() == Gravity.START || snap.getGravity() == Gravity.END || snap.getGravity() == Gravity.CENTER_HORIZONTAL, snap.getGravity() == Gravity.CENTER, snap.getApps()));
}
Aggregations