mac
2024-03-08 4e4630ca78f00daf431088fbdc7e2ecc5b724369
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
package com.hdl.photovoltaic.ui.newC;
 
 
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
 
import androidx.recyclerview.widget.LinearLayoutManager;
 
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.photovoltaic.R;
import com.hdl.photovoltaic.base.CustomBaseActivity;
import com.hdl.photovoltaic.databinding.ActivityMessageCenterListBinding;
import com.hdl.photovoltaic.enums.MessageStateType;
import com.hdl.photovoltaic.listener.CloudCallBeak;
import com.hdl.photovoltaic.other.HdlCommonLogic;
import com.hdl.photovoltaic.other.HdlMessageLogic;
import com.hdl.photovoltaic.other.HdlThreadLogic;
import com.hdl.photovoltaic.ui.bean.MessageBean;
import com.hdl.photovoltaic.ui.newC.adapter.MessageCenterListAdapter;
import com.hdl.photovoltaic.widget.TypeTitleListDialog;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * C端消息中心列表
 */
public class MessageCenterList extends CustomBaseActivity {
 
    private ActivityMessageCenterListBinding viewBinding;
 
    private MessageCenterListAdapter messageCenterListAdapter;
 
    private boolean isAlarmDeviceClick = true;//true表示告警设备被选中,则false表示报警记录被选中
 
    private final List<MessageBean> mList = new ArrayList<>();
    private int currentPage = 0; // 当前页码
    private int currentTotal = 0; // 总页码
 
 
    private boolean isLoadingMore = false; // 标记正在加载更多数据
 
    LinearLayoutManager layoutManager;
 
    @Override
    public Object getContentView() {
        viewBinding = ActivityMessageCenterListBinding.inflate(getLayoutInflater());
        return viewBinding.getRoot();
    }
 
    @Override
    public void onBindView(Bundle savedInstanceState) {
        //初始化数据
        initData();
        //初始化
        initView();
        //初始化界面监听器
        initEvent();
        //进来读取一次数据(为了更新currentPage,currentTotal这个值)
        loadNextPageNascentMessageList(1, true);
    }
 
