Skip to content

Commit

Permalink
Updated README for v1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Sira Lam committed Jan 4, 2018
1 parent 0eabede commit 2f501fd
Showing 1 changed file with 34 additions and 23 deletions.
57 changes: 34 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ A ViewPager and a PagerAdapter that can:

1. AutoScroll (On/Off able)
2. Infinite Loop (On/Off able)
3. ViewPager's height can be wrap_content
3. ViewPager's height can be wrap_content / an aspect ratio
4. Adjustable auto scroll interval
5. Won't scroll nor loop if there is only 1 item
6. Works well with notifyDataSetChanged()
Expand All @@ -27,7 +27,7 @@ I cannot find one that fits all of the below requirements:
2. Last updated in less than 3 years
3. Good infinite looping effect
4. Configurable auto-scroll
5. ViewPager that supports wrap_content (or at least aspect ratio)
5. ViewPager that supports fixed aspect ratio (Or wrap_content)
6. Good support with Page Indicators

Especially for 6, even some of them supports, they provide built-in indicators only; or does not tell user how to implement their own indicator.
Expand All @@ -50,7 +50,7 @@ allprojects {
And then add the below to your app's build.gradle:

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

### Step 1: Create LoopingViewPager in XML
Expand All @@ -63,15 +63,22 @@ And then add the below to your app's build.gradle:
app:isInfinite="true"
app:autoScroll="true"
app:scrollInterval="5000"
app:wrap_content="true"/>
app:viewpagerAspectRatio="1.33"/>
```

| Attribute Name | Default | Allowed Values |
|:-----------------|:--------|:------------------------------|
| isInfinite | false | true / false |
| autoScroll | false | true / false |
| wrap_content | true | true / false |
| scrollInterval | 5000 | any integer (represents ms) |
| Attribute Name | Default | Allowed Values |
|:------------------------|:--------|:------------------------------|
| isInfinite | false | true / false |
| autoScroll | false | true / false |
| viewpagerAspectRatio | 0 | any float (width / height) |
| wrap_content | true | true / false |
| scrollInterval | 5000 | any integer (represents ms) |

viewpagerAspectRatio 0 means does not apply aspectRatio.
That means, default LoopingViewPager has no aspect ratio and wrap_content is true.
Once aspect ratio is set, wrap_content will be overrided (meaningless).

In most cases, you should set an aspect ratio.

If you wonder why you need to set `app:wrap_content="true"`, take a look at [this Stackoverflow post](https://stackoverflow.com/questions/8394681/android-i-am-unable-to-have-viewpager-wrap-content).

Expand All @@ -80,7 +87,7 @@ If you wonder why you need to set `app:wrap_content="true"`, take a look at [thi
You should
1. Specify the data type in the generic (`<DataType>`)
2. Create your own constructor according to this `DataType`
3. override `getItemView`
3. override `inflateView()` and `bindView()`

```java
public class DemoInfiniteAdapter extends LoopingPagerAdapter<Integer> {
Expand All @@ -89,22 +96,21 @@ public class DemoInfiniteAdapter extends LoopingPagerAdapter<Integer> {
super(context, itemList, isInfinite);
}

//You should return the View (With data binded) to display in this method.
//This method will be triggered if the item View has not been inflated before.
@Override
protected View getItemView(View convertView, int listPosition, ViewPager container) {
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.item_pager, null);
container.addView(convertView);
}

//Bind your view elements with data in itemList here.
//You can also consider using a ViewHolder pattern.
//Below is just an example in the demo app.
protected View inflateView() {
return LayoutInflater.from(context).inflate(R.layout.item_pager, null);
}

//Bind your data with your item View here.
//Below is just an example in the demo app.
//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) {
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)));

return convertView;
}
}
```
Expand Down Expand Up @@ -234,6 +240,11 @@ if you cannot accept these minor defects, I suggest you use `onIndicatorPageChan

## Release notes

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

v1.0.4
- Indicator now works with page skipping as well (By calling `selectCurrentItem()`)
- Leviated indicator fluctuating phenomenon when using `onIndicatorProgress()` callback
Expand Down

0 comments on commit 2f501fd

Please sign in to comment.