package ca.antonious.viewcelladapter.extensions;

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

import ca.antonious.viewcelladapter.ViewCellAdapter;

/**
 * Created by George on 2017-05-14.
 */

public class ViewCellGridLayoutManager extends GridLayoutManager {
    private ViewCellAdapter viewCellAdapter;

    public ViewCellGridLayoutManager(Context context, ViewCellAdapter viewCellAdapter, int spanCount, int orientation, boolean reverseLayout) {
        super(context, spanCount, orientation, reverseLayout);
        this.viewCellAdapter = viewCellAdapter;
        init();
    }

    public static ViewCellGridLayoutManager create(Context context, ViewCellAdapter viewCellAdapter, int spanCount) {
        return new ViewCellGridLayoutManager(context, viewCellAdapter, spanCount, VERTICAL, false);
    }

    private void init() {
        setSpanSizeLookup(new SpanSizeLookup() {
            @Override
            public int getSpanSize(int position) {
                return getSpanFor(position);
            }
        });
    }

    private int getSpanFor(int position) {
        return Math.max(1, getSpanCount() - (viewCellAdapter.get(position).getTotalPerLine() - 1));
    }
}

@@ -603,20 +603,31 @@
         
-init
+setupSpanLookup
 ();%0A    
@@ -762,20 +762,16 @@
  return 
-new 
 ViewCell
@@ -787,16 +787,23 @@
 tManager
+.create
 (context
@@ -840,16 +840,254 @@
 VERTICAL
+);%0A    %7D%0A%0A    public static ViewCellGridLayoutManager create(Context context, ViewCellAdapter viewCellAdapter, int spanCount, int orientation) %7B%0A        return new ViewCellGridLayoutManager(context, viewCellAdapter, spanCount, orientation
 , false)
@@ -1116,12 +1116,23 @@
 oid 
-init
+setupSpanLookup
 () %7B

Clean up ViewCellGridLayoutManager