From 5d3efa4c93dde0cde474951e5310bb72ebbf4184 Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 07 五月 2025 15:18:26 +0800
Subject: [PATCH] 2025年05月07日15:18:20 1.2.0

---
 app/src/main/java/com/hdl/photovoltaic/ui/message/SearchMessageActivity.java |  347 ++++++++++++++++++++++++++++++++++++++-------------------
 1 files changed, 229 insertions(+), 118 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/message/SearchMessageActivity.java b/app/src/main/java/com/hdl/photovoltaic/ui/message/SearchMessageActivity.java
index aecfe33..944fd6d 100644
--- a/app/src/main/java/com/hdl/photovoltaic/ui/message/SearchMessageActivity.java
+++ b/app/src/main/java/com/hdl/photovoltaic/ui/message/SearchMessageActivity.java
@@ -1,11 +1,17 @@
 package com.hdl.photovoltaic.ui.message;
 
 
+import android.content.Context;
+import android.content.Intent;
+import android.os.AsyncTask;
 import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
 import android.text.Editable;
 import android.text.TextUtils;
 import android.text.TextWatcher;
 import android.view.View;
+import android.view.inputmethod.InputMethodManager;
 
 import androidx.annotation.NonNull;
 import androidx.recyclerview.widget.LinearLayoutManager;
@@ -17,17 +23,19 @@
 import com.hdl.linkpm.sdk.core.exception.HDLException;
 import com.hdl.photovoltaic.R;
 import com.hdl.photovoltaic.base.CustomBaseActivity;
-import com.hdl.photovoltaic.bean.PageNumberObject;
 import com.hdl.photovoltaic.databinding.ActivitySearchMessgeBinding;
-import com.hdl.photovoltaic.enums.ShowErrorMode;
 import com.hdl.photovoltaic.listener.CloudCallBeak;
-import com.hdl.photovoltaic.other.HdlDeviceLogic;
+import com.hdl.photovoltaic.other.HdlCommonLogic;
 import com.hdl.photovoltaic.other.HdlFileLogic;
 import com.hdl.photovoltaic.other.HdlLogLogic;
+import com.hdl.photovoltaic.other.HdlMessageLogic;
 import com.hdl.photovoltaic.other.HdlThreadLogic;
 import com.hdl.photovoltaic.ui.adapter.SearchHistoryAdapter;
 import com.hdl.photovoltaic.ui.adapter.SearchMessageAdapter;
