package com.tejia.lijin.app.ui.BrandRebate;
|
|
import android.content.Context;
|
import android.content.Intent;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.ViewGroup;
|
import android.widget.BaseAdapter;
|
import android.widget.ImageView;
|
import android.widget.TextView;
|
|
import com.app.hubert.guide.util.ScreenUtils;
|
import com.bumptech.glide.Glide;
|
import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.entity.BranShopInfo;
|
import com.tejia.lijin.app.util.GlideCircleTransform;
|
|
import java.util.List;
|
|
public class BrandInfoAllAdapter extends BaseAdapter {
|
private Context mContext;
|
|
private List<BranShopInfo> mList;
|
|
|
public BrandInfoAllAdapter(Context context, List<BranShopInfo> list) {
|
mContext = context;
|
mList = list;
|
}
|
|
@Override
|
public int getCount() {
|
return mList == null ? 0 : mList.size();
|
}
|
|
@Override
|
public Object getItem(int position) {
|
return mList.get(position);
|
}
|
|
@Override
|
public long getItemId(int position) {
|
return position;
|
}
|
|
|
@Override
|
public View getView(final int position, View convertView, ViewGroup parent) {
|
Holder holder = null;
|
if (convertView == null) {
|
holder = new Holder();
|
convertView = LayoutInflater.from(mContext).inflate(R.layout.item_shophistory, null);
|
holder.iv_category = convertView.findViewById(R.id.item_shophistory_img);
|
holder.tv_category_name = convertView.findViewById(R.id.item_shophistory_txt);
|
convertView.setBackgroundColor(mContext.getResources().getColor(R.color.white));
|
holder.item_shophistory_imgv = convertView.findViewById(R.id.item_shophistory_imgv);
|
ViewGroup.LayoutParams para1 = holder.iv_category.getLayoutParams();
|
ViewGroup.LayoutParams para2 = holder.item_shophistory_imgv.getLayoutParams();
|
para1.height = ScreenUtils.dp2px(mContext, 50);
|
para1.width = ScreenUtils.dp2px(mContext, 50);
|
para2.height = ScreenUtils.dp2px(mContext, 52);
|
para2.width = ScreenUtils.dp2px(mContext, 52);
|
holder.iv_category.setLayoutParams(para1);
|
holder.item_shophistory_imgv.setLayoutParams(para2);
|
convertView.setTag(holder);
|
} else {
|
holder = (Holder) convertView.getTag();
|
}
|
final BranShopInfo object = mList.get(position);
|
if (object.getIcon() != null) {
|
if (!object.getIcon().equals(holder.iv_category.getTag())) {//解决刷新闪烁
|
Glide.with(mContext).load(object.getIcon())
|
.transform(new GlideCircleTransform(mContext))
|
.placeholder(R.drawable.ic_category_default) //设置等待时的图片
|
.diskCacheStrategy(DiskCacheStrategy.RESOURCE)//保存最终图片
|
.into(holder.iv_category);
|
} else {
|
}
|
convertView.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
// CategoryCustomEvent.classSecond(mContext);
|
//跳转 品牌店铺详情
|
Intent intent = new Intent(mContext, BrandInfoActivity.class);
|
intent.putExtra("sid", object.getId());
|
intent.putExtra("shopname", object.getName());
|
mContext.startActivity(intent);
|
}
|
});
|
} else {
|
// Glide.with(mContext).load(R.drawable.ic_category_more2)
|
// .placeholder(R.drawable.ic_goods_default) //设置等待时的图片
|
// .bitmapTransform(new GlideCircleTransform(mContext))//加载圆形图片
|
// .into(holder.iv_category);
|
// convertView.setOnClickListener(new View.OnClickListener() {
|
// @Override
|
// public void onClick(View v) {
|
// mList = bList;
|
// if (arg_id != null && !StringUtils.isEmpty(arg_id) && !arg_id.equals("0")) {
|
// notifyDataSetChanged();
|
// //
|
//// Bundle bundle = new Bundle();
|
//// bundle.put
|
// ArrayList<CharSequence> str = new ArrayList<>();
|
// for (JSONObject js : bList) {
|
// str.add(js.toString());
|
// }
|
//
|
// mContext.startActivity(new Intent(mContext, BrandInfoAllActivity.class).putExtra("arg", arg_).putCharSequenceArrayListExtra("bList", str));
|
// } else {
|
//// 跳转到 店铺足迹详情
|
// mContext.startActivity(new Intent(mContext, BrandFootprintInfoActivity.class));
|
// }
|
//// mContext.startActivity(new Intent(mContext, CategoryTypeActivity.class));
|
// }
|
// });
|
}
|
|
holder.tv_category_name.setText(Stringsubstr(mList.get(position).getName()));
|
return convertView;
|
}
|
|
private String Stringsubstr(String shopName) {
|
String str = "";
|
if (shopName.length() > 4) {
|
str = shopName.substring(0, 4) + "...";//这种情况下默认从,start位置到原字符串末尾,即返回:"ello"
|
} else {
|
str = shopName;
|
}
|
return str;
|
}
|
|
class Holder {
|
ImageView iv_category;
|
ImageView item_shophistory_imgv;
|
TextView tv_category_name;
|
}
|
|
}
|