Search in sources :

Example 1 with GravityPagerSnapHelper

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()));
}
Also used : GravitySnapHelper(com.github.rubensousa.gravitysnaphelper.GravitySnapHelper) LinearSnapHelper(android.support.v7.widget.LinearSnapHelper) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) GravityPagerSnapHelper(com.github.rubensousa.gravitysnaphelper.GravityPagerSnapHelper)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 LinearSnapHelper (android.support.v7.widget.LinearSnapHelper)1 GravityPagerSnapHelper (com.github.rubensousa.gravitysnaphelper.GravityPagerSnapHelper)1 GravitySnapHelper (com.github.rubensousa.gravitysnaphelper.GravitySnapHelper)1