-import com.hdl.photovoltaic.ui.bean.DeviceBean;
+import com.hdl.photovoltaic.ui.bean.MessageBean;
+import com.hdl.photovoltaic.utils.KeyboardStateObserverUtils;
+import com.hdl.photovoltaic.widget.refreshlayout.BGARefreshLayout;
+import com.hdl.photovoltaic.widget.refreshlayout.HDLRefreshViewHolder;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -38,20 +46,24 @@
  */
 public class SearchMessageActivity extends CustomBaseActivity {
 
+    private Handler handler;
+    private Runnable delayedRunnable;
+
     private ActivitySearchMessgeBinding viewBinding;
 
     SearchMessageAdapter searchMessageAdapter;//璁惧閫傞厤鍣�
     SearchHistoryAdapter searchHistoryAdapter;//鍘嗗彶璁板綍閫傞厤鍣�
 
-    private List<DeviceBean> deviceList = new ArrayList<>();
-
-    private int currentHouseListPage = 0; // 褰撳墠鐢电珯鍒楄〃椤电爜
-    private int currentHouseListTotal = 0; // 鐢电珯鍒楄〃鎬婚〉鐮�
-    private boolean isHouseLoadingMore = false; // 鏍囪鐢电珯鍒楄〃姝e湪鍔犺浇鏇村鏁版嵁
+    private final List<MessageBean> mList = new ArrayList<>();
+    private int mCurrentPage = 0; // 褰撳墠椤电爜
+    private int mCurrentTotal = 0; // 鎬婚〉鐮�
+    private boolean isLoadingMore = false; // 鏍囪姝e湪鍔犺浇鏇村鏁版嵁
 
     private String currSearchText;
 
     List<String> searchHistoryTitleList = new ArrayList<>();
+
+    String mMessageStateType = "";
 
     @Override
     public Object getContentView() {
@@ -62,6 +74,8 @@
     @Override
     public void onBindView(Bundle savedInstanceState) {
         setStatusBarTranslucent();
+        getWindow().setNavigationBarColor(getColor(R.color.text_FF000000));
+        mMessageStateType = getIntent().getStringExtra("MessageStateType");
         //鍘嗗彶璁板綍鏂囦欢澶瑰垱寤�
         HdlFileLogic.getInstance().createFileDir(HdlFileLogic.getInstance().getCurrentUserRootPath());
         //鍒濆鍖栨暟鎹�
@@ -84,6 +98,53 @@
         }
     }
 
+    /**
+     * 涓嬫媺鍒锋柊鐨勯�昏緫
+     */
+    protected void pullToRefresh() {
+        viewBinding.listSrl.setDelegate(new BGARefreshLayout.BGARefreshLayoutDelegate() {
+            @Override
+            public void onBGARefreshLayoutBeginRefreshing(BGARefreshLayout refreshLayout) {
+                handler = new Handler(Looper.getMainLooper());
+
+                delayedRunnable = new Runnable() {
+                    @Override
+                    public void run() {
+                        viewBinding.listSrl.endRefreshing();
+                        loadNextPageMessageList(false, 1, viewBinding.messageSearchEt.getText().toString(), true);
+                    }
+                };
+                // 寤惰繜 5 绉掓墽琛�
+                handler.postDelayed(delayedRunnable, 1000);
+            }
+
+
+            @Override
+            public boolean onBGARefreshLayoutBeginLoadingMore(BGARefreshLayout refreshLayout) {
+
+                handler = new Handler(Looper.getMainLooper());
+                delayedRunnable = new Runnable() {
+                    @Override
+                    public void run() {
+                        viewBinding.listSrl.endLoadingMore();
+                        if (!isLoadingMore) {
+                            // 婊戝姩鍒颁簡搴曢儴锛屾墽琛岀浉搴旂殑鎿嶄綔
+                            loadNextPageMessageList(false, ++mCurrentPage, viewBinding.messageSearchEt.getText().toString(), false);
+                        }
+                    }
+                };
+                // 寤惰繜 5 绉掓墽琛�
+                handler.postDelayed(delayedRunnable, 10);
+
+                return true;
+            }
+        });
+        HDLRefreshViewHolder hdlRefreshViewHolder = new HDLRefreshViewHolder(_mActivity, true);
+        hdlRefreshViewHolder.setPullDownImageResource(R.mipmap.loading_44);
+        hdlRefreshViewHolder.setChangeToReleaseRefreshAnimResId(R.drawable.loading_refresh);
+        hdlRefreshViewHolder.setRefreshingAnimResId(R.drawable.loading_refresh_end);
+        viewBinding.listSrl.setRefreshViewHolder(hdlRefreshViewHolder);
+    }
 
     private void initEvent() {
 
@@ -95,8 +156,6 @@
             }
         });
         viewBinding.messageSearchEt.addTextChangedListener(textWatcher);
-
-
         //鎼滅储
         viewBinding.powerStationSearchTv.setOnClickListener(new View.OnClickListener() {
             @Override
@@ -107,42 +166,12 @@
                     HdlThreadLogic.toast(_mActivity, R.string.search_content_null);
                     return;
                 }
+                viewBinding.messageSearchEt.clearFocus();
+                hideSoftInputFromWindow();
                 viewBinding.historyListParent.setVisibility(View.GONE);
                 viewBinding.listParent.setVisibility(View.VISIBLE);
                 addSearchTextToList();
-                loadNextPageHouseList(true, 1, true);
-            }
-        });
-
-
-        //涓嬫媺绠ご棰滆壊
-        viewBinding.listSrl.setColorSchemeResources(R.color.text_FF245EC3);
-        //涓嬫媺璇诲彇
-        viewBinding.listSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
-            @Override
-            public void onRefresh() {
-                viewBinding.listSrl.setRefreshing(false);
-                loadNextPageHouseList(true, 1, true);
-            }
-        });
-        //涓婃媺璇诲彇
-        viewBinding.listRcv.addOnScrollListener(new RecyclerView.OnScrollListener() {
-            @Override
-            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int 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 (!isHouseLoadingMore) {
-                        // 婊戝姩鍒颁簡搴曢儴锛屾墽琛岀浉搴旂殑鎿嶄綔
-                        HdlLogLogic.print("--->婊戝姩鍒颁簡搴曢儴");
-                        loadNextPageHouseList(false, ++currentHouseListPage, false);
-                    }
-                }
+                loadNextPageMessageList(true, 1, viewBinding.messageSearchEt.getText().toString(), true);
             }
         });
         //娓呴櫎
@@ -152,17 +181,23 @@
                 currSearchText = "";
                 viewBinding.messageSearchEt.setText("");
                 viewBinding.historyListParent.setVisibility(View.VISIBLE);
