From dbff6d6f9200417ea60e2fe507b79cbe2eb7ea32 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期四, 11 一月 2024 18:19:48 +0800
Subject: [PATCH] 2024年01月11日18:19:42
---
app/src/main/java/com/hdl/photovoltaic/ui/message/NascentMessageFragment.java | 95 +++++++++++++++++++++++++++++++++++++++++------
1 files changed, 83 insertions(+), 12 deletions(-)
diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/message/NascentMessageFragment.java b/app/src/main/java/com/hdl/photovoltaic/ui/message/NascentMessageFragment.java
index a04dbdf..3388a68 100644
--- a/app/src/main/java/com/hdl/photovoltaic/ui/message/NascentMessageFragment.java
+++ b/app/src/main/java/com/hdl/photovoltaic/ui/message/NascentMessageFragment.java
@@ -3,8 +3,11 @@
import android.content.Intent;
import android.os.Bundle;
+import android.os.Handler;
+import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import com.hdl.linkpm.sdk.core.exception.HDLException;
@@ -15,10 +18,16 @@
import com.hdl.photovoltaic.enums.MessageFunctionTabSwitch;
import com.hdl.photovoltaic.enums.MessageStateType;
import com.hdl.photovoltaic.listener.CloudCallBeak;
+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.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;
@@ -32,6 +41,13 @@
private MessageAdapter messageNascentAdapter;
private final List<MessageBean> mList = new ArrayList<>();
+
+ // 娣诲姞涓婃媺鍔犺浇鏇村鐨勯�昏緫
+ private int visibleThreshold = 5; // 褰撳墠鏄剧ず鐨勬渶鍚庝竴椤逛笌鎬诲叡鏈夊灏戞潯鏁版嵁涔嬮棿鐨勫樊鍊�
+ private int currentPage = 1; // 褰撳墠椤电爜
+ private boolean isLoadingMore = false; // 鏍囪姝e湪鍔犺浇鏇村鏁版嵁
+
+ LinearLayoutManager layoutManager;
@Override
public Object getContentView() {
@@ -61,6 +77,7 @@
@Override
public void onRefresh() {
mList.clear();//琛ㄧず寮哄埗閲嶆柊璇锋眰娑堟伅鍒楄〃
+ updateListData();//娓呯┖涔嬪墠缂撳瓨,鍥犱负閬囧埌涓�涓棶棰樼寷鎷夌殑鏃跺�欐姤閿�;
getNascentMessageList(false);
}
});
@@ -77,10 +94,24 @@
}
});
+ 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);
}
@@ -93,20 +124,35 @@
this.messageNascentAdapter.setList(mList);
this.messageNascentAdapter.notifyDataSetChanged();
}
+
+ if (mList.size() > 0) {
+ BaseEventBus baseEventBus = new BaseEventBus();
+ baseEventBus.setTopic(ConstantManage.message_count);
+ baseEventBus.setType(MessageStateType.untreated);
+ baseEventBus.setData(mList.size());
+ EventBus.getDefault().post(baseEventBus);
+ }
+
}
- @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.nascent.toString())) {
initData();
getNascentMessageList(true);
+ // 鍙栨秷绮樻�т簨浠�
+ EventBus.getDefault().removeStickyEvent(eventBus);
}
} else if (eventBus.getTopic().equals(ConstantManage.message_function_push_post)) {
if (eventBus.getType().equals(MessageStateType.untreated)) {
+ //娑堟伅璇︽儏鍥炶皟
initData();
updateListData();
}
@@ -126,17 +172,23 @@
HdlMessageLogic.getInstance().getNascentMessageList(new CloudCallBeak<List<MessageBean>>() {
@Override
public void onSuccess(List<MessageBean> list) {
- if (isShowLoading) {
- hideLoading();
- }
- if (!isShowLoading) {
- viewBinding.messageNascentSrl.setRefreshing(false);
- }
+ HdlThreadLogic.runMainThread(new Runnable() {
+ @Override
+ public void run() {
+ if (isShowLoading) {
+ hideLoading();
+ }
+ if (!isShowLoading) {
+ viewBinding.messageNascentSrl.setRefreshing(false);
+ }
- if (list != null && list.size() != 0) {
- mList.addAll(list);
- updateListData();
- }
+ if (list != null && list.size() != 0) {
+ mList.addAll(list);
+ updateListData();
+ }
+ }
+ });
+
}
@Override
@@ -151,4 +203,23 @@
});
}
}
+
+// 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;
+// }
}
--
Gitblit v1.8.0