From 30859ca8f2175475d2c666353bc27f3b2ceede53 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期四, 22 八月 2024 13:43:47 +0800 Subject: [PATCH] 2024年08月22日13:43:45 --- app/src/main/java/com/hdl/photovoltaic/ui/message/SearchMessageActivity.java | 259 ++++++++++++++++++++++++++++++++++----------------- 1 files changed, 170 insertions(+), 89 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..6268561 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,14 @@ package com.hdl.photovoltaic.ui.message; +import android.content.Context; +import android.content.Intent; import android.os.Bundle; 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 +20,17 @@ 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 java.util.ArrayList; import java.util.Collections; @@ -43,15 +46,16 @@ 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 +66,7 @@ @Override public void onBindView(Bundle savedInstanceState) { setStatusBarTranslucent(); + mMessageStateType = getIntent().getStringExtra("MessageStateType"); //鍘嗗彶璁板綍鏂囦欢澶瑰垱寤� HdlFileLogic.getInstance().createFileDir(HdlFileLogic.getInstance().getCurrentUserRootPath()); //鍒濆鍖栨暟鎹� @@ -95,8 +100,6 @@ } }); viewBinding.messageSearchEt.addTextChangedListener(textWatcher); - - //鎼滅储 viewBinding.powerStationSearchTv.setOnClickListener(new View.OnClickListener() { @Override @@ -107,10 +110,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); + loadNextPageMessageList(true, 1, viewBinding.messageSearchEt.getText().toString(), true); } }); @@ -122,7 +127,7 @@ @Override public void onRefresh() { viewBinding.listSrl.setRefreshing(false); - loadNextPageHouseList(true, 1, true); + loadNextPageMessageList(true, 1, viewBinding.messageSearchEt.getText().toString(), true); } }); //涓婃媺璇诲彇 @@ -137,10 +142,10 @@ int totalItemCount = layoutManager.getItemCount(); int firstVisibleItemPosition = layoutManager.findFirstVisibleItemPosition(); if (visibleItemCount > 0 && visibleItemCount + firstVisibleItemPosition == totalItemCount) { - if (!isHouseLoadingMore) { + if (!isLoadingMore) { // 婊戝姩鍒颁簡搴曢儴锛屾墽琛岀浉搴旂殑鎿嶄綔 HdlLogLogic.print("--->婊戝姩鍒颁簡搴曢儴"); - loadNextPageHouseList(false, ++currentHouseListPage, false); + loadNextPageMessageList(false, ++mCurrentPage, viewBinding.messageSearchEt.getText().toString(), false); } } } @@ -152,17 +157,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 +182,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 +235,33 @@ 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(); + } + }); + + //鍦ㄧ晫闈腑浣跨敤 + 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 +292,21 @@ }; /** + * 鍒锋柊鍒楄〃鏁版嵁 + */ + private void updateListData() { + HdlThreadLogic.runMainThread(new Runnable() { + @Override + public void run() { + if (searchMessageAdapter != null) { + searchMessageAdapter.setList(mList); + } + nullDataUpdateUi(); + } + }); + } + + /** * 鐗╃悊鎸夐敭杩斿洖浜嬩欢 */ @Override @@ -243,90 +324,84 @@ 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 +412,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 +443,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); } /** -- Gitblit v1.8.0