+                viewBinding.deviceNullDataIc.getRoot().setVisibility(View.GONE);
                 viewBinding.listParent.setVisibility(View.GONE);
                 searchHistoryAdapter.setList(searchHistoryTitleList);
-                clearData();
+                clearCacheData();
+                viewBinding.messageSearchEt.requestFocus();
+                showSoftInput();
             }
         });
         //鍒犻櫎
         viewBinding.messageDelIv.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
+                viewBinding.messageSearchEt.clearFocus();
+                hideSoftInputFromWindow();
                 searchHistoryTitleList = new ArrayList<>();
                 searchHistoryAdapter.setList(searchHistoryTitleList);
+                viewBinding.deviceNullDataIc.getRoot().setVisibility(View.GONE);
                 HdlFileLogic.getInstance().deleteFile(getHistoryFileNamePath());
             }
         });
@@ -171,16 +206,48 @@
             @Override
             public void onClick(int position, String title) {
                 viewBinding.messageSearchEt.setText(title);
+                //鎼滅储鍏抽敭瀛�
+                currSearchText = viewBinding.messageSearchEt.getText().toString().replace(" ", "");
+                if (TextUtils.isEmpty(currSearchText)) {
+                    HdlThreadLogic.toast(_mActivity, R.string.search_content_null);
+                    return;
+                }
+                viewBinding.messageSearchEt.clearFocus();
+                hideSoftInputFromWindow();
+                viewBinding.historyListParent.setVisibility(View.GONE);
+                viewBinding.listParent.setVisibility(View.VISIBLE);
+                addSearchTextToList();
+                loadNextPageMessageList(true, 1, viewBinding.messageSearchEt.getText().toString(), true);
             }
         });
-        //鐢电珯鐐瑰嚮鏄簨浠�
+        //娑堟伅鐐瑰嚮鏄簨浠�
         searchMessageAdapter.setOnclickListener(new SearchMessageAdapter.OnClickListener() {
             @Override
-            public void onClick(int position, DeviceBean deviceBean) {
-
+            public void onClick(int position, MessageBean messageBean) {
+                Intent intent = new Intent();
+                intent.putExtra("messageBean", new Gson().toJson(messageBean));
+                intent.setClass(_mActivity, MessageInfoActivity.class);
+                startActivity(intent);
             }
         });
 
+    }
+
+    /**
+     * 鏄剧ず杞敭鐩�
+     */
+    public void showSoftInput() {
+        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+        inputMethodManager.showSoftInput(viewBinding.messageSearchEt, 0);
+
+    }
+
+    /**
+     * 闅愯棌杞敭鐩�
+     */
+    public void hideSoftInputFromWindow() {
+        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+        inputMethodManager.hideSoftInputFromWindow(viewBinding.getRoot().getWindowToken(), 0);
     }
 
     private void initView() {
@@ -192,10 +259,34 @@
         viewBinding.historyListRcv.setLayoutManager(new LinearLayoutManager(_mActivity));
         viewBinding.historyListRcv.setAdapter(searchHistoryAdapter);
         searchHistoryAdapter.setList(searchHistoryTitleList);
-        //鍒濆鍖栫數绔欓�傞厤鍣�
+        //鍒濆鍖栨秷鎭�傞厤鍣�
         searchMessageAdapter = new SearchMessageAdapter(_mActivity);
         viewBinding.listRcv.setLayoutManager(new LinearLayoutManager(_mActivity));
         viewBinding.listRcv.setAdapter(searchMessageAdapter);
+        viewBinding.messageSearchEt.post(new Runnable() {
+            @Override
+            public void run() {
+                viewBinding.messageSearchEt.requestFocus();
+            }
+        });
+        pullToRefresh();
+
+        //鍦ㄧ晫闈腑浣跨敤
+        KeyboardStateObserverUtils.getKeyboardStateObserver(_mActivity).setKeyboardVisibilityListener(new KeyboardStateObserverUtils.OnKeyboardVisibilityListener() {
+            @Override
+            public void onKeyboardShow(int h) {
+                //Toast.makeText(MainActivity.this,"閿洏寮瑰嚭",Toast.LENGTH_SHORT).show();
+//                viewBinding.messageSearchEt.requestFocus();
+
+            }
+
+            @Override
+
+            public void onKeyboardHide(int h) {
+                viewBinding.messageSearchEt.clearFocus();
+            }
+
+        });
     }
 
 
