From 3aa86eda8f416bec308d065689d39c847d2d9cc7 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期二, 30 一月 2024 19:48:26 +0800 Subject: [PATCH] 2024年01月30日19:44:13 --- app/src/main/java/com/hdl/photovoltaic/ui/message/RecoverMessageFragment.java | 209 ++++++++++++++++++++++++++++++++-------------------- 1 files changed, 128 insertions(+), 81 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 0aad188..74aa78b 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 @@ -4,7 +4,9 @@ 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; @@ -40,6 +42,12 @@ FragmentRecoverMessageBinding viewBinding; private MessageAdapter messageRecoverAdapter; + private int currentPage = 0; // 褰撳墠椤电爜 + private int total = 0; // 鏈�鍚庨〉鐮� + + private int totalCount = 0;//娑堟伅鏁伴噺鎬绘暟 + + private boolean isLoadingMore = false; // 鏍囪姝e湪鍔犺浇鏇村鏁版嵁 private final List<MessageBean> mList = new ArrayList<>(); @@ -71,9 +79,10 @@ viewBinding.messageRecoverSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { - mList.clear();//琛ㄧず寮哄埗閲嶆柊璇锋眰娑堟伅鍒楄〃 - updateListData();//娓呯┖涔嬪墠缂撳瓨,鍥犱负閬囧埌涓�涓棶棰樼寷鎷夌殑鏃跺�欐姤閿�; - getRecoverMessageList(false); + viewBinding.messageRecoverSrl.setRefreshing(false); +// mList.clear();//琛ㄧず寮哄埗閲嶆柊璇锋眰娑堟伅鍒楄〃 +// updateListData();//娓呯┖涔嬪墠缂撳瓨,鍥犱负閬囧埌涓�涓棶棰樼寷鎷夌殑鏃跺�欐姤閿�; +// getRecoverMessageList(false); } }); messageRecoverAdapter.setNoOnclickListener(new MessageAdapter.OnclickListener() { @@ -88,7 +97,30 @@ 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)); @@ -101,15 +133,99 @@ * 鍒锋柊鍒楄〃鏁版嵁 */ private void updateListData() { - if (this.messageRecoverAdapter != null) { - this.messageRecoverAdapter.setList(mList); - this.messageRecoverAdapter.notifyDataSetChanged(); - } - //鍒锋柊銆愬凡鎭㈠銆戜俊鎭暟閲忔�绘暟 - this.refreshRecoverCount(); - this.nullDataUpdateUi(); + HdlThreadLogic.runMainThread(new Runnable() { + @Override + public void run() { + //鏇存柊缂撳瓨鏁版嵁 + initData(); + //鍒锋柊鍒楄〃 + 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())) { + initData(); + 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(); + } + } + }); + } + /** * 鍒锋柊銆愬凡鎭㈠銆戜俊鎭暟閲忔�绘暟 @@ -122,83 +238,13 @@ if (textView != null) { textView.setText(getText(R.string.message_recover)); if (mList.size() > 0) { - String s = getText(R.string.message_recover) + "(" + mList.size() + ")"; + String s = getText(R.string.message_recover) + "(" + totalCount + ")"; 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.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); - } - } - }); - } } /** @@ -210,4 +256,5 @@ viewBinding.nullDataIc.nullDataGifAnimationIv, viewBinding.nullDataIc.nullDataTv, getString(R.string.message_alarm_data_null), mList.size() > 0); } + } -- Gitblit v1.8.0