Skip to content

Commit

Permalink
1.优化BaseAdapter
Browse files Browse the repository at this point in the history
2.更新到0.5.0版本
  • Loading branch information
caikaidev committed Oct 23, 2016
1 parent 42a9dfd commit 6766cec
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
8 changes: 8 additions & 0 deletions app/src/main/java/com/kcode/autoviewpager/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.Toast;

import com.kcode.autoscrollviewpager.view.AutoScrollViewPager;
Expand Down Expand Up @@ -33,6 +34,13 @@ protected void onCreate(Bundle savedInstanceState) {
mViewPager = autoScrollViewPager.getViewPager();
mAdapter = new PictureViewPagerAdapter(getApplicationContext(),initData(),mViewPager, listener);

new BaseViewPagerAdapter<Picture>(getApplicationContext(),initData(),mViewPager, listener){

@Override
public void loadImage(ImageView view, int position, Picture picture) {

}
};
}

private List<Picture> initData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ private void init(Context context){
addView(mViewPager);
}

public void setAdapter(BaseViewPagerAdapter adapter){
if (mViewPager != null) {
mViewPager.init(mViewPager,adapter);
}
}

public AutoViewPager getViewPager() {
return mViewPager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public AutoViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}

public void init(AutoViewPager viewPager,BaseViewPagerAdapter adapter){
adapter.init(viewPager,adapter);
}

public void start(){
if (mTimer == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,30 @@ public BaseViewPagerAdapter(List<T> t) {
this.data = t;
}

public BaseViewPagerAdapter(Context context, AutoViewPager viewPager) {
public BaseViewPagerAdapter(Context context) {
this.mContext = context;
mView = viewPager;
mView.setAdapter(this);
mView.addOnPageChangeListener(this);
mView.setCurrentItem(0);
}


public BaseViewPagerAdapter(Context context, AutoViewPager viewPager,OnAutoViewPagerItemClickListener listener) {
public BaseViewPagerAdapter(Context context, OnAutoViewPagerItemClickListener listener) {
this.mContext = context;
mView = viewPager;
this.listener = listener;
mView.setAdapter(this);
mView.addOnPageChangeListener(this);
mView.setCurrentItem(0);
}

public BaseViewPagerAdapter(Context context, List<T> data,AutoViewPager viewPager,OnAutoViewPagerItemClickListener listener) {
public BaseViewPagerAdapter(Context context, List<T> data,OnAutoViewPagerItemClickListener listener) {
this.mContext = context;
mView = viewPager;
this.data = data;
this.listener = listener;
}

public void init(AutoViewPager viewPager,BaseViewPagerAdapter adapter){
mView = viewPager;
mView.setAdapter(this);
mView.addOnPageChangeListener(this);

if (data == null || data.size() == 0){
return;
}
mView.setCurrentItem(0);

mView.start();
Expand Down

0 comments on commit 6766cec

Please sign in to comment.