@@ -226,6 +317,21 @@
     };
 
     /**
+     * 鍒锋柊鍒楄〃鏁版嵁
+     */
+    private void updateListData() {
+        HdlThreadLogic.runMainThread(new Runnable() {
+            @Override
+            public void run() {
+                if (searchMessageAdapter != null) {
+                    searchMessageAdapter.setList(mList);
+                }
+                nullDataUpdateUi();
+            }
+        });
+    }
+
+    /**
      * 鐗╃悊鎸夐敭杩斿洖浜嬩欢
      */
     @Override
@@ -240,93 +346,90 @@
             HdlFileLogic.getInstance().deleteFile(getHistoryFileNamePath());
             HdlFileLogic.getInstance().appendFile(getHistoryFileNamePath(), new Gson().toJson(searchHistoryTitleList));
         }
+        if (handler != null && delayedRunnable != null) {
+            handler.removeCallbacks(delayedRunnable);
+        }
         super.onDestroy();
     }
 
+
     /**
-     * 鍒锋柊UI锛堣澶囷級
+     * 鍔犺浇涓�椤垫暟鎹�
      *
-     * @param isRefreshing 琛ㄧず鏄笅鎷夊埛鏂扮殑
+     * @param isShowLoading 鏄惁鍚姩鍔犺浇妗� true鍚姩
+     * @param pageNo        椤垫暟
+     * @param search_title  鎼滅储鏂囨湰
+     * @param isClear       true琛ㄧず娓呯┖缂撳瓨
      */
