diff --git a/app/build.gradle b/app/build.gradle index e86f632..af54f52 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -27,8 +27,8 @@ dependencies { compile 'com.android.support:appcompat-v7:25.3.1' compile 'com.android.support.constraint:constraint-layout:1.0.2' testCompile 'junit:junit:4.12' - //compile project(':mzbanner') - compile 'com.github.pinguo-zhouwei:MZBannerView:v1.1.1' + compile project(':mzbanner') + //compile 'com.github.pinguo-zhouwei:MZBannerView:v1.1.1' compile 'com.squareup.retrofit2:retrofit:2.1.0' compile 'com.google.code.gson:gson:2.6.2' diff --git a/app/src/main/java/com/zhouwei/mzbannerview/remote/RemoteTestFragment.java b/app/src/main/java/com/zhouwei/mzbannerview/remote/RemoteTestFragment.java index 83bc65c..bfeceb4 100644 --- a/app/src/main/java/com/zhouwei/mzbannerview/remote/RemoteTestFragment.java +++ b/app/src/main/java/com/zhouwei/mzbannerview/remote/RemoteTestFragment.java @@ -10,6 +10,7 @@ import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.TextView; import com.squareup.picasso.Picasso; import com.zhouwei.mzbanner.MZBannerView; @@ -18,6 +19,7 @@ import com.zhouwei.mzbannerview.R; import com.zhouwei.mzbannerview.http.Fault; +import java.util.ArrayList; import java.util.List; import rx.functions.Action1; @@ -26,9 +28,11 @@ * Created by zhouwei on 17/6/8. */ -public class RemoteTestFragment extends Fragment { +public class RemoteTestFragment extends Fragment implements View.OnClickListener{ private MovieLoader mMovieLoader; private MZBannerView mMZBannerView; + private TextView mBtnChange; + private List mMovies; private Handler mHandler = new Handler(); public static RemoteTestFragment newInstance(){ RemoteTestFragment fragment = new RemoteTestFragment(); @@ -40,6 +44,8 @@ public static RemoteTestFragment newInstance(){ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.remote_test_layout,null); mMZBannerView = (MZBannerView) view.findViewById(R.id.my_banner); + mBtnChange = (TextView) view.findViewById(R.id.btn_change); + mBtnChange.setOnClickListener(this); mMovieLoader = new MovieLoader(); getMovieList(); return view; @@ -53,6 +59,7 @@ private void getMovieList(){ mMovieLoader.getMovie(0,10).subscribe(new Action1>() { @Override public void call(List movies) { + mMovies = movies; Log.e("zhouwei","get data suceess"); setBanner(movies); } @@ -94,6 +101,16 @@ public void onDestroy() { mMZBannerView.pause(); } + @Override + public void onClick(View v) { + if(v.getId() == R.id.btn_change){ + List movies = new ArrayList(mMovies); + movies.add(mMovies.get(0)); + movies.add(mMovies.get(1)); + setBanner(movies); + } + } + public static class BannerViewHolder implements MZViewHolder{ private ImageView mImageView; @Override diff --git a/app/src/main/res/layout/remote_test_layout.xml b/app/src/main/res/layout/remote_test_layout.xml index 2f3189c..ce8a2b2 100644 --- a/app/src/main/res/layout/remote_test_layout.xml +++ b/app/src/main/res/layout/remote_test_layout.xml @@ -4,6 +4,7 @@ android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> + + + \ No newline at end of file diff --git a/mzbanner/src/main/java/com/zhouwei/mzbanner/MZBannerView.java b/mzbanner/src/main/java/com/zhouwei/mzbanner/MZBannerView.java index 5125a27..b731f77 100644 --- a/mzbanner/src/main/java/com/zhouwei/mzbanner/MZBannerView.java +++ b/mzbanner/src/main/java/com/zhouwei/mzbanner/MZBannerView.java @@ -337,6 +337,8 @@ public void setPages(List datas,MZHolderCreator mzHolderCreator){ return; } mDatas = datas; + //如果在播放,就先让播放停止 + pause(); //增加一个逻辑:由于魅族模式会在一个页面展示前后页面的部分,因此,数据集合的长度至少为3,否则,自动为普通Banner模式 //不管配置的:open_mz_mode 属性的值是否为true @@ -350,10 +352,16 @@ public void setPages(List datas,MZHolderCreator mzHolderCreator){ mViewPager.setClipChildren(true); } setOpenMZEffect(); + // 2017.7.20 fix:将Indicator初始化放在Adapter的初始化之前,解决更新数据变化更新时crush. + //初始化Indicator + initIndicator(); mAdapter = new MZPagerAdapter(datas,mzHolderCreator,mIsCanLoop); mAdapter.setUpViewViewPager(mViewPager); mAdapter.setPageClickListener(mBannerPageClickListener); + + + mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { @@ -392,8 +400,7 @@ public void onPageScrollStateChanged(int state) { if(mOnPageChangeListener!=null){ mViewPager.addOnPageChangeListener(mOnPageChangeListener); } - //初始化Indicator - initIndicator(); + } /**