|
|
@@ -33,51 +33,40 @@ import java.util.List;
|
|
|
* Description: 首页商品适配器
|
|
|
*/
|
|
|
public class TemplateAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
|
|
|
- private int mRadius = 8;
|
|
|
private Context mContext;
|
|
|
+ private int mDividerSize;
|
|
|
|
|
|
- private int screenWidth;
|
|
|
- private int mDividerWidth;
|
|
|
- private int defaultSize;
|
|
|
-
|
|
|
- public TemplateAdapter(Context context, @Nullable List<String> data, int dividerWidth) {
|
|
|
+ public TemplateAdapter(Context context, @Nullable List<String> data, int dividerSize) {
|
|
|
super(R.layout.item_template, data);
|
|
|
- mRadius = (int) context.getResources().getDimension(R.dimen.margin_s);
|
|
|
mContext = context;
|
|
|
- this.screenWidth = SizeTool.SCREEN_WIDTH;
|
|
|
- this.mDividerWidth = dividerWidth;
|
|
|
- this.defaultSize = (screenWidth - dividerWidth * TemplateFragment.SPACE_LINES) / TemplateFragment.SPAN_COUNT;
|
|
|
+ mDividerSize = dividerSize;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
protected void convert(@NonNull BaseViewHolder holder, String url) {
|
|
|
ImageView iv_template = holder.getView(R.id.iv_template);
|
|
|
|
|
|
-
|
|
|
- String realUrl = url.startsWith("http") ? url : BuildConfig.HOST_STATIC_RESOURCE +url;
|
|
|
-
|
|
|
+ String realUrl = url.startsWith("http") ? url : BuildConfig.HOST_STATIC_RESOURCE + url;
|
|
|
// 设置默认图片
|
|
|
setDefaultView(iv_template);
|
|
|
// 解决图片错乱
|
|
|
iv_template.setTag(R.id.aciv_goods, realUrl);
|
|
|
Glide.with(mContext).load(realUrl)
|
|
|
- //.transform(new CenterCrop(), new RoundedCorners(48))
|
|
|
- //.apply(RequestOptions.bitmapTransform(new RoundedCorners(mRadius)))
|
|
|
- //.apply(new RequestOptions()
|
|
|
- // .skipMemoryCache(true)
|
|
|
- // .diskCacheStrategy(DiskCacheStrategy.NONE))
|
|
|
- //.centerCrop() 千万不要加,加了就没有圆角效果了
|
|
|
- //先加载原图大小的十分之一
|
|
|
.thumbnail(0.1f)
|
|
|
.into(new SimpleTarget<Drawable>() {
|
|
|
@Override
|
|
|
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
|
|
|
- //iv_template.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
|
|
- //iv_template.setImageDrawable(resource);
|
|
|
if (resource == null) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+ int imageWidth = resource.getIntrinsicWidth();
|
|
|
+ int imageHeight = resource.getIntrinsicHeight();
|
|
|
+ // 减去间距
|
|
|
+ int height = (SizeTool.SCREEN_WIDTH - mDividerSize * TemplateFragment.SPACE_LINES) / TemplateFragment.SPAN_COUNT * imageHeight / imageWidth;
|
|
|
+ ViewGroup.LayoutParams para = iv_template.getLayoutParams();
|
|
|
+ para.height = height;
|
|
|
+
|
|
|
String coverUrl = null;
|
|
|
try {
|
|
|
coverUrl = (String) iv_template.getTag(R.id.aciv_goods);
|
|
|
@@ -85,14 +74,6 @@ public class TemplateAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
if (!TextUtils.isEmpty(coverUrl) && TextUtils.equals(coverUrl, realUrl)) {
|
|
|
- int imageWidth = resource.getIntrinsicWidth();
|
|
|
- int imageHeight = resource.getIntrinsicHeight();
|
|
|
- // 减去间距
|
|
|
- int height = (screenWidth - mDividerWidth * TemplateFragment.SPACE_LINES) / TemplateFragment.SPAN_COUNT * imageHeight / imageWidth;
|
|
|
- ViewGroup.LayoutParams para = iv_template.getLayoutParams();
|
|
|
- para.height = height;
|
|
|
- para.width = (screenWidth - mDividerWidth * TemplateFragment.SPACE_LINES) / TemplateFragment.SPAN_COUNT;
|
|
|
- iv_template.setScaleType(ImageView.ScaleType.FIT_XY);
|
|
|
iv_template.setImageDrawable(resource);
|
|
|
}
|
|
|
|
|
|
@@ -116,14 +97,11 @@ public class TemplateAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
|
|
|
}
|
|
|
|
|
|
private void setDefaultView(ImageView iv_template) {
|
|
|
- ViewGroup.LayoutParams para = iv_template.getLayoutParams();
|
|
|
- para.height = defaultSize;
|
|
|
- para.width = defaultSize;
|
|
|
- iv_template.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
|
|
iv_template.setImageResource(R.mipmap.logo_gray);
|
|
|
}
|
|
|
|
|
|
private ItemLongClickListener couponLongClickListener;
|
|
|
+
|
|
|
public ItemLongClickListener getCouponLongClickListener() {
|
|
|
return couponLongClickListener;
|
|
|
}
|