-    private void loadNextPageHouseList(boolean isRefreshing, long pageNo, boolean isClear) {
-
-        //鎼滅储鍏抽敭瀛�
-        if (TextUtils.isEmpty(currSearchText)) {
-            return;
-        }
-
+    private void loadNextPageMessageList(boolean isShowLoading, int pageNo, String search_title, boolean isClear) {
         if (isClear) {
-            clearData();
+            //琛ㄧず浠庣涓�椤靛彲浠ヨ鍙栵紝榛樿娓呯┖鎵�鏈夌紦瀛樻暟鎹�;
+            clearCacheData();
         }
-        //绗竴椤佃鍙栨暟鎹己鍒惰鍙�
-        if (pageNo > 1 && currentHouseListPage > currentHouseListTotal) {
-            --currentHouseListPage;
+        //绗竴椤佃鍙栨暟鎹己鍒惰
+        if (pageNo > 1 && mCurrentPage > mCurrentTotal) {
+            --mCurrentPage;
             //褰撳墠椤典笉鑳藉ぇ浜庢�婚〉鏁�
             return;
         }
-        isHouseLoadingMore = true;//鏍囪璇诲彇鐘舵��
-        if (isRefreshing) {
+        isLoadingMore = true;//鏍囪璇诲彇鐘舵��
+        if (isShowLoading) {
             showLoading();
         }
-
-        //鑾峰彇浜戠涓婅澶囧垪琛�
-        HdlDeviceLogic.getInstance().getPowerStationDeviceList(currSearchText, pageNo, 20, new CloudCallBeak<PageNumberObject<DeviceBean>>() {
-            @Override
-            public void onSuccess(PageNumberObject<DeviceBean> deviceClass) {
-                HdlThreadLogic.runMainThread(new Runnable() {
+        HdlMessageLogic.getInstance().getPageNoMessageList(
+                "",
+                pageNo,
+                mMessageStateType,
+                "",
+                "",
+                "",
+                "",
+                "",
+                "",
+                search_title,
+                new CloudCallBeak<HdlMessageLogic.MessageListClass>() {
                     @Override
-                    public void run() {
-                        if (isRefreshing) {
+                    public void onSuccess(HdlMessageLogic.MessageListClass messageListClass) {
+                        if (messageListClass != null) {
+                            mCurrentTotal = (int) messageListClass.getTotalPage();
+                            mCurrentPage = (int) messageListClass.getPageNo();
+                            setMessageList(messageListClass.getList());
+                            updateListData();
+                        }
+                        isLoadingMore = false;
+                        if (isShowLoading) {
                             hideLoading();
                         }
-                        isHouseLoadingMore = false;
-                        if (deviceClass != null) {
-                            currentHouseListTotal = (int) deviceClass.getTotalPage();
-                            currentHouseListPage = (int) deviceClass.getPageNo();
-                            //鏇存柊缂撳瓨
-                            setDeviceList(deviceClass.getList());
-                            if (searchMessageAdapter != null) {
-                                initData();
-                                //鏇存柊UI
-                                searchMessageAdapter.setList(deviceList);
-                            }
-                        }
                     }
-                }, _mActivity, ShowErrorMode.YES);
 
-            }
-
-            @Override
-            public void onFailure(HDLException e) {
-                HdlThreadLogic.runMainThread(new Runnable() {
                     @Override
-                    public void run() {
-                        if (currentHouseListPage > 1) {
-                            --currentHouseListPage;
+                    public void onFailure(HDLException e) {
+                        if (mCurrentPage > 1) {
+                            --mCurrentPage;
                         }
-                        isHouseLoadingMore = false;
-                        if (isRefreshing) {
+                        isLoadingMore = false;
+                        if (isShowLoading) {
                             hideLoading();
                         }
-
                     }
-                }, _mActivity, ShowErrorMode.YES);
-            }
-        });
+                });
+
+
     }
 
-    private void clearData() {
-        if (deviceList != null && deviceList.size() > 0) {
-            deviceList.clear();
+
+    private void clearCacheData() {
+        if (mList != null && mList.size() > 0) {
+            mList.clear();
         }
     }
 
-    public void setDeviceList(List<DeviceBean> list) {
+    public void setMessageList(List<MessageBean> list) {
         if (list == null || list.size() == 0) {
             return;
         }
-        if (this.deviceList.size() == 0) {
-            this.deviceList.addAll(list);
+        if (this.mList.size() == 0) {
+            this.mList.addAll(list);
             return;
         }
         for (int i = 0; i < list.size(); i++) {
@@ -337,26 +440,26 @@
     /**
      * 娣诲姞璁惧鍒板垪琛ㄩ噷闈�
      *
-     * @param deviceBean -璁惧瀵硅薄
+     * @param messageBean -璁惧瀵硅薄
      */
-    public void setSingleDevice(DeviceBean deviceBean) {
+    public void setSingleDevice(MessageBean messageBean) {
         try {
-            if (deviceBean == null) {
+            if (messageBean == null) {
                 return;
             }
             boolean if_boolean = false;
-            for (int i = 0; i < deviceList.size(); i++) {
-                if (deviceList.get(i).getHomeId().equals(deviceBean.getHomeId())) {
+            for (int i = 0; i < mList.size(); i++) {
+                if (mList.get(i).getHomeId().equals(messageBean.getHomeId())) {
                     //瀛樺湪鏇挎崲
-                    deviceList.remove(i);
-                    deviceList.add(i, deviceBean);
+                    mList.remove(i);
+                    mList.add(i, messageBean);
                     if_boolean = true;
                     break;
                 }
             }
             if (!if_boolean) {
                 //娌℃湁娣诲姞
-                this.deviceList.add(deviceBean);
+                this.mList.add(messageBean);
             }
         } catch (Exception e) {
             String mes = e.getMessage();
@@ -368,19 +471,25 @@
      * 娣诲姞鍘嗗彶璁板綍
      */
     private void addSearchTextToList() {
+        int maxValue = 10;
         for (int i = 0; i < searchHistoryTitleList.size(); i++) {
             if (searchHistoryTitleList.get(i).equals(currSearchText)) {
                 searchHistoryTitleList.remove(searchHistoryTitleList.get(i));
             }
         }
-        searchHistoryTitleList.add(currSearchText);
-        // 鍊掑簭鎺掑垪鏁版嵁(鎼滅储鏈�鍚庢帓鍦ㄥ墠闈�)
-        Collections.reverse(searchHistoryTitleList);
-        if (searchHistoryTitleList.size() > 10) {
+        searchHistoryTitleList.add(0, currSearchText);
+        if (searchHistoryTitleList.size() > maxValue) {
             //鍘嗗彶璁板綍涓嶈兘瓒呭嚭10
-            searchHistoryTitleList.remove(searchHistoryTitleList.get(11));
+            searchHistoryTitleList.remove(searchHistoryTitleList.get(maxValue));
         }
+    }
 
+    /**
+     * 娌℃湁娑堟伅鍒楄〃鐨勬牱寮�
+     */
+    private void nullDataUpdateUi() {
+        boolean is_data = mList != null && mList.size() > 0;
+        HdlCommonLogic.getInstance().nullDataUpdateUi(_mActivity, viewBinding.deviceNullDataIc.getRoot(), viewBinding.deviceNullDataIc.nullDataGifAnimationIv, viewBinding.deviceNullDataIc.nullDataTv, getString(R.string.message_alarm_data_null), is_data);
     }
 
     /**
@@ -389,4 +498,6 @@
     public String getHistoryFileNamePath() {
         return HdlFileLogic.getInstance().getCurrentUserRootPath() + "/message.txt";
     }
+
+
 }
\ No newline at end of file

--
Gitblit v1.8.0