Skip to content

Commit

Permalink
v1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
loonggg committed Feb 17, 2017
1 parent 5a2593f commit 17de25b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 2 additions & 9 deletions app/src/main/java/com/loonggg/rvbanner/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerViewBanner = (RecyclerViewBanner) findViewById(R.id.rv_banner);
final List<RecyclerViewBanner.RvBanner> banners = new ArrayList<>();
final List<Banner> banners = new ArrayList<>();
for (int i = 0; i < 2; i++) {
banners.add(new Banner("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1487221110004&di=d6043e4b0c90ddf3ea5096c3d8eb8f58&imgtype=0&src=http%3A%2F%2Fimage.tianjimedia.com%2FuploadImages%2F2014%2F067%2F5116EPAUD762_1000x500.jpg"));
banners.add(new Banner("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1487221129421&di=c085432cf7c15836f8a6479138740f39&imgtype=0&src=http%3A%2F%2Fimage85.360doc.com%2FDownloadImg%2F2015%2F05%2F0517%2F53199602_2.jpg"));
Expand All @@ -33,23 +33,16 @@ public void switchBanner(int position, ImageView bannerView) {
Glide.with(bannerView.getContext()).load(banners.get(position % banners.size()).getUrl()).placeholder(R.mipmap.ic_launcher).into(bannerView);
}
});
recyclerViewBanner.setOnRvBannerClickListener(new RecyclerViewBanner.OnRvBannerClickListener() {
@Override
public void onClick(RecyclerViewBanner.RvBanner banner) {
Toast.makeText(MainActivity.this, banner.getUrl(), Toast.LENGTH_LONG).show();
}
});
}

private class Banner implements RecyclerViewBanner.RvBanner {
private class Banner {

String url;

public Banner(String url) {
this.url = url;
}

@Override
public String getUrl() {
return url;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class RecyclerViewBanner extends FrameLayout {
private ReyclerAdapter adapter;
private OnRvBannerClickListener onRvBannerClickListener;
private OnSwitchRvBannerListener onSwitchRvBannerListener;
private List<RvBanner> datas = new ArrayList<>();
private List datas = new ArrayList<>();

private int size, startX, startY, currentIndex;
private boolean isPlaying;
Expand Down Expand Up @@ -148,7 +148,7 @@ public synchronized void setPlaying(boolean playing) {
*
* @param datas
*/
public void setRvBannerDatas(List<RvBanner> datas) {
public void setRvBannerDatas(List datas) {
setPlaying(false);
this.datas.clear();
linearLayout.removeAllViews();
Expand Down Expand Up @@ -242,7 +242,7 @@ public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType
@Override
public void onClick(View v) {
if (onRvBannerClickListener != null) {
onRvBannerClickListener.onClick(datas.get(currentIndex % datas.size()));
onRvBannerClickListener.onClick(currentIndex % datas.size());
}
}
});
Expand Down Expand Up @@ -299,15 +299,12 @@ public void setOnSwitchRvBannerListener(OnSwitchRvBannerListener listener) {
}

public interface OnRvBannerClickListener {
void onClick(RvBanner banner);
void onClick(int position);
}

public void setOnRvBannerClickListener(OnRvBannerClickListener onRvBannerClickListener) {
this.onRvBannerClickListener = onRvBannerClickListener;
}

public interface RvBanner {
String getUrl();
}

}

0 comments on commit 17de25b

Please sign in to comment.