mac
2024-04-10 1a758b1bfbff1b910cd912c4e7434bf8f63a210a
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
package com.hdl.photovoltaic.ui.message;
 
 
import android.annotation.SuppressLint;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
 
import androidx.appcompat.content.res.AppCompatResources;
 
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.photovoltaic.R;
import com.hdl.photovoltaic.base.CustomBaseActivity;
import com.hdl.photovoltaic.config.ConstantManage;
import com.hdl.photovoltaic.config.UserConfigManage;
import com.hdl.photovoltaic.databinding.ActivityMessageInfoBinding;
import com.hdl.photovoltaic.enums.MessageAlarmStateType;
import com.hdl.photovoltaic.enums.MessageStateType;
import com.hdl.photovoltaic.listener.CloudCallBeak;
import com.hdl.photovoltaic.other.HdlMessageLogic;
import com.hdl.photovoltaic.other.HdlThreadLogic;
import com.hdl.photovoltaic.ui.bean.MessageBean;
import com.hdl.photovoltaic.utils.TimeUtils;
import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus;
 
import org.greenrobot.eventbus.EventBus;
 
/**
 * 消息详情
 */
public class MessageInfoActivity extends CustomBaseActivity {
 
    ActivityMessageInfoBinding viewBinding;
 
    private MessageBean mMessageBean;
 
    private String mMsgId;
 
    @Override
    public Object getContentView() {
        viewBinding = ActivityMessageInfoBinding.inflate(getLayoutInflater());
        return viewBinding.getRoot();
    }
 
    @Override
    public void onBindView(Bundle savedInstanceState) {
        setNotificationBarBackgroundColor(CustomColor.white);
        setStatusBarTextColor();
        try {
            mMsgId = getIntent().getStringExtra("msgId");
        } catch (Exception ignored) {
        }
 
        //初始化
        initView();
        //初始化界面监听器
        initEvent();
        //读取数据
        readData();
    }
 
    private void readData() {
 
//        showLoading();
        HdlMessageLogic.getInstance().getMessageInfo(mMsgId, new CloudCallBeak<MessageBean>() {
            @Override
            public void onSuccess(MessageBean msg) {
                HdlThreadLogic.runMainThread(new Runnable() {
                    @Override
                    public void run() {
//                        hideLoading();
                        if (msg == null) {
                            return;
                        }
                        mMessageBean = msg;
 
                        viewBinding.messageInfoHomeNameTv.setText(mMessageBean.getHomeName());
                        viewBinding.messageInfoAlarmContentIn.rightContentTv.setText(mMessageBean.getTitle());
                        viewBinding.messageInfoAlarmDeviceIn.rightContentTv.setText(mMessageBean.getDeviceDesc());
                        viewBinding.messageInfoAlarmRangeIn.rightContentTv.setText(mMessageBean.getEffectScopeDesc());
                        viewBinding.messageInfoPowerStationLocationIn.rightContentTv.setText(mMessageBean.getLocationAddress());
                        String date = TimeUtils.getTimeFromTimestamp(mMessageBean.getCreateTime());
                        viewBinding.messageInfoAlarmTimeIn.rightContentTv.setText(date);
 
                        String type = "";//FAULT:故障,WARN:告警,EVENT:事件
                        Drawable drawable = AppCompatResources.getDrawable(_mActivity, R.drawable.alarm_ffb300);
                        if (mMessageBean.getType().equals(MessageAlarmStateType.fault)) {
                            type = _mActivity.getString(R.string.my_power_station_malfunction);
                            drawable = AppCompatResources.getDrawable(_mActivity, R.drawable.alarm_e34343);
                        } else if (mMessageBean.getType().equals(MessageAlarmStateType.warn)) {
                            type = _mActivity.getString(R.string.message_alarm);
                            drawable = AppCompatResources.getDrawable(_mActivity, R.drawable.alarm_ffb300);
                        } else if (mMessageBean.getType().equals(MessageAlarmStateType.event)) {
                            type = _mActivity.getString(R.string.event);
                            drawable = AppCompatResources.getDrawable(_mActivity, R.drawable.alarm_ffb300);
                        }
                        viewBinding.messageInfoAlarmStateTv.setText(type);
                        viewBinding.messageInfoAlarmStateTv.setBackground(drawable);
 
                        if (mMessageBean.getStatus().equals(MessageStateType.processed)) {
                            //已经解决掉的隐藏
                            viewBinding.messageInfoBackTv.setVisibility(View.GONE);
                            viewBinding.messageInfoSolveTv.setVisibility(View.GONE);
                        }
                    }
                });
            }
 
            @Override
            public void onFailure(HDLException e) {
//                hideLoading();
                HdlThreadLogic.toast(_mActivity, e);
            }
        });
    }
 
