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 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 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.messageTabAllGradeCl.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { List 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) { } }); } }); //全部时间(当天、近3天、近7天、近30天)按钮 viewBinding.messageTabAllTimeCl.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { List 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.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); 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() { @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() { @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); } }