Search in sources :

Example 66 with RecyclerView

use of android.support.v7.widget.RecyclerView in project epoxy by airbnb.

the class VerticalGridCardSpacingDecoration method getItemOffsets.

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, State state) {
    if (outerPadding == -1 || innerPadding == -1) {
        DisplayMetrics m = view.getResources().getDisplayMetrics();
        outerPadding = (int) TypedValue.applyDimension(COMPLEX_UNIT_DIP, OUTER_PADDING_DP, m);
        innerPadding = (int) TypedValue.applyDimension(COMPLEX_UNIT_DIP, INNER_PADDING_DP, m);
    }
    int position = parent.getChildAdapterPosition(view);
    final GridLayoutManager layoutManager = (GridLayoutManager) parent.getLayoutManager();
    final SpanSizeLookup spanSizeLookup = layoutManager.getSpanSizeLookup();
    // Zero everything out for the common case
    outRect.setEmpty();
    int spanSize = spanSizeLookup.getSpanSize(position);
    int spanCount = layoutManager.getSpanCount();
    int spanIndex = spanSizeLookup.getSpanIndex(position, spanCount);
    if (spanSize == spanCount) {
        // Only item in row
        outRect.left = outerPadding;
        outRect.right = outerPadding;
    } else if (spanIndex == 0) {
        // First item in row
        outRect.left = outerPadding;
        outRect.right = innerPadding;
    } else if (spanIndex == spanCount - 1) {
        // Last item in row
        outRect.left = innerPadding;
        outRect.right = outerPadding;
    } else {
        // Inner item (not relevant for less than three columns)
        outRect.left = innerPadding;
        outRect.right = innerPadding;
    }
}
Also used : SpanSizeLookup(android.support.v7.widget.GridLayoutManager.SpanSizeLookup) GridLayoutManager(android.support.v7.widget.GridLayoutManager) DisplayMetrics(android.util.DisplayMetrics)

Example 67 with RecyclerView

use of android.support.v7.widget.RecyclerView in project GestureViews by alexvasilkov.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    RecyclerView recyclerView = Views.find(this, R.id.main_list);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(new SampleAdapter(this, getActivitiesList()));
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 68 with RecyclerView

use of android.support.v7.widget.RecyclerView in project GestureViews by alexvasilkov.

the class DefaultEndlessRecyclerAdapter method onAttachedToRecyclerView.

@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
        GridLayoutManager gridManager = (GridLayoutManager) recyclerView.getLayoutManager();
        spanCount = gridManager.getSpanCount();
        originalSpanLookup = gridManager.getSpanSizeLookup();
        gridManager.setSpanSizeLookup(spanSizes);
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager)

Example 69 with RecyclerView

use of android.support.v7.widget.RecyclerView in project GestureViews by alexvasilkov.

the class DefaultEndlessRecyclerAdapter method onDetachedFromRecyclerView.

@Override
public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
    super.onDetachedFromRecyclerView(recyclerView);
    if (recyclerView.getLayoutManager() instanceof GridLayoutManager) {
        GridLayoutManager gridManager = (GridLayoutManager) recyclerView.getLayoutManager();
        gridManager.setSpanSizeLookup(originalSpanLookup);
        originalSpanLookup = null;
        spanCount = 1;
    }
}
Also used : GridLayoutManager(android.support.v7.widget.GridLayoutManager)

Example 70 with RecyclerView

use of android.support.v7.widget.RecyclerView in project GestureViews by alexvasilkov.

the class EndlessRecyclerAdapter method loadNextItemsIfNeeded.

private void loadNextItemsIfNeeded(RecyclerView recyclerView) {
    if (!isLoading && !isError) {
        View lastVisibleChild = recyclerView.getChildAt(recyclerView.getChildCount() - 1);
        int lastVisiblePos = recyclerView.getChildAdapterPosition(lastVisibleChild);
        int total = getItemCount();
        if (lastVisiblePos >= total - loadingOffset) {
            // We need to use runnable, since recycler view does not like when we are notifying
            // about changes during scroll callback.
            recyclerView.post(new Runnable() {

                @Override
                public void run() {
                    loadNextItems();
                }
            });
        }
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)1778 View (android.view.View)1237 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1106 TextView (android.widget.TextView)384 GridLayoutManager (android.support.v7.widget.GridLayoutManager)234 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)225 ImageView (android.widget.ImageView)210 ArrayList (java.util.ArrayList)190 Toolbar (android.support.v7.widget.Toolbar)137 Intent (android.content.Intent)117 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)102 ViewGroup (android.view.ViewGroup)101 Nullable (android.support.annotation.Nullable)99 Context (android.content.Context)96 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)96 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)93 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)93 Bundle (android.os.Bundle)92 Test (org.junit.Test)90 Paint (android.graphics.Paint)80