|
|
@@ -1,10 +1,10 @@
|
|
|
package com.itant.shibei.ui.home.coupon;
|
|
|
|
|
|
-import android.app.Activity;
|
|
|
import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
import android.text.TextUtils;
|
|
|
-import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
import android.widget.ImageView;
|
|
|
|
|
|
import androidx.annotation.NonNull;
|
|
|
@@ -15,10 +15,13 @@ import com.bumptech.glide.request.target.SimpleTarget;
|
|
|
import com.bumptech.glide.request.transition.Transition;
|
|
|
import com.chad.library.adapter.base.BaseQuickAdapter;
|
|
|
import com.chad.library.adapter.base.BaseViewHolder;
|
|
|
+import com.itant.shibei.BuildConfig;
|
|
|
import com.itant.shibei.R;
|
|
|
import com.itant.shibei.base.ItemLongClickListener;
|
|
|
import com.itant.shibei.manager.UserInfoManager;
|
|
|
-import com.miekir.common.utils.ActivityTool;
|
|
|
+import com.itant.shibei.ui.TabActivity;
|
|
|
+import com.itant.shibei.ui.home.goods.detail.MeizhiDetailActivity;
|
|
|
+import com.miekir.common.utils.SizeTool;
|
|
|
import com.miekir.common.utils.ToastTool;
|
|
|
|
|
|
import java.util.List;
|
|
|
@@ -29,93 +32,98 @@ import java.util.List;
|
|
|
* @date 2020/7/6 20:08
|
|
|
* Description: 首页商品适配器
|
|
|
*/
|
|
|
-public class TemplateAdapter extends BaseQuickAdapter<CouponBean, BaseViewHolder> {
|
|
|
+public class TemplateAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
|
|
|
private int mRadius = 8;
|
|
|
private Context mContext;
|
|
|
|
|
|
- public TemplateAdapter(Context context, @Nullable List<CouponBean> data) {
|
|
|
+ private int screenWidth;
|
|
|
+ private int mDividerWidth;
|
|
|
+ private int defaultSize;
|
|
|
+
|
|
|
+ public TemplateAdapter(Context context, @Nullable List<String> data, int dividerWidth) {
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- protected void convert(@NonNull BaseViewHolder holder, CouponBean couponBean) {
|
|
|
+ protected void convert(@NonNull BaseViewHolder holder, String url) {
|
|
|
ImageView iv_template = holder.getView(R.id.iv_template);
|
|
|
// 解决图片错乱
|
|
|
- iv_template.setTag(R.id.aciv_goods, couponBean.coverUrl);
|
|
|
- if (couponBean.isCoverUrlLocal) {
|
|
|
- int resourceId = Integer.parseInt(couponBean.coverUrl);
|
|
|
- iv_template.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
|
|
- iv_template.setImageResource(resourceId);
|
|
|
- //Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), resourceId);
|
|
|
- // 圆角
|
|
|
- //RoundedBitmapDrawable roundDrawable = RoundedBitmapDrawableFactory.create(mContext.getResources(), bitmap);
|
|
|
- //roundDrawable.setCornerRadius(48);
|
|
|
- //iv_template.setImageDrawable(roundDrawable);
|
|
|
- // 这些处理都是把drawable圆角了,如果drawable本身尺寸比较小,就起不到圆角效果
|
|
|
- } else {
|
|
|
- // 圆角
|
|
|
- Glide.with(mContext).load(couponBean.coverUrl)
|
|
|
- //.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) {
|
|
|
- iv_template.setImageResource(R.mipmap.logo_gray);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- String coverUrl = null;
|
|
|
- try {
|
|
|
- coverUrl = (String) iv_template.getTag(R.id.aciv_goods);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- if (TextUtils.isEmpty(coverUrl) || !TextUtils.equals(coverUrl, couponBean.coverUrl)) {
|
|
|
- iv_template.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
|
|
|
- iv_template.setImageResource(R.mipmap.logo_gray);
|
|
|
- } else {
|
|
|
- iv_template.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
|
|
- iv_template.setImageDrawable(resource);
|
|
|
- }
|
|
|
+ iv_template.setTag(R.id.aciv_goods, url);
|
|
|
+
|
|
|
+ String realUrl = url.startsWith("http") ? url : BuildConfig.BASE_URL+url;
|
|
|
+
|
|
|
+ // 设置默认图片
|
|
|
+ setDefaultView(iv_template);
|
|
|
+
|
|
|
+ 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) {
|
|
|
+ iv_template.setImageResource(R.mipmap.logo_gray);
|
|
|
+ return;
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
|
|
|
+ String coverUrl = null;
|
|
|
+ try {
|
|
|
+ coverUrl = (String) iv_template.getTag(R.id.aciv_goods);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ if (TextUtils.isEmpty(coverUrl) || !TextUtils.equals(coverUrl, url)) {
|
|
|
+ setDefaultView(iv_template);
|
|
|
+ } else {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
|
|
|
- holder.setText(R.id.tv_template, couponBean.couponName);
|
|
|
- holder.setOnClickListener(R.id.rl_template, new View.OnClickListener() {
|
|
|
- @Override
|
|
|
- public void onClick(View v) {
|
|
|
- if (!couponBean.actionEnable) {
|
|
|
- ToastTool.showShort("敬请期待");
|
|
|
- return;
|
|
|
- }
|
|
|
+ }
|
|
|
+ });
|
|
|
|
|
|
- ActivityTool.openUrl((Activity) mContext, couponBean.jumpUrl);
|
|
|
+ iv_template.setOnClickListener(v -> {
|
|
|
+ if (!UserInfoManager.getInstance().getBeiUser().isVip) {
|
|
|
+ ToastTool.showShort("请先激活会员");
|
|
|
+ if (mContext instanceof TabActivity) {
|
|
|
+ ((TabActivity) mContext).setCurrentPage(2);
|
|
|
+ }
|
|
|
+ return;
|
|
|
}
|
|
|
+
|
|
|
+ // 跳转查看大图界面
|
|
|
+ Intent photoIntent = new Intent(mContext, MeizhiDetailActivity.class);
|
|
|
+ photoIntent.putExtra(MeizhiDetailActivity.TAG_URL, realUrl);
|
|
|
+ mContext.startActivity(photoIntent);
|
|
|
});
|
|
|
+ }
|
|
|
|
|
|
- if (UserInfoManager.getInstance().isLogin() &&
|
|
|
- TextUtils.equals("[email protected]", UserInfoManager.getInstance().getBeiUser().email)) {
|
|
|
- View view = holder.getView(R.id.rl_template);
|
|
|
- view.setOnLongClickListener(v -> {
|
|
|
- if (couponLongClickListener != null) {
|
|
|
- couponLongClickListener.onItemLongClick(holder.getLayoutPosition());
|
|
|
- }
|
|
|
- return false;
|
|
|
- });
|
|
|
- }
|
|
|
+ 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;
|