diff --git a/README.md b/README.md index 3315666..5035fd3 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Add OkAdapter dependency to project level build.gradle. ```gradle dependencies { - compile 'com.github.FuckBoilerplate:OkAdapters:0.0.7' + compile 'com.github.FuckBoilerplate:OkAdapters:0.0.8' } ``` diff --git a/app/src/main/java/app/recycler_view/RecyclerViewPagerActivity.java b/app/src/main/java/app/recycler_view/RecyclerViewPagerActivity.java index b5d699c..74e6431 100644 --- a/app/src/main/java/app/recycler_view/RecyclerViewPagerActivity.java +++ b/app/src/main/java/app/recycler_view/RecyclerViewPagerActivity.java @@ -2,7 +2,7 @@ import android.os.Bundle; import android.support.v7.app.AppCompatActivity; -import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.View; import android.view.ViewGroup; @@ -36,11 +36,6 @@ public class RecyclerViewPagerActivity extends AppCompatActivity { } private void setUpRecyclerView(boolean reverseLayout) { - LinearLayoutManager layoutManager = new LinearLayoutManager(this); - layoutManager.setReverseLayout(reverseLayout); - - rv_items.setLayoutManager(layoutManager); - final OkRecyclerViewAdapter adapter = new OkRecyclerViewAdapter() { @Override protected ItemViewGroup onCreateItemView(ViewGroup parent, int viewType) { return new ItemViewGroup(parent.getContext()); @@ -54,10 +49,10 @@ private void setUpRecyclerView(boolean reverseLayout) { }); adapter.setRxPager(R.layout.loading_pager, new RxPager.LoaderPager() { - @Override public Observable> onNextPage(Item lastItem) { - return getItems(lastItem); - } - }); + @Override public Observable> onNextPage(Item lastItem) { + return getItems(lastItem); + } + }); findViewById(R.id.bt_reset).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -79,12 +74,17 @@ private void setUpRecyclerView(boolean reverseLayout) { } }); + GridLayoutManager layoutManager = new GridLayoutManager(this, 2); + layoutManager.setReverseLayout(reverseLayout); + adapter.configureGridLayoutManagerForPagination(layoutManager); + + rv_items.setLayoutManager(layoutManager); rv_items.setAdapter(adapter); } private Observable> getItems(Item lastItem) { int index = lastItem != null ? lastItem.getId() + 1 : 0; - int max = index + 30; + int max = index + 31; List items = new ArrayList(); diff --git a/ok_adapters/src/main/java/library/recycler_view/OkRecyclerViewAdapter.java b/ok_adapters/src/main/java/library/recycler_view/OkRecyclerViewAdapter.java index e2ed8b0..7a6029a 100644 --- a/ok_adapters/src/main/java/library/recycler_view/OkRecyclerViewAdapter.java +++ b/ok_adapters/src/main/java/library/recycler_view/OkRecyclerViewAdapter.java @@ -17,6 +17,7 @@ package library.recycler_view; import android.support.annotation.LayoutRes; +import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; @@ -145,4 +146,16 @@ public void resetPager(Observable> oItems) { public interface LastItemListener { void lastItemReached(); } + + public void configureGridLayoutManagerForPagination(final GridLayoutManager gridLayoutManager) { + gridLayoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() { + @Override public int getSpanSize(int position) { + if (position == getItemCount() - 1) { + return gridLayoutManager.getSpanCount(); + } else { + return 1; + } + } + }); + } }