Skip to content

Commit

Permalink
Updated README for v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Sira Lam committed Jan 4, 2018
1 parent fe1081f commit 7866014
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ A ViewPager and a PagerAdapter that can:
5. Won't scroll nor loop if there is only 1 item
6. Works well with notifyDataSetChanged()
7. Supports page indicators
8. Supports different view types

## Demo Effect

Expand Down Expand Up @@ -50,7 +51,7 @@ allprojects {
And then add the below to your app's build.gradle:

```groovy
implementation 'com.asksira.android:loopingviewpager:1.0.5'
implementation 'com.asksira.android:loopingviewpager:1.1.0'
```

### Step 1: Create LoopingViewPager in XML
Expand Down Expand Up @@ -98,7 +99,7 @@ public class DemoInfiniteAdapter extends LoopingPagerAdapter<Integer> {

//This method will be triggered if the item View has not been inflated before.
@Override
protected View inflateView() {
protected View inflateView(int viewType, int listPosition) {
return LayoutInflater.from(context).inflate(R.layout.item_pager, null);
}

Expand All @@ -107,7 +108,7 @@ public class DemoInfiniteAdapter extends LoopingPagerAdapter<Integer> {
//You can assume convertView will not be null here.
//You may also consider using a ViewHolder pattern.
@Override
protected void bindView(View convertView, int listPosition) {
protected void bindView(View convertView, int listPosition, int viewType) {
convertView.findViewById(R.id.image).setBackgroundColor(context.getResources().getColor(getBackgroundColor(listPosition)));
TextView description = convertView.findViewById(R.id.description);
description.setText(String.valueOf(itemList.get(listPosition)));
Expand Down Expand Up @@ -147,6 +148,21 @@ adapter.setItemList(newItemList);
viewPager.reset(); //In order to reset the current page position
```

## How do I implement different View types?

Simple! Override one more method in your Adapter:

```java
@Override
protected int getItemViewType(int listPosition) {
//Return your own view type, same as what you did when using RecyclerView
}
```

And then, of course, according to the `viewtype` parameter passed to you in `inflateView()` and `bindView()`, differentiate what you need to inflate or bind.

You may also refer to the demo app for a complete example.

## How do I integrate a Page Indicator?

I don't provide a built-in page indicator because:
Expand Down Expand Up @@ -240,6 +256,9 @@ if you cannot accept these minor defects, I suggest you use `onIndicatorPageChan

## Release notes

v1.1.0
- Added support for view type. But therefore changed parameters needed in `inflateView()` and `bindView()`.

v1.0.5
- Added asepct ratio attribute for `LoopingViewPager`
- Rewrote the way of caching Views in `LoopingPagerAdapter`, and therefore separated inflation and data binding
Expand Down

0 comments on commit 7866014

Please sign in to comment.