From 0b6f27a6aeeb6eb3d5ee55b500797875c2bd5d2c Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期二, 12 三月 2024 21:08:03 +0800 Subject: [PATCH] 2024年03月12日21:07:52 --- app/src/main/java/com/hdl/photovoltaic/ui/message/RecoverMessageFragment.java | 241 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 240 insertions(+), 1 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/message/RecoverMessageFragment.java b/app/src/main/java/com/hdl/photovoltaic/ui/message/RecoverMessageFragment.java index 3a13ff1..e42864b 100644 --- a/app/src/main/java/com/hdl/photovoltaic/ui/message/RecoverMessageFragment.java +++ b/app/src/main/java/com/hdl/photovoltaic/ui/message/RecoverMessageFragment.java @@ -1,20 +1,259 @@ package com.hdl.photovoltaic.ui.message; +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.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; /** * 娑堟伅-宸叉仮澶� */ public class RecoverMessageFragment extends CustomBaseFragment { + + FragmentRecoverMessageBinding viewBinding; + + private MessageAdapter messageRecoverAdapter; + private int currentPage = 0; // 褰撳墠椤电爜 + private int currentTotal = 0; // 鎬婚〉鐮� + + private int totalCount = 0;//娑堟伅鏁伴噺鎬绘暟 + + private boolean isLoadingMore = false; // 鏍囪姝e湪鍔犺浇鏇村鏁版嵁 + + private final List<MessageBean> mList = new ArrayList<>(); + @Override public Object getContentView() { - return null; + viewBinding = FragmentRecoverMessageBinding.inflate(getLayoutInflater()); + return viewBinding.getRoot(); } @Override public void onBindView(Bundle savedInstanceState) { + //鍒濆鍖栫晫闈� + initView(); + //鍒濆鍖栫洃鍚櫒 + initEvent(); + //杩涙潵璇诲彇涓�娆℃暟鎹�(涓轰簡鏇存柊currentPage锛宑urrentTotal杩欎釜鍊�) + loadNextPageRecoverMessageList(1, true); + } + + /** + * 鏇存柊鏈湴缂撳瓨鏁版嵁 + */ + private void updatelocalityCacheData() { + 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() { + viewBinding.messageRecoverSrl.setRefreshing(false); + mList.clear();//琛ㄧず寮哄埗閲嶆柊璇锋眰绗竴椤垫秷鎭垪琛� + HdlMessageLogic.getInstance().clearListMessage();//琛ㄧず寮哄埗娓呯┖鎵�鏈夌紦瀛樹俊鎭� + loadNextPageRecoverMessageList(1, true); + } + }); + 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.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)); + messageRecoverAdapter = new MessageAdapter(this.mList, _mActivity); + viewBinding.messageRecoverRecyclerview.setAdapter(messageRecoverAdapter); + } + + + /** + * 鍒锋柊鍒楄〃鏁版嵁 + */ + private void updateListData() { + + HdlThreadLogic.runMainThread(new Runnable() { + @Override + public void run() { + //鏇存柊鏈湴缂撳瓨鏁版嵁 + updatelocalityCacheData(); + //鍒锋柊鍒楄〃 + if (messageRecoverAdapter != null) { + messageRecoverAdapter.setList(mList); + messageRecoverAdapter.notifyDataSetChanged(); + } + //鍒锋柊銆愬凡鎭㈠銆戜俊鎭暟閲忔�绘暟 + refreshRecoverCount(); + //鏄剧ず娌℃暟鎹甎i鏍峰紡 + nullDataUpdateUi(); + } + }); + + } + + + @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())) { + // 鍙栨秷绮樻�т簨浠� + EventBus.getDefault().removeStickyEvent(eventBus); + } + } else if (eventBus.getTopic().equals(ConstantManage.message_function_push_post)) { + if (eventBus.getType().equals(MessageStateType.processed)) { + //娑堟伅璇︽儏鍥炶皟 + updatelocalityCacheData(); + ++totalCount; + updateListData(); + + } + } + } + + /** + * 鍔犺浇涓�椤垫暟鎹� + * + * @param pageNo 椤垫暟 + * @param isShowLoading 鏄惁鍚姩鍔犺浇妗� true鍚姩 + */ + private void loadNextPageRecoverMessageList(int pageNo, boolean isShowLoading) { + //绗竴椤佃鍙栨暟鎹己鍒惰 + if (pageNo > 1 && currentPage > currentTotal) { + --currentPage; + //褰撳墠椤典笉鑳藉ぇ浜庢�婚〉鏁� + 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) { + currentTotal = (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(); + } + } + }); + } + + + /** + * 鍒锋柊銆愬凡鎭㈠銆戜俊鎭暟閲忔�绘暟 + */ + 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); + } + } + + } + }); + } + + /** + * 娌℃湁鐢电珯鍒楄〃鐨勬牱寮� + */ + 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); + } + } -- Gitblit v1.8.0