/**
 * Copyright © 2017 Wayfair. All rights reserved.
 */
package com.wayfair.brickkit;

import android.content.Context;
import android.support.v7.widget.GridLayoutManager;

import com.wayfair.brickkit.brick.BaseBrick;

/**
 * {@link android.support.v7.widget.GridLayoutManager.SpanSizeLookup} which grabs the span size
 * from the brick at the given position.
 */
class BrickSpanSizeLookup extends GridLayoutManager.SpanSizeLookup {
    private final Context context;
    private final BrickDataManager brickDataManager;

    /**
     * Constructor.
     *
     * @param ctx context passed to bricks when looking up their span count
     * @param manager {@link} BrickDataManager to look up bricks in
     */
    BrickSpanSizeLookup(Context ctx, BrickDataManager manager) {
        context = ctx;
        brickDataManager = manager;
    }

    @Override
    public int getSpanSize(int position) {
        BaseBrick brick = brickDataManager.getRecyclerViewItems().get(position);

        return brick != null ? brick.getSpanSize().getSpans(context) : 1;
    }
}

@@ -887,24 +887,42 @@
 position) %7B%0A
+        try %7B%0A    
         Base
@@ -999,16 +999,20 @@
         
+  
+  
 return b
@@ -1069,16 +1069,151 @@
 t) : 1;%0A
+        %7D catch (IndexOutOfBoundsException e) %7B%0A            // Appears to be a bug in the support lib.%0A            return 1;%0A        %7D%0A
     %7D%0A%7D%0A

Fix for getSpanSize() support lib bug (#46)