From c3542b10ea66a1c3fad44fe8e0efd357d7d3857e Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期三, 19 十一月 2025 19:32:41 +0800
Subject: [PATCH] 2025年11月19日19:32:39

---
 app/src/main/java/com/hdl/photovoltaic/ui/message/SearchMessageHouseActivity.java |  435 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 435 insertions(+), 0 deletions(-)

diff --git a/app/src/main/java/com/hdl/photovoltaic/ui/message/SearchMessageHouseActivity.java b/app/src/main/java/com/hdl/photovoltaic/ui/message/SearchMessageHouseActivity.java
new file mode 100644
index 0000000..9799503
--- /dev/null
+++ b/app/src/main/java/com/hdl/photovoltaic/ui/message/SearchMessageHouseActivity.java
@@ -0,0 +1,435 @@
+package com.hdl.photovoltaic.ui.message;
+
+import android.content.Context;
+import android.content.Intent;
+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.recyclerview.widget.LinearLayoutManager;
+
+import com.google.gson.Gson;
+import com.google.gson.reflect.TypeToken;
+import com.hdl.linkpm.sdk.core.exception.HDLException;
+import com.hdl.photovoltaic.R;
+import com.hdl.photovoltaic.base.CustomBaseActivity;
+import com.hdl.photovoltaic.config.ConstantManage;
+import com.hdl.photovoltaic.databinding.ActivityHouseSearchBinding;
+import com.hdl.photovoltaic.enums.HomepageTitleTabSwitch;
+import com.hdl.photovoltaic.listener.CloudCallBeak;
+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.MessageHouseAdapter;
+import com.hdl.photovoltaic.ui.adapter.SearchHistoryAdapter;
+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 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 SearchMessageHouseActivity extends CustomBaseActivity {
+    private ActivityHouseSearchBinding viewBinding;
+    private Handler handler;
+    private Runnable delayedRunnable;
+    SearchHistoryAdapter searchHistoryAdapter;
+    MessageHouseAdapter searchMessageHouseAdapter;
+
+    List<MessageBean> mList = new ArrayList<>();
+    List<String> searchHistoryTitleList = new ArrayList<>();
+    private String currSearchText;
+
+    @Override
+    public Object getContentView() {
+        viewBinding = ActivityHouseSearchBinding.inflate(getLayoutInflater());
+        return viewBinding.getRoot();
+    }
+
+    @Override
+    public void onBindView(Bundle savedInstanceState) {
+        setStatusBarTranslucent();
+        getWindow().setNavigationBarColor(getColor(R.color.text_FF000000));
+        //鍘嗗彶璁板綍鏂囦欢澶瑰垱寤�
+        HdlFileLogic.getInstance().createFileDir(HdlFileLogic.getInstance().getCurrentUserRootPath());
+        //鍒濆鍖栨暟鎹�
+        initData();
+        //鍒濆鍖�
+        initView();
+        //鍒濆鍖栫晫闈㈢洃鍚櫒
+        initEvent();
+    }
+
+
+    private void initData() {
+        try {
+            String json = HdlFileLogic.getInstance().readFile(getHistoryFileNamePath());
+            if (TextUtils.isEmpty(json)) {
+                return;
+            }
+            searchHistoryTitleList = new Gson().fromJson(json, new TypeToken<List<String>>() {
+            }.getType());
+        } catch (Exception ignored) {
+        }
+    }
+
+    /**
+     * 涓嬫媺鍒锋柊鐨勯�昏緫
+     */
+    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();
+                        getMessageHouseList(currSearchText, false);
+                    }
+                };
+                // 寤惰繜 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 (!isHouseLoadingMore) {
+//                            // 婊戝姩鍒颁簡搴曢儴锛屾墽琛岀浉搴旂殑鎿嶄綔
+//                            getMessageHouseList(currSearchText,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() {
+
+        //鍚庨��
+        viewBinding.backRl.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                finish();
+            }
+        });
+        viewBinding.powerStationSearchEt.addTextChangedListener(textWatcher);
+        //鎼滅储
+        viewBinding.powerStationSearchTv.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                //鎼滅储鍏抽敭瀛�
+                currSearchText = viewBinding.powerStationSearchEt.getText().toString().replace(" ", "");
+                viewBinding.historyListParent.setVisibility(View.GONE);
+                viewBinding.listParent.setVisibility(View.VISIBLE);
+                viewBinding.powerStationSearchEt.clearFocus();
+                hideSoftInputFromWindow();
+                addSearchTextToList();
+                getMessageHouseList(currSearchText, true);
+            }
+        });
+        //娓呴櫎
+        viewBinding.powerStationClearIv.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                currSearchText = "";
+                viewBinding.powerStationSearchEt.setText("");
+                viewBinding.historyListParent.setVisibility(View.VISIBLE);
+                viewBinding.listParent.setVisibility(View.GONE);
+                viewBinding.deviceNullDataIc.getRoot().setVisibility(View.GONE);
+                searchHistoryAdapter.setList(searchHistoryTitleList);
+                viewBinding.powerStationSearchEt.requestFocus();
+                showSoftInput();
+                mList.clear();
+                searchMessageHouseAdapter.setList(mList);
+            }
+        });
+        //鍒犻櫎
+        viewBinding.powerStationDelIv.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                viewBinding.powerStationSearchEt.clearFocus();
+                hideSoftInputFromWindow();
+                searchHistoryTitleList = new ArrayList<>();
+                searchHistoryAdapter.setList(searchHistoryTitleList);
+                viewBinding.deviceNullDataIc.getRoot().setVisibility(View.GONE);
+                HdlFileLogic.getInstance().deleteFile(getHistoryFileNamePath());
+
+            }
+        });
+        //鍘嗗彶璁板綍鐐瑰嚮浜嬩欢
+        searchHistoryAdapter.setOnclickListener(new SearchHistoryAdapter.OnClickListener() {
+            @Override
+            public void onClick(int position, String title) {
+                viewBinding.powerStationSearchEt.setText(title);
+                //鎼滅储鍏抽敭瀛�
+                currSearchText = viewBinding.powerStationSearchEt.getText().toString().replace(" ", "");
+                if (TextUtils.isEmpty(currSearchText)) {
+                    HdlThreadLogic.toast(_mActivity, R.string.search_content_null);
+                    return;
+                }
+                viewBinding.powerStationSearchEt.clearFocus();
+                hideSoftInputFromWindow();
+                viewBinding.historyListParent.setVisibility(View.GONE);
+                viewBinding.listParent.setVisibility(View.VISIBLE);
+                addSearchTextToList();
+                getMessageHouseList(currSearchText, true);
+
+            }
+        });
+        //鐢电珯鐐瑰嚮鏄簨浠�
+        if (searchMessageHouseAdapter != null) {
+            searchMessageHouseAdapter.setOnclickListener(new MessageHouseAdapter.OnClickListener() {
+                @Override
+                public void onClick(int position, MessageBean messageBean) {
+                    Intent intent = new Intent();
+                    intent.putExtra("messageBean", new Gson().toJson(messageBean));
+                    intent.setClass(_mActivity, MessageActivity.class);
+                    startActivity(intent);
+                }
+            });
+
+        }
+
+    }
+
+    /**
+     * 鏄剧ず杞敭鐩�
+     */
+    public void showSoftInput() {
+        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+        inputMethodManager.showSoftInput(viewBinding.powerStationSearchEt, 0);
+
+    }
+
+    /**
+     * 闅愯棌杞敭鐩�
+     */
+    public void hideSoftInputFromWindow() {
+        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+        inputMethodManager.hideSoftInputFromWindow(viewBinding.getRoot().getWindowToken(), 0);
+    }
+
+    private void initView() {
+        viewBinding.historyListParent.setVisibility(View.VISIBLE);
+        viewBinding.listParent.setVisibility(View.GONE);
+        viewBinding.powerStationClearIv.setVisibility(View.GONE);
+        //鍒濆鍖栧巻鍙茶褰曢�傞厤鍣�
+        searchHistoryAdapter = new SearchHistoryAdapter(_mActivity);
+        viewBinding.historyListRcv.setLayoutManager(new LinearLayoutManager(_mActivity));
+        viewBinding.historyListRcv.setAdapter(searchHistoryAdapter);
+        searchHistoryAdapter.setList(searchHistoryTitleList);
+        //鍒濆鍖栫數绔欓�傞厤鍣�
+        searchMessageHouseAdapter = new MessageHouseAdapter(_mActivity);
+        viewBinding.listRcv.setLayoutManager(new LinearLayoutManager(_mActivity));
+        viewBinding.listRcv.setAdapter(searchMessageHouseAdapter);
+        viewBinding.powerStationSearchEt.post(new Runnable() {
+            @Override
+            public void run() {
+                viewBinding.powerStationSearchEt.requestFocus();
+            }
+        });
+
+        pullToRefresh();
+
+        //鍦ㄧ晫闈腑浣跨敤
+        KeyboardStateObserverUtils.getKeyboardStateObserver(_mActivity).setKeyboardVisibilityListener(new KeyboardStateObserverUtils.OnKeyboardVisibilityListener() {
+            @Override
+            public void onKeyboardShow(int h) {
+                //Toast.makeText(MainActivity.this,"閿洏寮瑰嚭",Toast.LENGTH_SHORT).show();
+//                viewBinding.powerStationSearchEt.requestFocus();
+
+            }
+
+            @Override
+
+            public void onKeyboardHide(int h) {
+                viewBinding.powerStationSearchEt.clearFocus();
+            }
+
+        });
+
+
+    }
+
+
+    /**
+     * 杈撳叆鐢电珯鍚嶇О杩涜杩囨护
+     */
+    private final TextWatcher textWatcher = new TextWatcher() {
+        @Override
+        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+
+        }
+
+        @Override
+        public void onTextChanged(CharSequence s, int start, int before, int count) {
+        }
+
+        @Override
+        public void afterTextChanged(Editable s) {
+            String et = viewBinding.powerStationSearchEt.getText().toString().replace(" ", "");
+            if (TextUtils.isEmpty(et)) {
+                viewBinding.powerStationClearIv.setVisibility(View.GONE);
+            } else {
+                viewBinding.powerStationClearIv.setVisibility(View.VISIBLE);
+            }
+            viewBinding.powerStationSearchEt.setSelection(viewBinding.powerStationSearchEt.length());
+
+        }
+    };
+
+    /**
+     * 閲嶆柊鏇存柊鍒楄〃鏁版嵁
+     */
+    private void updateRecyclerViewList() {
+        if (searchMessageHouseAdapter == null) {
+            return;
+        }
+        searchMessageHouseAdapter.setList(mList);
+        nullDataUpdateUi();
+    }
+
+    /**
+     * 鐗╃悊鎸夐敭杩斿洖浜嬩欢
+     */
+    @Override
+    public void onBackPressed() {
+        super.onBackPressed();
+    }
+
+    @Override
+    protected void onDestroy() {
+        viewBinding.powerStationSearchEt.removeTextChangedListener(textWatcher);
+        if (searchHistoryTitleList.size() > 0) {
+            HdlFileLogic.getInstance().deleteFile(getHistoryFileNamePath());
+            HdlFileLogic.getInstance().appendFile(getHistoryFileNamePath(), new Gson().toJson(searchHistoryTitleList));
+        }
+        if (handler != null && delayedRunnable != null) {
+            handler.removeCallbacks(delayedRunnable);
+        }
+        super.onDestroy();
+    }
+
+
+    /**
+     * 娣诲姞鍘嗗彶璁板綍
+     */
+    private void addSearchTextToList() {
+        if (TextUtils.isEmpty(currSearchText.replace(" ", ""))) {
+            return;
+        }
+        for (int i = 0; i < searchHistoryTitleList.size(); i++) {
+            if (searchHistoryTitleList.get(i).equals(currSearchText)) {
+                searchHistoryTitleList.remove(searchHistoryTitleList.get(i));
+            }
+        }
+        final int maxValue = 10;
+        searchHistoryTitleList.add(0, currSearchText);
+        if (searchHistoryTitleList.size() > maxValue) {
+            //鍘嗗彶璁板綍涓嶈兘瓒呭嚭10
+            searchHistoryTitleList.remove(searchHistoryTitleList.get(maxValue));
+        }
+
+    }
+
+    @Subscribe(threadMode = ThreadMode.MAIN)
+    public void onEventMessage(BaseEventBus eventBus) {
+        super.onEventMessage(eventBus);
+        if (eventBus == null) {
+            return;
+        }
+        //鎺ユ敹澶栭儴鐐瑰嚮浜嬩欢
+        if (eventBus.getTopic().equals(ConstantManage.refresh_message_house)) {
+            EventBus.getDefault().removeStickyEvent(eventBus);
+            getMessageHouseList(currSearchText, false);
+        }
+
+    }
+
+    /**
+     * 鑾峰彇璐﹀彿涓嬪叏閮ㄧ數绔欐秷鎭�
+     *
+     * @param homeName      鐢电珯鍚嶇О锛堟悳绱㈢敤鐨勶級,濡傛灉鏄┖瀛楃涓查粯璁よ鍙栧叏閮�
+     * @param isShowLoading 鏄惁闇�瑕佸姞杞界獥锛坱rue=闇�瑕侊紝false=涓嶉渶瑕侊級
+     */
+    private void getMessageHouseList(String homeName, boolean isShowLoading) {
+        if (isShowLoading) {
+            showLoading();
+        }
+        HdlMessageLogic.getInstance().getMessageHouseList(homeName, new CloudCallBeak<List<MessageBean>>() {
+            @Override
+            public void onSuccess(List<MessageBean> list) {
+                if (isShowLoading) {
+                    hideLoading();
+                }
+                mList.clear();
+                if (list != null && !list.isEmpty()) {
+                    mList.addAll(list);
+                }
+                updateRecyclerViewList();
+
+            }
+
+            @Override
+            public void onFailure(HDLException e) {
+
+                if (isShowLoading) {
+                    hideLoading();
+                }
+            }
+        });
+    }
+
+    /**
+     * 娌℃湁鐢电珯鍒楄〃鐨勬牱寮�
+     */
+    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.my_power_station_data_null), is_data);
+    }
+
+    /**
+     * 鑾峰彇銆愭悳绱㈠巻鍙茶褰曟枃浠躲�戝叏璺緞
+     */
+    public String getHistoryFileNamePath() {
+        return HdlFileLogic.getInstance().getCurrentUserRootPath() + "/message_house_history.txt";
+    }
+
+
+}
\ No newline at end of file

--
Gitblit v1.8.0