Skip to content

Commit

Permalink
Update REDMINE.md,update sample.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhpanvip committed Oct 4, 2020
1 parent de74889 commit f6d4e9a
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 17 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[![License](https://img.shields.io/github/license/zhpanvip/BannerViewPager)](https://github.com/zhpanvip/BannerViewPager/blob/master/LICENSE)
![MinSdk](https://img.shields.io/badge/API-16%2B-brightgreen.svg?style=flat)
[![JitPack](https://jitpack.io/v/zhpanvip/BannerViewPager.svg)](https://jitpack.io/#zhpanvip/BannerViewPager)
[![JCenter](https://api.bintray.com/packages/zhpanvip/CircleViewPager/bannerview/images/download.svg) ](https://bintray.com/zhpanvip/CircleViewPager/bannerview/_latestVersion)
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-BannerViewPager-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/7961)
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-ViewPagerIndicator-brightgreen.svg?style=flat)](https://github.com/zhpanvip/viewpagerindicator)
[![Stars](https://img.shields.io/github/stars/zhpanvip/BannerViewPager)](https://github.com/zhpanvip/BannerViewPager/stargazers)
Expand All @@ -30,6 +29,10 @@
- SCALE slide mode and COLOR slide mode supported(V3.1.0)
- refreshData() supported (V3.1.0)
- setLifecycleRegistry(Lifecycle) supported (v3.1.4)
- addData(List<T>) Supported (3.2.0)
- insertItem and removeItem Supported. (3.2.0)
- addItemDecoration Supported. (3.2.0)

## Preview

### [Click here or scan the QR code to download demo apk](https://www.pgyer.com/bannerviewpager)
Expand Down
9 changes: 6 additions & 3 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
[![License](https://img.shields.io/github/license/zhpanvip/BannerViewPager)](https://github.com/zhpanvip/BannerViewPager/blob/master/LICENSE)
![MinSdk](https://img.shields.io/badge/API-16%2B-brightgreen.svg?style=flat)
[![JitPack](https://jitpack.io/v/zhpanvip/BannerViewPager.svg)](https://jitpack.io/#zhpanvip/BannerViewPager)
[![JCenter](https://api.bintray.com/packages/zhpanvip/CircleViewPager/bannerview/images/download.svg) ](https://bintray.com/zhpanvip/CircleViewPager/bannerview/_latestVersion)
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-BannerViewPager-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/7961)
[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-ViewPagerIndicator-brightgreen.svg?style=flat)](https://github.com/zhpanvip/viewpagerindicator)
[![Stars](https://img.shields.io/github/stars/zhpanvip/BannerViewPager)](https://github.com/zhpanvip/BannerViewPager/stargazers)
Expand All @@ -30,10 +29,14 @@
- 不再支持android support.
- 新增Indicator SCALE与COLOR滑动样式(V3.1.0)
- 支持刷新通过refreshData()方法刷新数据(V3.1.0)
- 支持通过setLifecycleRegistry(Lifecycle)管理BVP生命周期(3.1.4)
- 支持addData(List<T>) (3.2.0)
- 支持insertItem and removeItem(3.2.0)
- 支持addItemDecoration(3.2.0)

## 效果预览

### [点击或扫描二维码下载apk](https://github.com/zhpanvip/BannerViewPager/raw/master/download/app.apk)
### [点击或扫描二维码下载apk](https://www.pgyer.com/bannerviewpager)

![扫描下载Demo](https://gitee.com/zhpanvip/images/raw/master/project/banner/qrcode.png)

Expand Down Expand Up @@ -136,7 +139,7 @@ BannerViewPager目前已支持三种IndicatorViewStyle,以及五种IndicatorSlid

## 如何使用

由于ViewPager2不支持Android support,因此BannerViewPager 3.0不再支持Android support,如果你仍在使用Android support请使用,请移步[BannerViewPager 2.x版本](https://github.com/zhpanvip/BannerViewPager/tree/v_2.x)
由于ViewPager2不支持Android support,因此BannerViewPager 3.0不再支持Android support,如果你仍在使用Android support,请移步[BannerViewPager 2.x版本](https://github.com/zhpanvip/BannerViewPager/tree/v_2.x)

### 1.gradle中添加依赖

Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ android {
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "3.1.0"
versionName "3.2.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.zhpan.indicator.base.IIndicator;
import com.zhpan.indicator.enums.IndicatorSlideMode;

import java.util.List;
import java.util.Random;

/**
Expand Down Expand Up @@ -68,6 +69,7 @@ protected void initView(Bundle savedInstanceState, @NonNull View view) {
mViewPager = view.findViewById(R.id.banner_view);
view.findViewById(R.id.tv_add_data).setOnClickListener(this);
view.findViewById(R.id.tv_remove_item).setOnClickListener(this);
view.findViewById(R.id.tv_insert_item).setOnClickListener(this);
mIndicatorView = view.findViewById(R.id.indicator_view);
view.findViewById(R.id.tv_photo_view).setOnClickListener(this);
mViewPager.setIndicatorSliderGap(BannerUtils.dp2px(6))
Expand Down Expand Up @@ -170,11 +172,6 @@ private void updateData() {
ToastUtils.show("size=" + mViewPager.getData().size());
}

private void addData() {
mViewPager.addData(getPicList(0));
ToastUtils.show("size=" + mViewPager.getData().size());
}

@Override
public void onClick(View view) {
switch (view.getId()) {
Expand All @@ -184,6 +181,9 @@ public void onClick(View view) {
case R.id.tv_remove_item:
removeItem();
break;
case R.id.tv_insert_item:
insertItem();
break;
default:
int position = new Random().nextInt(5);
mViewPager.setCurrentItem(position, true);
Expand All @@ -192,7 +192,17 @@ public void onClick(View view) {
}
}

private void addData() {
mViewPager.addData(getPicList(2));
ToastUtils.show("size=" + mViewPager.getData().size());
}

private void insertItem() {
Integer item = getPicList(0).get(0);
mViewPager.insertItem(mViewPager.getData().size(), item);
}

private void removeItem() {
mViewPager.removeItem(0);
mViewPager.removeItem(mViewPager.getData().size() - 1);
}
}
15 changes: 13 additions & 2 deletions app/src/main/res/layout/fragment_others.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,17 +114,28 @@
android:textSize="@dimen/sp_16" />

<TextView
android:id="@+id/tv_remove_item"
android:id="@+id/tv_insert_item"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_45"
android:layout_below="@id/tv_add_data"
android:layout_marginTop="@dimen/dp_10"
android:background="@color/white"
android:gravity="center"
android:text="@string/remove_item"
android:text="@string/insert_item"
android:textColor="#000000"
android:textSize="@dimen/sp_16" />

<TextView
android:id="@+id/tv_remove_item"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_45"
android:layout_below="@id/tv_insert_item"
android:layout_marginTop="@dimen/dp_10"
android:background="@color/white"
android:gravity="center"
android:text="@string/remove_item"
android:textColor="#000000"
android:textSize="@dimen/sp_16" />
</RelativeLayout>
</androidx.core.widget.NestedScrollView>
</com.scwang.smartrefresh.layout.SmartRefreshLayout>
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
<string name="indicator_name">ViewPagerIndicator</string>
<string name="email">[email protected]</string>
<string name="add_data">Add Data</string>
<string name="remove_item">Remove first Item</string>
<string name="remove_item">Remove Item</string>
<string name="insert_item">Insert Item</string>
</resources>
17 changes: 14 additions & 3 deletions bannerview/src/main/java/com/zhpan/bannerview/BannerViewPager.java
Original file line number Diff line number Diff line change
Expand Up @@ -829,19 +829,30 @@ public void addData(List<? extends T> list) {
}
}

/**
* Removes the item at the specified position in this list.
*
* @param index the index of the item to be removed
*/
public void removeItem(int index) {
List<T> data = mBannerPagerAdapter.getData();
if (data.size() > index) {
if (index >= 0 && index < data.size()) {
data.remove(index);
mBannerPagerAdapter.notifyDataSetChanged();
resetCurrentItem(getCurrentItem());
refreshIndicator(data);
}
}

public void insertItem(T item, int index) {
/**
* Inserts the specified element at the specified position in this list
*
* @param index index at which the specified element is to be inserted
* @param item item element to be inserted
*/
public void insertItem(int index,T item) {
List<T> data = mBannerPagerAdapter.getData();
if (data.size() > index) {
if (index >= 0 && index <= data.size()) {
data.add(index, item);
mBannerPagerAdapter.notifyDataSetChanged();
resetCurrentItem(getCurrentItem());
Expand Down

0 comments on commit f6d4e9a

Please sign in to comment.