|
|
@@ -2,6 +2,7 @@ package kr.co.zumo.app.lifeplus.view.custom.category.banner;
|
|
|
|
|
|
import android.content.Context;
|
|
|
import android.support.annotation.ColorRes;
|
|
|
+import android.support.annotation.DrawableRes;
|
|
|
import android.support.constraint.ConstraintLayout;
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
@@ -34,6 +35,21 @@ public class MainBannerView extends ConstraintLayout {
|
|
|
private RecyclerView recyclerView;
|
|
|
private CustomIndicator customIndicator;
|
|
|
private View view;
|
|
|
+ private Context context;
|
|
|
+ private List<? extends IImageTitleBean> textImageBeanList;
|
|
|
+ private IEventListener listener;
|
|
|
+
|
|
|
+ @ColorRes
|
|
|
+ private int activeColor;
|
|
|
+
|
|
|
+ @ColorRes
|
|
|
+ private int inactiveColor;
|
|
|
+
|
|
|
+ private boolean isDim;
|
|
|
+
|
|
|
+ @DrawableRes
|
|
|
+ private int placeholder;
|
|
|
+
|
|
|
|
|
|
public MainBannerView(Context context) {
|
|
|
super(context);
|
|
|
@@ -47,9 +63,16 @@ public class MainBannerView extends ConstraintLayout {
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
}
|
|
|
|
|
|
- public void init(Context context, List<? extends IImageTitleBean> textImageBeanList,
|
|
|
- IEventListener listener, boolean isDimLayerEnabled,
|
|
|
- @ColorRes int activeColor, @ColorRes int inActiveColor) {
|
|
|
+ private void init(Builder builder) {
|
|
|
+
|
|
|
+ this.context = builder.context;
|
|
|
+ this.textImageBeanList = builder.textImageBeanList;
|
|
|
+ this.listener = builder.listener;
|
|
|
+ this.activeColor = builder.activeColor;
|
|
|
+ this.inactiveColor = builder.inactiveColor;
|
|
|
+ this.isDim = builder.isDim;
|
|
|
+ this.placeholder = builder.placeholder;
|
|
|
+
|
|
|
|
|
|
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
|
view = inflater.inflate(R.layout.main_banner_view, this);
|
|
|
@@ -67,7 +90,7 @@ public class MainBannerView extends ConstraintLayout {
|
|
|
}
|
|
|
};
|
|
|
recyclerView.setLayoutManager(layoutManager);
|
|
|
- customIndicator.setIndicator(recyclerView, activeColor, inActiveColor, event -> {
|
|
|
+ customIndicator.setIndicator(recyclerView, activeColor, inactiveColor, event -> {
|
|
|
recyclerView.smoothScrollToPosition(event.getIndex());
|
|
|
});
|
|
|
|
|
|
@@ -82,7 +105,7 @@ public class MainBannerView extends ConstraintLayout {
|
|
|
if (null != listener) {
|
|
|
listener.onEvent(event);
|
|
|
}
|
|
|
- }, isDimLayerEnabled);
|
|
|
+ }, isDim, placeholder);
|
|
|
|
|
|
recyclerView.setOnFlingListener(null);
|
|
|
snapHelper.attachToRecyclerView(recyclerView);
|
|
|
@@ -97,4 +120,54 @@ public class MainBannerView extends ConstraintLayout {
|
|
|
this.removeAllViews();
|
|
|
customIndicator = null;
|
|
|
}
|
|
|
+
|
|
|
+ public static class Builder {
|
|
|
+
|
|
|
+ private Context context;
|
|
|
+ private List<? extends IImageTitleBean> textImageBeanList;
|
|
|
+ private IEventListener listener;
|
|
|
+
|
|
|
+ @ColorRes
|
|
|
+ private int activeColor = R.color.CFFFFFF;
|
|
|
+
|
|
|
+ @ColorRes
|
|
|
+ private int inactiveColor = R.color.C4DFFFFFF;
|
|
|
+
|
|
|
+ private boolean isDim = true;
|
|
|
+
|
|
|
+ @DrawableRes
|
|
|
+ private int placeholder = R.drawable.image_loading_banner;
|
|
|
+
|
|
|
+ public Builder(Context context, List<? extends IImageTitleBean> textImageBeanList,
|
|
|
+ IEventListener listener) {
|
|
|
+ this.context = context;
|
|
|
+ this.textImageBeanList = textImageBeanList;
|
|
|
+ this.listener = listener;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Builder activeColor(@ColorRes int activeColor) {
|
|
|
+ this.activeColor = activeColor;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Builder inactiveColor(@ColorRes int inactiveColor) {
|
|
|
+ this.inactiveColor = inactiveColor;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Builder isDim(boolean isDim) {
|
|
|
+ this.isDim = isDim;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Builder placeholder(@DrawableRes int placeholder) {
|
|
|
+ this.placeholder = placeholder;
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Builder build(MainBannerView bannerView) {
|
|
|
+ bannerView.init(this);
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|