NewsOrderAdapter.java
4.7 KB
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
package com.huaheng.mmsrf.adapter;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.huaheng.mmsrf.R;
import com.huaheng.mmsrf.activity.car.ScanningCarkListActivity;
import com.huaheng.mmsrf.activity.work.NewsOrderActivity;
import com.huaheng.mmsrf.bean.Constant;
import com.huaheng.mmsrf.bean.NewsBean;
import com.huaheng.mmsrf.https.HttpInterface;
import com.huaheng.mmsrf.https.Subscribers.ProgressSubscriber;
import com.huaheng.mmsrf.https.Subscribers.SubscriberOnNextListener;
import com.huaheng.mmsrf.util.MyColor;
import com.huaheng.mmsrf.util.WMSUtils;
import java.util.ArrayList;
import java.util.List;
/**
* Created by youjie on 2020/12/15
*/
public class NewsOrderAdapter extends BaseAdapter {
private Context mContext;
private List<NewsBean> mList = new ArrayList<>();
public NewsOrderAdapter(Context mContext) {
this.mContext = mContext;
}
public List <NewsBean> getmList() {
return mList;
}
public void setList(List <NewsBean> mList) {
this.mList = mList;
}
@Override
public int getCount() {
return mList.size();
}
@Override
public Object getItem(int i) {
return mList.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(final int position, View convertView, ViewGroup viewGroup) {
ViewHolder viewHolder = new ViewHolder();
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.news_list_item, null);
TextView title = (TextView) convertView.findViewById(R.id.title);
TextView content = (TextView) convertView.findViewById(R.id.content);
TextView ctime = (TextView) convertView.findViewById(R.id.ctime);
viewHolder.title = title;
viewHolder.content = content;
viewHolder.ctime = ctime;
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
final NewsBean bean = (NewsBean) mList.get(position);
if ("0".equals(bean.getReadFlag())){
viewHolder.title.setTextColor(MyColor.red);
viewHolder.content.setTextColor(MyColor.red);
viewHolder.ctime.setTextColor(MyColor.red);
}else{
viewHolder.title.setTextColor(MyColor.black);
viewHolder.content.setTextColor(MyColor.black);
viewHolder.ctime.setTextColor(MyColor.black);
}
viewHolder.title.setText(bean.getTitile());
viewHolder.content.setText(bean.getContent());
viewHolder.ctime.setText(bean.getCtime());
// convertView.setOnLongClickListener(new View.OnLongClickListener() {
// @Override
// public boolean onLongClick(View view) {
// showUpdateDialog(bean.getId());
// return false;
// }
// });
return convertView;
}
private void showUpdateDialog(final String id) {
AlertDialog mDialog;
AlertDialog.Builder builder = new AlertDialog.Builder(mContext).setTitle("确认已读")
.setMessage("是否标记为已读")
.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
//按下确定键后的事件
Read(id);
}
}).setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
mDialog = builder.create();
mDialog.setCancelable(false);
mDialog.show();
}
public void Read(String id) {
HttpInterface.getInsstance().Read(new ProgressSubscriber<String>(mContext, ReadListener),
id);
}
SubscriberOnNextListener ReadListener = new SubscriberOnNextListener <String>() {
@Override
public void onNext(String str) {
((NewsOrderActivity)mContext).search();
//search();
}
@Override
public void onError(String str) {
if(Constant.RESET.equals(str)) {
} else {
WMSUtils.showShort(str);
}
}
};
private class ViewHolder {
TextView title;
TextView content;
TextView ctime;
}
}