From be5c9f324ac1d31f4f262d288c5f72a7a0c10c47 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期五, 19 一月 2024 10:08:23 +0800
Subject: [PATCH] 2024年01月19日10:08:08

---
 app/src/main/java/com/hdl/photovoltaic/ui/message/NascentMessageFragment.java |  159 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 157 insertions(+), 2 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 1568045..10c2b79 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,10 +3,19 @@
 
 import android.content.Intent;
 import android.os.Bundle;
+import android.os.Handler;
+import android.text.TextUtils;
+import android.view.MotionEvent;
+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;
@@ -15,10 +24,14 @@
 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;
@@ -37,6 +50,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() {
@@ -83,10 +103,36 @@
 
             }
         });
+
+        viewBinding.messageNascentRecyclerview.addOnScrollListener(new RecyclerView.OnScrollListener() {
+            @Override
+            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
+                super.onScrolled(recyclerView, dx, dy);
+
+                if (dy <= 0) {
+                    //绛変簬0鏄《閮�
+                    return;
+                }
+                LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
+                assert layoutManager != null;
+                // 鍙湁鍨傜洿甯冨眬鎵嶄細瑙﹀彂涓婃媺浜嬩欢
+                if (!layoutManager.canScrollVertically()) {
+                    return;
+                }
+
+                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);
     }
@@ -99,18 +145,47 @@
             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)) {
@@ -118,6 +193,7 @@
                 //娑堟伅璇︽儏鍥炶皟
                 initData();
                 updateListData();
+                getUnreadCount();
             }
         }
     }
@@ -125,7 +201,7 @@
     /**
      * 鑾峰彇鍙戠敓涓殑娑堟伅鍒楄〃
      *
-     * @param isShowLoading 鏄惁鍚姩 true鍚姩
+     * @param isShowLoading 鏄惁鍚姩鍔犺浇妗� true鍚姩
      */
     private void getNascentMessageList(boolean isShowLoading) {
         if (mList.size() == 0) {
@@ -166,4 +242,83 @@
             });
         }
     }
+
+//    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);
+    }
 }

--
Gitblit v1.8.0