package com.tejia.lijin.app.ui.recommend;
|
|
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.LinearLayout;
|
import android.widget.TextView;
|
|
import com.bumptech.glide.Glide;
|
import com.tejia.lijin.app.util.JumpActivityUtil;
|
import com.wpc.library.util.common.StringUtils;
|
import com.tejia.lijin.app.BasicTextHttpResponseHandler;
|
import com.tejia.lijin.app.R;
|
import com.tejia.lijin.app.ShoppingApi;
|
import com.tejia.lijin.app.entity.CommonList;
|
import com.tejia.lijin.app.ui.main.MainActivity;
|
import com.tejia.lijin.app.util.KeFuUtil;
|
|
import org.apache.http.Header;
|
import org.json.JSONObject;
|
|
import java.util.Iterator;
|
import java.util.List;
|
|
/**
|
* 消息 TopView Adapters
|
*/
|
public class MessagelistAdapter extends BaseAdapter {
|
private List<CommonList> mlist;
|
private LayoutInflater mInflater;
|
private MainActivity mcontext;
|
|
public MessagelistAdapter(MainActivity context, List<CommonList> list) {
|
this.mlist = list;
|
this.mInflater = LayoutInflater.from(context);
|
this.mcontext = context;
|
}
|
|
@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) {
|
ViewHolder holder = null;
|
if (convertView == null) {
|
holder = new ViewHolder();
|
convertView = mInflater.inflate(R.layout.item_message_top2, null);
|
//官宣任务
|
holder.ll_critical_guanxuan = convertView.findViewById(R.id.ll_critical_guanxuan);
|
holder.tv_critical_guanxuan_title = convertView.findViewById(R.id.tv_critical_guanxuan_title);//title
|
holder.tv_critical_guanxuan_time = convertView.findViewById(R.id.tv_critical_guanxuan_time);//时间
|
holder.iv_critical_guanxuan_img = convertView.findViewById(R.id.iv_critical_guanxuan_img);//头像
|
holder.tv_critical_guanxuan_content = convertView.findViewById(R.id.tv_critical_guanxuan_content);//内容
|
holder.iv_guanxuan_dot = convertView.findViewById(R.id.iv_guanxuan_dot);//红点
|
holder.iv_guanxuan_dot2 = convertView.findViewById(R.id.iv_guanxuan_dot2);//客服红点
|
|
convertView.setTag(holder);
|
} else {
|
holder = (ViewHolder) convertView.getTag();
|
}
|
final CommonList object = mlist.get(position);//消息 jsonobj
|
// holder.ll_critical_guanxuan.setVisibility(View.VISIBLE);//显示 小助手
|
holder.tv_critical_guanxuan_title.setText(object.getTitle());
|
holder.tv_critical_guanxuan_time.setText(object.getTime());
|
Glide.with(mcontext).load(object.getIcon()).into(holder.iv_critical_guanxuan_img);
|
holder.tv_critical_guanxuan_content.setText(object.getLatestMsg());
|
//未读则显示 红点
|
if (!object.getRead()) {
|
if (object.getType() != null && object.getType().equals("kefu")) {
|
holder.iv_guanxuan_dot2.setVisibility(View.VISIBLE);
|
holder.iv_guanxuan_dot.setVisibility(View.GONE);
|
holder.iv_guanxuan_dot2.setText(object.getRedcount() > 99 ? "99+" : String.valueOf(object.getUnReadCount()));
|
} else {
|
holder.iv_guanxuan_dot.setVisibility(View.VISIBLE);
|
holder.iv_guanxuan_dot2.setVisibility(View.GONE);
|
}
|
} else { //已读隐藏 红点
|
holder.iv_guanxuan_dot2.setVisibility(View.GONE);
|
holder.iv_guanxuan_dot.setVisibility(View.GONE);
|
}
|
// guanxuan_activity = object.optJSONObject("jumpDetail").optString("activity");//跳转activity
|
// guanxuan_params = object.getString("params");//跳转打开网址
|
final ViewHolder finalHolder = holder;
|
holder.ll_critical_guanxuan.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
//未读则显示 红点
|
// object.setRead(true);
|
mlist.get(position).setRead(true);
|
//隐藏红点消息
|
finalHolder.iv_guanxuan_dot.setVisibility(View.GONE);
|
finalHolder.iv_guanxuan_dot2.setVisibility(View.GONE);
|
Intent intent = null;
|
//客服
|
if (object.getType() != null && object.getType().equals("kefu")) {
|
readCommonMsg(object.getType());
|
MainActivity activity = mcontext;
|
activity.setclear(false);
|
KeFuUtil.jumpKeFu(mcontext, "消息");
|
}
|
//推荐记录
|
else if (object.getType() != null && object.getType().equals("recommend")) {
|
readCommonMsg(object.getType());
|
if (!StringUtils.isEmpty(object.getJumpDetail().getActivity())) {
|
try {
|
intent = new Intent(mcontext, Class.forName(JumpActivityUtil.filterActivityName(object.getJumpDetail().getActivity())));
|
mcontext.startActivity(intent);
|
} catch (ClassNotFoundException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
//板栗快省小助手
|
else if (object.getType() != null && object.getType().equals("zhushou")) {
|
readCommonMsg(object.getType());
|
|
if (!StringUtils.isEmpty(object.getJumpDetail().getActivity())) {
|
try {
|
intent = new Intent(mcontext, Class.forName(JumpActivityUtil.filterActivityName(object.getJumpDetail().getActivity())));
|
if (object.getParams() != null) {
|
Iterator<String> its = object.getParams().keySet().iterator();
|
while (its.hasNext()) {
|
String key = its.next();
|
intent.putExtra(key, object.getParams().getString(key));
|
}
|
}
|
|
mcontext.startActivity(intent);
|
} catch (ClassNotFoundException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
//官宣任务
|
else if (object.getType() != null && object.getType().equals("guanxuan")) {
|
readCommonMsg(object.getType());
|
if (!StringUtils.isEmpty(object.getJumpDetail().getActivity())) {
|
try {
|
intent = new Intent(mcontext, Class.forName(JumpActivityUtil.filterActivityName(object.getJumpDetail().getActivity())));
|
if (object.getParams() != null) {
|
Iterator<String> its = object.getParams().keySet().iterator();
|
while (its.hasNext()) {
|
String key = its.next();
|
intent.putExtra(key, object.getParams().getString(key));
|
}
|
}
|
|
mcontext.startActivity(intent);
|
} catch (ClassNotFoundException e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
|
|
}
|
});
|
return convertView;
|
}
|
|
/**
|
* 读常规消息
|
*
|
* @param type
|
*/
|
private void readCommonMsg(String type) {
|
// final boolean isLogin = sp.getBoolean("isLogin", false);
|
String uid = mcontext.getSharedPreferences("user", Context.MODE_PRIVATE).getString("uid", "");
|
ShoppingApi.getreadCommonMsg(mcontext, uid, type, new BasicTextHttpResponseHandler() {
|
@Override
|
public void onSuccessPerfect(int statusCode, Header[] headers, JSONObject jsonObject) throws Exception {
|
}
|
});
|
|
}
|
|
/*控件缓存类*/
|
class ViewHolder {
|
//官宣任务
|
private LinearLayout ll_critical_guanxuan;
|
private TextView tv_critical_guanxuan_title;//title
|
private TextView tv_critical_guanxuan_time;//时间
|
private ImageView iv_critical_guanxuan_img;//头像
|
private TextView tv_critical_guanxuan_content;//内容
|
private ImageView iv_guanxuan_dot;//红点
|
private TextView iv_guanxuan_dot2;//红点
|
}
|
}
|