From 1f3acf4c29f367e40a3f589b51176ed24e28948f Mon Sep 17 00:00:00 2001
From: wjc <1243177876@qq.com>
Date: 星期二, 02 九月 2025 17:54:42 +0800
Subject: [PATCH] 2025年09月02日17:54:39
---
app/src/main/java/com/hdl/photovoltaic/ui/message/SearchMessageActivity.java | 179 +++++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 137 insertions(+), 42 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 3dbe82b..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,12 +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;
@@ -18,20 +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.MessageStateType;
-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;
@@ -41,6 +45,9 @@
* 娑堟伅鎼滅储鐣岄潰
*/
public class SearchMessageActivity extends CustomBaseActivity {
+
+ private Handler handler;
+ private Runnable delayedRunnable;
private ActivitySearchMessgeBinding viewBinding;
@@ -67,6 +74,7 @@
@Override
public void onBindView(Bundle savedInstanceState) {
setStatusBarTranslucent();
+ getWindow().setNavigationBarColor(getColor(R.color.text_FF000000));
mMessageStateType = getIntent().getStringExtra("MessageStateType");
//鍘嗗彶璁板綍鏂囦欢澶瑰垱寤�
HdlFileLogic.getInstance().createFileDir(HdlFileLogic.getInstance().getCurrentUserRootPath());
@@ -90,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() {
@@ -111,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();
loadNextPageMessageList(true, 1, viewBinding.messageSearchEt.getText().toString(), true);
- }
- });
-
-
- //涓嬫媺绠ご棰滆壊
- viewBinding.listSrl.setColorSchemeResources(R.color.text_FF245EC3);
- //涓嬫媺璇诲彇
- viewBinding.listSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
- @Override
- public void onRefresh() {
- viewBinding.listSrl.setRefreshing(false);
- loadNextPageMessageList(true, 1, viewBinding.messageSearchEt.getText().toString(), 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 (!isLoadingMore) {
- // 婊戝姩鍒颁簡搴曢儴锛屾墽琛岀浉搴旂殑鎿嶄綔
- HdlLogLogic.print("--->婊戝姩鍒颁簡搴曢儴");
- loadNextPageMessageList(false, ++mCurrentPage, viewBinding.messageSearchEt.getText().toString(), false);
- }
- }
}
});
//娓呴櫎
@@ -156,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);
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());
}
});
@@ -175,6 +206,18 @@
@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);
}
});
//娑堟伅鐐瑰嚮鏄簨浠�
@@ -182,12 +225,29 @@
@Override
public void onClick(int position, MessageBean messageBean) {
Intent intent = new Intent();
- intent.putExtra("messageBean",new Gson().toJson(messageBean));
+ 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() {
@@ -203,6 +263,30 @@
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();
+ }
+
+ });
}
@@ -242,6 +326,7 @@
if (searchMessageAdapter != null) {
searchMessageAdapter.setList(mList);
}
+ nullDataUpdateUi();
}
});
}
@@ -260,6 +345,9 @@
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();
}
@@ -389,14 +477,19 @@
searchHistoryTitleList.remove(searchHistoryTitleList.get(i));
}
}
- searchHistoryTitleList.add(currSearchText);
- // 鍊掑簭鎺掑垪鏁版嵁(鎼滅储鏈�鍚庢帓鍦ㄥ墠闈�)
- Collections.reverse(searchHistoryTitleList);
+ searchHistoryTitleList.add(0, currSearchText);
if (searchHistoryTitleList.size() > maxValue) {
//鍘嗗彶璁板綍涓嶈兘瓒呭嚭10
- searchHistoryTitleList.remove(searchHistoryTitleList.get(maxValue + 1));
+ 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);
}
/**
@@ -405,4 +498,6 @@
public String getHistoryFileNamePath() {
return HdlFileLogic.getInstance().getCurrentUserRootPath() + "/message.txt";
}
+
+
}
\ No newline at end of file
--
Gitblit v1.8.0