    private void initEvent() {
        //后退的事件
        viewBinding.toolbarTopIn.topBackBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mMessageBean == null) {
                    finish();
                    return;
                }
                //未处理
                if (mMessageBean.getStatus().equals(MessageStateType.untreated)) {
                    BaseEventBus baseEventBus = new BaseEventBus();
                    baseEventBus.setTopic(ConstantManage.message_function_push_post);
                    //改变缓存状态
                    if (mMessageBean.getType().equals(MessageAlarmStateType.fault)) {
                        HdlMessageLogic.getInstance().setMessageState(mMessageBean.getMsgId(), true, MessageStateType.untreated);
                        baseEventBus.setType(MessageStateType.untreated);
                    } else {
                        //除“故障”外,其他等级信息“已读”后,自动移出“发生中”列表并加入“历史记录”列表
                        HdlMessageLogic.getInstance().setMessageState(mMessageBean.getMsgId(), true, MessageStateType.processed);
                        baseEventBus.setType(MessageStateType.processed);
                    }
                    EventBus.getDefault().post(baseEventBus);
                }
                finish();
            }
        });
        //返回的事件
        viewBinding.messageInfoBackTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mMessageBean == null) {
                    finish();
                    return;
                }
                //未处理
                if (mMessageBean.getStatus().equals(MessageStateType.untreated)) {
                    BaseEventBus baseEventBus = new BaseEventBus();
                    baseEventBus.setTopic(ConstantManage.message_function_push_post);
                    //改变缓存状态
                    if (mMessageBean.getType().equals(MessageAlarmStateType.fault)) {
                        HdlMessageLogic.getInstance().setMessageState(mMessageBean.getMsgId(), true, MessageStateType.untreated);
                        baseEventBus.setType(MessageStateType.untreated);
                    } else {
                        //除“故障”外,其他等级信息“已读”后,自动移出“发生中”列表并加入“历史记录”列表
                        HdlMessageLogic.getInstance().setMessageState(mMessageBean.getMsgId(), true, MessageStateType.processed);
                        baseEventBus.setType(MessageStateType.processed);
                    }
                    EventBus.getDefault().post(baseEventBus);
                }
                finish();
            }
        });
 
        //已处理的事件
        viewBinding.messageInfoSolveTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                HdlMessageLogic.getInstance().getMessageMessageSolve(mMsgId, new CloudCallBeak<Boolean>() {
                    @Override
                    public void onSuccess(Boolean obj) {
                        if (mMessageBean == null) {
                            return;
                        }
                        //未处理
                        if (mMessageBean.getStatus().equals(MessageStateType.untreated)) {
                            HdlMessageLogic.getInstance().setMessageState(mMessageBean.getMsgId(), true, MessageStateType.processed);
 
                            //通知已处理要更新数据
                            BaseEventBus processedBus = new BaseEventBus();
                            processedBus.setTopic(ConstantManage.message_function_push_post);
                            processedBus.setType(MessageStateType.processed);
                            EventBus.getDefault().post(processedBus);
                            //通知未处理要更新数据
                            BaseEventBus untreatedBus = new BaseEventBus();
                            untreatedBus.setTopic(ConstantManage.message_function_push_post);
                            untreatedBus.setType(MessageStateType.untreated);
                            EventBus.getDefault().post(untreatedBus);
                        }
                        finish();
 
 
                    }
 
                    @Override
                    public void onFailure(HDLException e) {
                        HdlThreadLogic.toast(_mActivity, e);
                    }
                });
 
            }
        });
 
 
    }
 
 
    private void initView() {
 
        viewBinding.toolbarTopIn.topTitleTv.setText(R.string.message_alarm_info);
        viewBinding.toolbarTopIn.topTitleTv.setTextColor(getResources().getColor(R.color.text_030D1C, null));
        viewBinding.toolbarTopIn.topBackBtn.setVisibility(View.VISIBLE);
        viewBinding.toolbarTopIn.topBarView.setBackgroundColor(getResources().getColor(R.color.text_FFFFFFFF, null));
 
        if (!UserConfigManage.getInstance().isBAccount()) {
            viewBinding.messageInfoBackTv.setTextColor(getColor(R.color.text_38C494));
            viewBinding.messageInfoBackTv.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.fillet_line_38c494));
            viewBinding.messageInfoSolveTv.setBackground(AppCompatResources.getDrawable(_mActivity, R.drawable.checked_38c494));
        }
 
        viewBinding.messageInfoAlarmContentIn.leftTitleTv.setText(R.string.messagealarm_details_content);
        viewBinding.messageInfoAlarmDeviceIn.leftTitleTv.setText(R.string.messagealarm_details_device);
        viewBinding.messageInfoAlarmRangeIn.leftTitleTv.setText(R.string.message_alarm_detailsaffect_region);
        viewBinding.messageInfoPowerStationLocationIn.leftTitleTv.setText(R.string.message_alarm_detailspower_station_location);
        viewBinding.messageInfoAlarmTimeIn.leftTitleTv.setText(R.string.message_alarm_details_time);
 
        viewBinding.messageInfoAlarmContentIn.rightContentTv.setText("");
        viewBinding.messageInfoAlarmDeviceIn.rightContentTv.setText("");
        viewBinding.messageInfoAlarmRangeIn.rightContentTv.setText("");
        viewBinding.messageInfoPowerStationLocationIn.rightContentTv.setText("");
        viewBinding.messageInfoAlarmTimeIn.rightContentTv.setText("");
    }
}