| | |
| | | |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.os.Handler; |
| | | import android.text.TextUtils; |
| | | import android.view.View; |
| | | 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.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.CustomBaseFragment; |
| | |
| | | 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.HouseIdBean; |
| | | import com.hdl.photovoltaic.ui.bean.MessageBean; |
| | | import com.hdl.photovoltaic.utils.GlideUtils; |
| | | import com.hdl.sdk.link.core.bean.eventbus.BaseEventBus; |
| | | |
| | | import org.greenrobot.eventbus.EventBus; |
| | |
| | | private MessageAdapter messageNascentAdapter; |
| | | |
| | | private final List<MessageBean> mList = new ArrayList<>(); |
| | | |
| | | // 添加上拉加载更多的逻辑 |
| | | private int visibleThreshold = 5; // 当前显示的最后一项与总共有多少条数据之间的差值 |
| | | private int currentPage = 1; // 当前页码 |
| | | private boolean isLoadingMore = false; // 标记正在加载更多数据 |
| | | |
| | | LinearLayoutManager layoutManager; |
| | | |
| | | @Override |
| | | public Object getContentView() { |
| | |
| | | |
| | | } |
| | | }); |
| | | viewBinding.messageNascentRecyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() { |
| | | @Override |
| | | public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { |
| | | super.onScrolled(recyclerView, dx, dy); |
| | | |
| | | // int totalItemCount = layoutManager.getItemCount(); |
| | | // int lastVisibleItemPosition = layoutManager.findLastVisibleItemPosition(); |
| | | // |
| | | // if (!isLoadingMore && totalItemCount <= (lastVisibleItemPosition + visibleThreshold)) { |
| | | // loadNextPage(); |
| | | // } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | private void initView() { |
| | | viewBinding.messageNascentRecyclerview.setLayoutManager(new LinearLayoutManager(_mActivity)); |
| | | layoutManager = new LinearLayoutManager(_mActivity); |
| | | viewBinding.messageNascentRecyclerview.setLayoutManager(layoutManager); |
| | | messageNascentAdapter = new MessageAdapter(this.mList, _mActivity); |
| | | viewBinding.messageNascentRecyclerview.setAdapter(messageNascentAdapter); |
| | | } |
| | |
| | | this.messageNascentAdapter.setList(mList); |
| | | this.messageNascentAdapter.notifyDataSetChanged(); |
| | | } |
| | | //刷新【发生中】信息数量总数 |
| | | this.refreshNascentCount(); |
| | | this.nullDataUpdateUi(); |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 刷新【发生中】信息数量总数 |
| | | */ |
| | | private void refreshNascentCount() { |
| | | HdlThreadLogic.runMainThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | TextView textView = _mActivity.findViewById(R.id.message_tab_nascent_title_tv); |
| | | if (textView != null) { |
| | | textView.setText(getText(R.string.message_nascent)); |
| | | if (mList.size() > 0) { |
| | | String s = getText(R.string.message_nascent) + "(" + 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(MessageFunctionTabSwitch.nascent.toString())) { |
| | | initData(); |
| | | getNascentMessageList(true); |
| | | getUnreadCount(); |
| | | // 取消粘性事件 |
| | | EventBus.getDefault().removeStickyEvent(eventBus); |
| | | |
| | | } |
| | | |
| | | } else if (eventBus.getTopic().equals(ConstantManage.message_function_push_post)) { |
| | |
| | | //消息详情回调 |
| | | initData(); |
| | | updateListData(); |
| | | getUnreadCount(); |
| | | } |
| | | } |
| | | } |
| | |
| | | /** |
| | | * 获取发生中的消息列表 |
| | | * |
| | | * @param isShowLoading 是否启动 true启动 |
| | | * @param isShowLoading 是否启动加载框 true启动 |
| | | */ |
| | | private void getNascentMessageList(boolean isShowLoading) { |
| | | if (mList.size() == 0) { |
| | |
| | | }); |
| | | } |
| | | } |
| | | |
| | | // private void loadNextPage() { |
| | | // isLoadingMore = true; |
| | | // |
| | | // // 模拟网络请求获取新的数据 |
| | | // Handler handler = new Handler(); |
| | | // handler.postDelayed(() -> { |
| | | // List<MessageBean> newData = fetchNewDataFromServer(currentPage++); |
| | | // messageNascentAdapter.setList(newData); |
| | | // isLoadingMore = false; |
| | | // }, 2000); |
| | | // } |
| | | // |
| | | // private List<MessageBean> fetchNewDataFromServer(int pageNumber) { |
| | | // // TODO: 从服务器获取新的数据并返回 |
| | | // pageNumber++; |
| | | // List<MessageBean> newData = HdlMessageLogic.getInstance().getAllMessageList(); |
| | | // return newData; |
| | | // } |
| | | |
| | | /** |
| | | * 读取消息【未读数量】 |
| | | */ |
| | | private void getUnreadCount() { |
| | | HdlMessageLogic.getInstance().getMessageUntreatedCount(new CloudCallBeak<String>() { |
| | | @Override |
| | | public void onSuccess(String data) { |
| | | |
| | | HdlThreadLogic.runMainThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | JSONObject jsonObject = JSON.parseObject(data); |
| | | // if (jsonObject.containsKey("untreatedCount")) { |
| | | // //未处理数量 |
| | | // jsonObject.getString("untreatedCount"); |
| | | // } |
| | | String unreadCount = "0"; |
| | | if (jsonObject.containsKey("unreadCount")) { |
| | | //未读数量 |
| | | unreadCount = jsonObject.getString("unreadCount"); |
| | | } |
| | | 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 { |
| | | if (unreadCount.length() > 2) { |
| | | //大于3位数,默认99+ |
| | | unreadCount = "99+"; |
| | | } |
| | | textView.setVisibility(View.VISIBLE); |
| | | textView.setText(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 nullDataUpdateUi() { |
| | | HdlCommonLogic.getInstance().nullDataUpdateUi(_mActivity, |
| | | viewBinding.nullDataIc.getRoot(), |
| | | viewBinding.nullDataIc.nullDataGifAnimationIv, |
| | | viewBinding.nullDataIc.nullDataTv, getString(R.string.message_alarm_data_null), mList.size() > 0); |
| | | } |
| | | } |