mac
2023-12-26 637e3152e3bfea430ca774c7dd178b4b9696c37f
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
package com.hdl.photovoltaic.ui.message;
 
import android.content.Intent;
import android.os.Bundle;
 
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
 
import com.hdl.linkpm.sdk.core.exception.HDLException;
import com.hdl.photovoltaic.R;
import com.hdl.photovoltaic.base.CustomBaseFragment;
import com.hdl.photovoltaic.config.ConstantManage;
import com.hdl.photovoltaic.databinding.FragmentRecoverMessageBinding;
import com.hdl.photovoltaic.enums.MessageFunctionTabSwitch;
import com.hdl.photovoltaic.listener.CloudCallBeak;
import com.hdl.photovoltaic.other.HdlCommonLogic;
import com.hdl.photovoltaic.other.HdlLogLogic;
import com.hdl.photovoltaic.other.HdlMessageLogic;
import com.hdl.photovoltaic.ui.adapter.MessageAdapter;
import com.hdl.photovoltaic.ui.bean.MessageBean;
import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus;
 
import java.util.ArrayList;
import java.util.List;
 
/**
 * 消息-已恢复
 */
public class RecoverMessageFragment extends CustomBaseFragment {
 
    FragmentRecoverMessageBinding viewBinding;
 
    private MessageAdapter messageRecoverAdapter;
 
    private final List<MessageBean> mList = new ArrayList<>();
 
    @Override
    public Object getContentView() {
        viewBinding = FragmentRecoverMessageBinding.inflate(getLayoutInflater());
        return viewBinding.getRoot();
    }
 
    @Override
    public void onBindView(Bundle savedInstanceState) {
 
        //初始化数据
        initData();
        //初始化界面
        initView();
        //初始化监听器
        initEvent();
    }
 
    private void initData() {
        for (int i = 0; i < 2; i++) {
            MessageBean messageBean = new MessageBean();
//            messageBean.setContent("来了一条告警信息" + i);
            messageBean.setHomeName(i + "");
//            messageBean.setTime("2023-12-06-15");
            messageBean.setRead(false);
            mList.add(messageBean);
        }
    }
 
    private void initEvent() {
        //设置下拉箭头颜色
        viewBinding.messageRecoverSrl.setColorSchemeResources(R.color.text_FF245EC3);
        viewBinding.messageRecoverSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mList.clear();//表示强制重新请求消息列表
                getRecoverMessageList(false);
                HdlLogLogic.print("RecoverMessageFragment下拉刷新", false);
            }
        });
        messageRecoverAdapter.setNoOnclickListener(new MessageAdapter.OnclickListener() {
            @Override
            public void onClick(int position, MessageBean item) {
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putSerializable("message_info", MessageBean.class);
                intent.putExtras(bundle);
                intent.setClass(_mActivity, MessageInfoActivity.class);
                startActivity(intent);
            }
        });
    }
 
    private void initView() {
        viewBinding.messageRecoverRecyclerview.setLayoutManager(new LinearLayoutManager(_mActivity));
        messageRecoverAdapter = new MessageAdapter(this.mList, _mActivity);
        viewBinding.messageRecoverRecyclerview.setAdapter(messageRecoverAdapter);
    }
 
 
    /**
     * 刷新列表数据
     */
    private void updateListData() {
        if (this.messageRecoverAdapter != null) {
            this.messageRecoverAdapter.setList(mList);
            this.messageRecoverAdapter.notifyDataSetChanged();
        }
    }
 
    @Override
    public void onEventMessage(BaseEventBus eventBus) {
        super.onEventMessage(eventBus);
        //接收外部点击事件
        if (eventBus.getTopic().equals(ConstantManage.message_function_tab_switch)) {
            if (eventBus.getType().equals(MessageFunctionTabSwitch.recover.toString())) {
                HdlLogLogic.print("正在点击【已恢复】");
                getRecoverMessageList(true);
            }
        }
    }
 
 
    /**
     * 获取恢复中的消息列表
     *
     * @param isShowLoading 是否启动 true启动
     */
    private void getRecoverMessageList(boolean isShowLoading) {
 
        if (mList.size() == 0) {
            if (isShowLoading) {
                showLoading();
            }
            HdlMessageLogic.getInstance().getMessageList(HdlMessageLogic.MessageStatus.processed, new CloudCallBeak<List<MessageBean>>() {
                @Override
                public void onSuccess(List<MessageBean> list) {
                    if (isShowLoading) {
                        hideLoading();
                    }
                    if (!isShowLoading) {
                        viewBinding.messageRecoverSrl.setRefreshing(false);
                    }
 
                    if (list != null && list.size() != 0) {
                        mList.addAll(list);
                        updateListData();
                    }
                }
 
                @Override
                public void onFailure(HDLException e) {
                    if (isShowLoading) {
                        hideLoading();
                    }
                    if (!isShowLoading) {
                        viewBinding.messageRecoverSrl.setRefreshing(false);
                    }
                }
            });
        }
    }
}