| | |
| | | package com.hdl.photovoltaic.ui.message; |
| | | |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.widget.TextView; |
| | | |
| | | import androidx.recyclerview.widget.LinearLayoutManager; |
| | | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
| | | |
| | | import com.google.gson.Gson; |
| | | 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.enums.MessageStateType; |
| | | 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.other.HdlThreadLogic; |
| | | import com.hdl.photovoltaic.ui.adapter.MessageAdapter; |
| | | import com.hdl.photovoltaic.ui.bean.BUserInfo; |
| | | import com.hdl.photovoltaic.ui.bean.MessageBean; |
| | | import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | | import org.greenrobot.eventbus.Subscribe; |
| | | import org.greenrobot.eventbus.ThreadMode; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | |
| | | private MessageAdapter messageRecoverAdapter; |
| | | |
| | | private List<MessageBean> mList; |
| | | private final List<MessageBean> mList = new ArrayList<>(); |
| | | |
| | | @Override |
| | | public Object getContentView() { |
| | | viewBinding = FragmentRecoverMessageBinding.inflate(getLayoutInflater()); |
| | |
| | | |
| | | @Override |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | |
| | | //初始化数据 |
| | | initData(); |
| | | // initData(); |
| | | //初始化界面 |
| | | initView(); |
| | | //初始化监听器 |
| | |
| | | } |
| | | |
| | | private void initData() { |
| | | mList = new ArrayList<>(); |
| | | for (int i = 0; i < 5; i++) { |
| | | MessageBean messageBean = new MessageBean(); |
| | | messageBean.setContent("来了一条告警信息" + i); |
| | | messageBean.setHomeName(i + ""); |
| | | messageBean.setTime("2023-12-06-15"); |
| | | messageBean.setRead(false); |
| | | mList.add(messageBean); |
| | | } |
| | | mList.clear(); |
| | | mList.addAll(HdlMessageLogic.getInstance().getRecoverMessageMemoryList()); |
| | | } |
| | | |
| | | private void initEvent() { |
| | | //设置下拉箭头颜色 |
| | | viewBinding.messageRecoverSrl.setColorSchemeResources(R.color.text_FF245EC3); |
| | | viewBinding.messageRecoverSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { |
| | | @Override |
| | | public void onRefresh() { |
| | | mList.clear();//表示强制重新请求消息列表 |
| | | updateListData();//清空之前缓存,因为遇到一个问题猛拉的时候报错; |
| | | getRecoverMessageList(false); |
| | | } |
| | | }); |
| | | messageRecoverAdapter.setNoOnclickListener(new MessageAdapter.OnclickListener() { |
| | | @Override |
| | | public void onClick(int position, MessageBean item) { |
| | | |
| | | if (position < 0 || position > mList.size()) { |
| | | return; |
| | | } |
| | | Intent intent = new Intent(); |
| | | intent.putExtra("msgId", item.getMsgId().toString()); |
| | | intent.setClass(_mActivity, MessageInfoActivity.class); |
| | | startActivity(intent); |
| | | } |
| | | }); |
| | | } |
| | |
| | | viewBinding.messageRecoverRecyclerview.setAdapter(messageRecoverAdapter); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 刷新列表数据 |
| | | */ |
| | | private void updateListData() { |
| | | if (this.messageRecoverAdapter != null) { |
| | | this.messageRecoverAdapter.setList(mList); |
| | | this.messageRecoverAdapter.notifyDataSetChanged(); |
| | | } |
| | | |
| | | //刷新【已恢复】信息数量总数 |
| | | this.refreshRecoverCount(); |
| | | this.nullDataUpdateUi(); |
| | | } |
| | | @Override |
| | | |
| | | /** |
| | | * 刷新【已恢复】信息数量总数 |
| | | */ |
| | | private void refreshRecoverCount() { |
| | | HdlThreadLogic.runMainThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | TextView textView = _mActivity.findViewById(R.id.message_tab_recover_title_tv); |
| | | if (textView != null) { |
| | | textView.setText(getText(R.string.message_recover)); |
| | | if (mList.size() > 0) { |
| | | String s = getText(R.string.message_recover) + "(" + mList.size() + ")"; |
| | | textView.setText(s); |
| | | } |
| | | } |
| | | |
| | | } |
| | | }); |
| | | } |
| | | |
| | | @Subscribe(threadMode = ThreadMode.MAIN, sticky = true) |
| | | public void onEventMessage(BaseEventBus eventBus) { |
| | | super.onEventMessage(eventBus); |
| | | if (eventBus == null) { |
| | | return; |
| | | } |
| | | //接收外部点击事件 |
| | | if (eventBus.getTopic().equals(ConstantManage.message_function_tab_switch)) { |
| | | if (eventBus.getType().equals(HdlCommonLogic.MessageFunctionTabSwitch.recover.toString())) { |
| | | HdlLogLogic.print("正在点击【已恢复】"); |
| | | if (eventBus.getType().equals(MessageFunctionTabSwitch.recover.toString())) { |
| | | initData(); |
| | | getRecoverMessageList(true); |
| | | // 取消粘性事件 |
| | | EventBus.getDefault().removeStickyEvent(eventBus); |
| | | } |
| | | } else if (eventBus.getTopic().equals(ConstantManage.message_function_push_post)) { |
| | | if (eventBus.getType().equals(MessageStateType.processed)) { |
| | | //消息详情回调 |
| | | initData(); |
| | | updateListData(); |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取恢复中的消息列表 |
| | | * |
| | | * @param isShowLoading 是否启动 true启动 |
| | | */ |
| | | private void getRecoverMessageList(boolean isShowLoading) { |
| | | |
| | | if (mList.size() == 0) { |
| | | if (isShowLoading) { |
| | | showLoading(); |
| | | } |
| | | HdlMessageLogic.getInstance().getRecoverMessageList(new CloudCallBeak<List<MessageBean>>() { |
| | | @Override |
| | | public void onSuccess(List<MessageBean> list) { |
| | | HdlThreadLogic.runMainThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | 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); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 没有电站列表的样式 |
| | | */ |
| | | 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); |
| | | } |
| | | } |