Skip to content

Commit

Permalink
added configureGridLayoutManagerForPagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor committed May 13, 2016
1 parent 638fa83 commit 82f5eab
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
```

Expand Down
22 changes: 11 additions & 11 deletions app/src/main/java/app/recycler_view/RecyclerViewPagerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Item, ItemViewGroup> adapter = new OkRecyclerViewAdapter<Item, ItemViewGroup>() {
@Override protected ItemViewGroup onCreateItemView(ViewGroup parent, int viewType) {
return new ItemViewGroup(parent.getContext());
Expand All @@ -54,10 +49,10 @@ private void setUpRecyclerView(boolean reverseLayout) {
});

adapter.setRxPager(R.layout.loading_pager, new RxPager.LoaderPager<Item>() {
@Override public Observable<List<Item>> onNextPage(Item lastItem) {
return getItems(lastItem);
}
});
@Override public Observable<List<Item>> onNextPage(Item lastItem) {
return getItems(lastItem);
}
});

findViewById(R.id.bt_reset).setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
Expand All @@ -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<List<Item>> getItems(Item lastItem) {
int index = lastItem != null ? lastItem.getId() + 1 : 0;
int max = index + 30;
int max = index + 31;

List<Item> items = new ArrayList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -145,4 +146,16 @@ public void resetPager(Observable<List<T>> 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;
}
}
});
}
}

0 comments on commit 82f5eab

Please sign in to comment.