| | |
| | | |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.widget.TextView; |
| | | |
| | | import androidx.annotation.NonNull; |
| | | import androidx.recyclerview.widget.LinearLayoutManager; |
| | | import androidx.recyclerview.widget.RecyclerView; |
| | | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
| | | |
| | | import com.google.gson.Gson; |
| | |
| | | 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; |
| | |
| | | FragmentRecoverMessageBinding viewBinding; |
| | | |
| | | private MessageAdapter messageRecoverAdapter; |
| | | private int currentPage = 0; // 当前页码 |
| | | private int total = 0; // 最后页码 |
| | | |
| | | private int totalCount = 0;//消息数量总数 |
| | | |
| | | private boolean isLoadingMore = false; // 标记正在加载更多数据 |
| | | |
| | | private final List<MessageBean> mList = new ArrayList<>(); |
| | | |
| | |
| | | viewBinding.messageRecoverSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { |
| | | @Override |
| | | public void onRefresh() { |
| | | mList.clear();//表示强制重新请求消息列表 |
| | | getRecoverMessageList(false); |
| | | HdlLogLogic.print("RecoverMessageFragment下拉刷新", false); |
| | | viewBinding.messageRecoverSrl.setRefreshing(false); |
| | | // mList.clear();//表示强制重新请求消息列表 |
| | | // updateListData();//清空之前缓存,因为遇到一个问题猛拉的时候报错; |
| | | // getRecoverMessageList(false); |
| | | } |
| | | }); |
| | | messageRecoverAdapter.setNoOnclickListener(new MessageAdapter.OnclickListener() { |
| | |
| | | startActivity(intent); |
| | | } |
| | | }); |
| | | |
| | | viewBinding.messageRecoverRecyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() { |
| | | @Override |
| | | public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { |
| | | // super.onScrolled(recyclerView, dx, dy); |
| | | |
| | | LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager(); |
| | | if (layoutManager == null) { |
| | | return; |
| | | } |
| | | int visibleItemCount = layoutManager.getChildCount(); |
| | | int totalItemCount = layoutManager.getItemCount(); |
| | | int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition(); |
| | | if (visibleItemCount > 0 && visibleItemCount + firstVisibleItemPosition == totalItemCount) { |
| | | if (!isLoadingMore) { |
| | | // 滑动到了底部,执行相应的操作 |
| | | HdlLogLogic.print("--->滑动到了底部"); |
| | | loadNextPageRecoverMessageList(++currentPage, false); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | private void initView() { |
| | | viewBinding.messageRecoverRecyclerview.setLayoutManager(new LinearLayoutManager(_mActivity)); |
| | |
| | | * 刷新列表数据 |
| | | */ |
| | | private void updateListData() { |
| | | if (this.messageRecoverAdapter != null) { |
| | | this.messageRecoverAdapter.setList(mList); |
| | | this.messageRecoverAdapter.notifyDataSetChanged(); |
| | | } |
| | | |
| | | HdlThreadLogic.runMainThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | //更新缓存数据 |
| | | initData(); |
| | | //刷新列表 |
| | | if (messageRecoverAdapter != null) { |
| | | messageRecoverAdapter.setList(mList); |
| | | messageRecoverAdapter.notifyDataSetChanged(); |
| | | } |
| | | //刷新【已恢复】信息数量总数 |
| | | refreshRecoverCount(); |
| | | //显示没数据Ui样式 |
| | | nullDataUpdateUi(); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | |
| | | @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(MessageFunctionTabSwitch.recover.toString())) { |
| | | HdlLogLogic.print("正在点击【已恢复】"); |
| | | initData(); |
| | | getRecoverMessageList(true); |
| | | loadNextPageRecoverMessageList(1, true); |
| | | // 取消粘性事件 |
| | | EventBus.getDefault().removeStickyEvent(eventBus); |
| | | } |
| | | } else if (eventBus.getTopic().equals(ConstantManage.message_function_push_post)) { |
| | | if (eventBus.getType().equals(MessageStateType.processed)) { |
| | | //消息详情回调 |
| | | initData(); |
| | | ++totalCount; |
| | | updateListData(); |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 加载一页数据 |
| | | * |
| | | * @param pageNo 页数 |
| | | * @param isShowLoading 是否启动加载框 true启动 |
| | | */ |
| | | private void loadNextPageRecoverMessageList(int pageNo, boolean isShowLoading) { |
| | | if (pageNo == 1 && mList.size() > 0) { |
| | | //缓存数据没有才可以读取第一页 |
| | | return; |
| | | } |
| | | if (currentPage > total) { |
| | | //当前页不能大于总页数 |
| | | return; |
| | | } |
| | | isLoadingMore = true;//标记读取状态 |
| | | if (isShowLoading) { |
| | | showLoading(); |
| | | } |
| | | HdlMessageLogic.getInstance().getPageNoMessageList(pageNo, MessageStateType.processed, new CloudCallBeak<HdlMessageLogic.MessageListClass>() { |
| | | @Override |
| | | public void onSuccess(HdlMessageLogic.MessageListClass messageListClass) { |
| | | if (messageListClass != null) { |
| | | total = (int) messageListClass.getTotalPage(); |
| | | currentPage = (int) messageListClass.getPageNo(); |
| | | totalCount = (int) messageListClass.getTotalCount(); |
| | | updateListData(); |
| | | } |
| | | isLoadingMore = false; |
| | | if (isShowLoading) { |
| | | hideLoading(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public void onFailure(HDLException e) { |
| | | if (currentPage > 1) { |
| | | --currentPage; |
| | | } |
| | | isLoadingMore = false; |
| | | if (isShowLoading) { |
| | | hideLoading(); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取恢复中的消息列表 |
| | | * |
| | | * @param isShowLoading 是否启动 true启动 |
| | | * 刷新【已恢复】信息数量总数 |
| | | */ |
| | | private void getRecoverMessageList(boolean isShowLoading) { |
| | | 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) + "(" + totalCount + ")"; |
| | | textView.setText(s); |
| | | } |
| | | } |
| | | |
| | | if (mList.size() == 0) { |
| | | if (isShowLoading) { |
| | | showLoading(); |
| | | } |
| | | HdlMessageLogic.getInstance().getRecoverMessageList(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); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 没有电站列表的样式 |
| | | */ |
| | | 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); |
| | | } |
| | | |
| | | } |