package com.tejia.lijin.app.ui.BrandRebate;
|
|
import android.content.Context;
|
import android.content.Intent;
|
import android.os.Bundle;
|
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.bumptech.glide.request.RequestOptions;
|
import com.wpc.library.util.common.StringUtils;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.entity.BranShopInfo;
|
import com.tejia.lijin.app.util.GlideCircleTransform;
|
import com.tejia.lijin.app.util.umengCustomEvent.BrandRebateEvent;
|
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* 品牌or品牌历史
|
*/
|
public class ShopHistoryAdapter extends BaseAdapter {
|
private Context mContext;
|
|
private List<BranShopInfo> mList = new ArrayList<>();
|
|
private List<BranShopInfo> bList;
|
private String arg_id;//店铺列表id
|
private String arg_;//店铺列表名字
|
|
public ShopHistoryAdapter(Context context, List<BranShopInfo> list, String id, String arg) {
|
mContext = context;
|
bList = list;
|
arg_id = id;
|
arg_ = arg;
|
}
|
|
//添加 更多
|
private BranShopInfo getinfo() {
|
BranShopInfo info = new BranShopInfo();
|
info.setId("0");
|
info.setName("更多");
|
info.setIcon("null");
|
return info;
|
}
|
|
public void setListCount() {
|
notifyDataSetChanged();
|
mList.clear();
|
int size = arg_id.equals("0") ? 4 : 7;
|
// 通过id判断 是否精选页
|
if (!arg_id.equals("0")) { //不是精选的情况
|
List<BranShopInfo> cList = new ArrayList<>();
|
if (bList.size() > size) { //大于7个
|
for (int i = 0; i < size; i++) {
|
if (i < size) {
|
cList.add(bList.get(i));
|
} else {
|
break;
|
}
|
}
|
// mList = cList;
|
mList.addAll(cList);
|
} else { //否则全部赋值
|
// mList = list;
|
mList.addAll(bList);
|
}
|
mList.add(getinfo());//添加 更多
|
} else {
|
//精选
|
mList.addAll(bList);
|
mList.add(getinfo());//添加 更多
|
}
|
}
|
|
@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);
|
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();
|
if (!arg_id.equals("0")) {//不是精选
|
para1.height = ScreenUtils.dp2px(mContext, 50);
|
para1.width = ScreenUtils.dp2px(mContext, 50);
|
para2.height = ScreenUtils.dp2px(mContext, 52);
|
para2.width = ScreenUtils.dp2px(mContext, 52);
|
} else {//精选
|
para1.height = ScreenUtils.dp2px(mContext, 40);
|
para1.width = ScreenUtils.dp2px(mContext, 40);
|
para2.height = ScreenUtils.dp2px(mContext, 42);
|
para2.width = ScreenUtils.dp2px(mContext, 42);
|
}
|
holder.iv_category.setLayoutParams(para1);
|
holder.item_shophistory_imgv.setLayoutParams(para2);
|
convertView.setTag(holder);
|
} else {
|
holder = (Holder) convertView.getTag();
|
}
|
final BranShopInfo info = mList.get(position);
|
if (!info.getIcon().equals("null")) {
|
if (!info.getIcon().equals(holder.iv_category.getTag())) {//解决刷新闪烁
|
Glide.with(mContext).load(info.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);
|
BrandRebateEvent.brandhistory(mContext);//品牌历史
|
//跳转 品牌店铺详情
|
Intent intent = new Intent(mContext, BrandInfoActivity.class);
|
intent.putExtra("sid", info.getId());
|
intent.putExtra("shopname", info.getName());
|
mContext.startActivity(intent);
|
}
|
});
|
} else {
|
Glide.with(mContext).load(R.drawable.ic_category_more2)
|
.placeholder(R.drawable.ic_category_default) //设置等待时的图片
|
.apply(new RequestOptions().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();
|
int i = 0;
|
for (BranShopInfo js : bList) {
|
i++;
|
bundle.putSerializable("info" + i, js);
|
}
|
BrandRebateEvent.brandmore(mContext);//品牌-品牌点击更多
|
//跳转到所有店铺
|
mContext.startActivity(new Intent(mContext, BrandInfoAllActivity.class)
|
.putExtra("arg", arg_)
|
.putExtra("bList", bundle));
|
} else {
|
// 跳转到 店铺足迹详情
|
mContext.startActivity(new Intent(mContext, BrandFootprintInfoActivity.class));
|
}
|
// mContext.startActivity(new Intent(mContext, CategoryTypeActivity.class));
|
}
|
});
|
}
|
// Log.e("eee", "getView: "+info.getName());
|
holder.tv_category_name.setText(Stringsubstr(info.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;
|
TextView tv_category_name;
|
ImageView item_shophistory_imgv;
|
}
|
}
|