    private void initEvent() {
        //返回按钮
        viewBinding.toolbarTopMessageCenterListRl.topBackBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
 
        //全部设备(全部设备、逆变器、BMS控制盒、电池单元)按钮
        viewBinding.messageTabAllDeviceCl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                List<String> stringList = new ArrayList<>();
                stringList.add(getString(R.string.alarm_all_device));
                stringList.add(getString(R.string.alarm_all_device_inverter));
                stringList.add(getString(R.string.alarm_all_device_bms));
                stringList.add(getString(R.string.alarm_all_device_battery_cell));
                TypeTitleListDialog typeTitleListDialog = new TypeTitleListDialog(_mActivity, stringList);
                typeTitleListDialog.show();
                typeTitleListDialog.setOnListener(new TypeTitleListDialog.OnClickListener() {
                    @Override
                    public void onClick(int position, String title) {
                        viewBinding.allDeviceTitleIv.setBackgroundResource(R.drawable.up);
                        viewBinding.allGradeTitleIv.setBackgroundResource(R.drawable.down);
                        viewBinding.allTimeTitleIv.setBackgroundResource(R.drawable.down);
                        viewBinding.allDeviceTitleTv.setText(title);
                    }
                });
 
 
            }
        });
        //全部等级(故障、警告、提示)按钮
        viewBinding.messageTabAllGradeCl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
 
                List<String> stringList = new ArrayList<>();
                stringList.add(getString(R.string.alarm_all_grade));
                stringList.add(getString(R.string.alarm_all_grade_malfunction));
                stringList.add(getString(R.string.alarm_all_grade_warning));
                stringList.add(getString(R.string.alarm_all_grade_tip));
                TypeTitleListDialog typeTitleListDialog = new TypeTitleListDialog(_mActivity, stringList);
                typeTitleListDialog.show();
                typeTitleListDialog.setOnListener(new TypeTitleListDialog.OnClickListener() {
                    @Override
                    public void onClick(int position, String title) {
                        viewBinding.allDeviceTitleIv.setBackgroundResource(R.drawable.down);
                        viewBinding.allGradeTitleIv.setBackgroundResource(R.drawable.up);
                        viewBinding.allTimeTitleIv.setBackgroundResource(R.drawable.down);
                        viewBinding.allGradeTitleTv.setText(title);
                    }
                });
            }
        });
        //全部时间(当天、近3天、近7天、近30天)按钮
        viewBinding.messageTabAllTimeCl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
 
                List<String> stringList = new ArrayList<>();
                stringList.add(getString(R.string.alarm_all_time));
                stringList.add(getString(R.string.alarm_all_time_same_day));
                stringList.add(getString(R.string.alarm_all_time_3));
                stringList.add(getString(R.string.alarm_all_time_7));
                stringList.add(getString(R.string.alarm_all_time_30));
                TypeTitleListDialog typeTitleListDialog = new TypeTitleListDialog(_mActivity, stringList);
                typeTitleListDialog.show();
                typeTitleListDialog.setOnListener(new TypeTitleListDialog.OnClickListener() {
                    @Override
                    public void onClick(int position, String title) {
                        viewBinding.allDeviceTitleIv.setBackgroundResource(R.drawable.down);
                        viewBinding.allGradeTitleIv.setBackgroundResource(R.drawable.down);
                        viewBinding.allTimeTitleIv.setBackgroundResource(R.drawable.up);
                        viewBinding.allTimeTitleTv.setText(title);
                    }
                });
            }
        });
 
        //报警设备按钮
        viewBinding.messageBottomAlarmDeviceCl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isAlarmDeviceClick = true;
                refreshBottomStyle(true);
            }
        });
        //告警记录按钮
        viewBinding.messageBottomAlarmRecordCl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                isAlarmDeviceClick = false;
                refreshBottomStyle(false);
            }
        });
 
    }
 
    private void initView() {
        viewBinding.toolbarTopMessageCenterListRl.getRoot().setBackgroundColor(getColor(R.color.text_FFFFFFFF));
        viewBinding.toolbarTopMessageCenterListRl.topBackBtn.setVisibility(View.VISIBLE);
        viewBinding.toolbarTopMessageCenterListRl.topLeftIv.setImageResource(R.drawable.back_c);
        viewBinding.toolbarTopMessageCenterListRl.topTitleTv.setText(R.string.set_message_center);
        viewBinding.toolbarTopMessageCenterListRl.topMoreBtn.setVisibility(View.VISIBLE);
        viewBinding.toolbarTopMessageCenterListRl.topMoreIv.setImageResource(R.drawable.clearall);
        //默认选中全部设备
        viewBinding.allDeviceTitleIv.setBackgroundResource(R.drawable.up);
        viewBinding.allGradeTitleIv.setBackgroundResource(R.drawable.down);
        viewBinding.allTimeTitleIv.setBackgroundResource(R.drawable.down);
        refreshBottomStyle(true);
        layoutManager = new LinearLayoutManager(_mActivity);
        messageCenterListAdapter = new MessageCenterListAdapter(_mActivity);
        viewBinding.messageContentRl.setLayoutManager(layoutManager);
        viewBinding.messageContentRl.setAdapter(messageCenterListAdapter);
        messageCenterListAdapter.setList(mList);
        this.nullDataUpdateUi();
    }
 
    private void initData() {
    }
 
    /**
     * 加载一页数据
     *
     * @param pageNo        页数
     * @param isShowLoading 是否启动加载框 true启动
     */
    private void loadNextPageNascentMessageList(int pageNo, boolean isShowLoading) {
        //第一页读取数据强制读
        if (pageNo > 1 && currentPage > currentTotal) {
            --currentPage;
            //当前页不能大于总页数
            return;
        }
        isLoadingMore = true;//标记读取状态
        if (isShowLoading) {
            showLoading();
        }
        HdlMessageLogic.getInstance().getPageNoMessageList(pageNo, MessageStateType.untreated, new CloudCallBeak<HdlMessageLogic.MessageListClass>() {
            @Override
            public void onSuccess(HdlMessageLogic.MessageListClass messageListClass) {
                if (messageListClass != null) {
                    currentTotal = (int) messageListClass.getTotalPage();
                    currentPage = (int) messageListClass.getPageNo();
                    updateListData();
                }
                isLoadingMore = false;
                if (isShowLoading) {
                    hideLoading();
                }
            }
 
            @Override
            public void onFailure(HDLException e) {
                if (currentPage > 1) {
                    --currentPage;
                }
                isLoadingMore = false;
                if (isShowLoading) {
                    hideLoading();
                }
            }
        });
    }
 
    /**
     * 读取消息【未读数量】
     */
    private void getUnreadCount() {
        HdlMessageLogic.getInstance().getMessageUntreatedCount(new CloudCallBeak<String>() {
            @Override
            public void onSuccess(String data) {
 
                HdlThreadLogic.runMainThread(new Runnable() {
                    @Override
                    public void run() {
                        JSONObject jsonObject = JSON.parseObject(data);
                        if (jsonObject.containsKey("untreatedCount")) {
                            //未处理数量
                            String untreatedCount = jsonObject.getString("untreatedCount");
                            refreshNascentCount(untreatedCount);
                        }
                        if (jsonObject.containsKey("unreadCount")) {
                            //未读数量
                            String unreadCount = jsonObject.getString("unreadCount");
                            refreshUnreadNascentCount(unreadCount);
                        }
                    }
                });
 
            }
 
            @Override
            public void onFailure(HDLException e) {
                TextView textView = _mActivity.findViewById(R.id.my_message_bottom_il2).findViewById(R.id.red_count_tv);
                if (textView != null) {
                    textView.setVisibility(View.GONE);
                }
            }
        });
    }
 
    /**
     * 刷新信息数量总数
     */
    private void refreshNascentCount(String totalCount) {
        HdlThreadLogic.runMainThread(new Runnable() {
            @Override
            public void run() {
                TextView textView = _mActivity.findViewById(R.id.message_bottom_alarm_device_title_tv);
                if (textView != null) {
                    textView.setText(getText(R.string.alarm_device));
                    if (!TextUtils.isEmpty(totalCount) && !totalCount.equals("0")) {
                        String s = getText(R.string.message_nascent) + "(" + totalCount + ")";
                        textView.setText(s);
                    }
                }
            }
        });
    }
 
    /**
     * 刷新底部样式
     *
     * @param typeClick 表示底部的类型(设备报警=true,报警记录=false)
     */
    private void refreshBottomStyle(boolean typeClick) {
        HdlThreadLogic.runMainThread(new Runnable() {
            @Override
            public void run() {
                if (typeClick) {
                    viewBinding.messageBottomAlarmDeviceTitleTv.setTextColor(getColor(R.color.text_191919));
                    viewBinding.messageBottomAlarmDeviceLineV.setVisibility(View.VISIBLE);
                    viewBinding.messageBottomAlarmRecordTitleTv.setTextColor(getColor(R.color.text_B2B2B2));
                    viewBinding.messageBottomAlarmRecordLineV.setVisibility(View.GONE);
 
 
                } else {
                    viewBinding.messageBottomAlarmDeviceTitleTv.setTextColor(getColor(R.color.text_B2B2B2));
                    viewBinding.messageBottomAlarmDeviceLineV.setVisibility(View.GONE);
                    viewBinding.messageBottomAlarmRecordTitleTv.setTextColor(getColor(R.color.text_191919));
                    viewBinding.messageBottomAlarmRecordLineV.setVisibility(View.VISIBLE);
                }
 
            }
        });
    }
 
 
    /**
     * 刷新角标【未读】信息数量总数
     */
    private void refreshUnreadNascentCount(String unreadCount) {
        HdlThreadLogic.runMainThread(new Runnable() {
            @SuppressLint("SetTextI18n")
            @Override
            public void run() {
                TextView textView = _mActivity.findViewById(R.id.my_message_bottom_il2).findViewById(R.id.red_count_tv);
                if (textView != null) {
                    if (TextUtils.isEmpty(unreadCount) || unreadCount.equals("0")) {
                        textView.setVisibility(View.GONE);
                    } else {
                        textView.setVisibility(View.VISIBLE);
                        if (unreadCount.length() > 2) {
                            textView.setText("99+");
                        } else {
                            textView.setText(unreadCount);
                        }
                    }
                }
            }
        });
    }
 
    /**
     * 刷新列表数据
     */
    private void updateListData() {
        HdlThreadLogic.runMainThread(new Runnable() {
            @Override
            public void run() {
                //读取缓存数据
                updateCacheData();
                //刷新列表
                if (messageCenterListAdapter != null) {
                    messageCenterListAdapter.setList(mList);
                }
                //显示未读信息总数量
                getUnreadCount();
                //显示没数据Ui样式
                nullDataUpdateUi();
 
            }
        });
    }
 
    /**
     * 更新缓存数据
     */
    private void updateCacheData() {
        mList.clear();
        mList.addAll(HdlMessageLogic.getInstance().getNascentMessageMemoryList());
    }
 
 
    /**
     * 没有电站列表的样式
     */
    private void nullDataUpdateUi() {
        HdlCommonLogic.getInstance().nullDataUpdateUi(_mActivity, viewBinding.nullDataIc.getRoot(), viewBinding.nullDataIc.nullDataGifAnimationIv, viewBinding.nullDataIc.nullDataTv, getString(R.string.message_alarm_data_null), mList.size() > 0);
    }
}