admin
2021-06-11 ae4dc86b64bd8ef85bc832106741fb98e8d516da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
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.ShoppingApplication;
import com.tejia.lijin.app.util.JumpActivityUtil;
import com.tejia.lijin.app.util.user.UserUtil;
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);
        ShoppingApi.getreadCommonMsg(mcontext, UserUtil.getUid(ShoppingApplication.application), 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;//红点
    }
}