| | |
| | | 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; |
| | |
| | | import com.hdl.photovoltaic.base.CustomBaseActivity; |
| | | import com.hdl.photovoltaic.databinding.ActivitySearchMessgeBinding; |
| | | 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.ui.adapter.SearchHistoryAdapter; |
| | | import com.hdl.photovoltaic.ui.adapter.SearchMessageAdapter; |
| | | 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; |
| | |
| | | * 消息搜索界面 |
| | | */ |
| | | public class SearchMessageActivity extends CustomBaseActivity { |
| | | |
| | | private Handler handler; |
| | | private Runnable delayedRunnable; |
| | | |
| | | private ActivitySearchMessgeBinding viewBinding; |
| | | |
| | |
| | | @Override |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | setStatusBarTranslucent(); |
| | | getWindow().setNavigationBarColor(getColor(R.color.text_FF000000)); |
| | | mMessageStateType = getIntent().getStringExtra("MessageStateType"); |
| | | //历史记录文件夹创建 |
| | | HdlFileLogic.getInstance().createFileDir(HdlFileLogic.getInstance().getCurrentUserRootPath()); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 下拉刷新的逻辑 |
| | | */ |
| | | 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() { |
| | | |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | //清除 |
| | |
| | | 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()); |
| | | } |
| | | }); |
| | |
| | | HdlThreadLogic.toast(_mActivity, R.string.search_content_null); |
| | | return; |
| | | } |
| | | viewBinding.messageSearchEt.clearFocus(); |
| | | hideSoftInputFromWindow(); |
| | | viewBinding.historyListParent.setVisibility(View.GONE); |
| | | viewBinding.listParent.setVisibility(View.VISIBLE); |
| | | addSearchTextToList(); |
| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 显示软键盘 |
| | | */ |
| | | 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() { |
| | | viewBinding.historyListParent.setVisibility(View.VISIBLE); |
| | | viewBinding.listParent.setVisibility(View.GONE); |
| | |
| | | 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(); |
| | | } |
| | | |
| | | }); |
| | | } |
| | | |
| | | |
| | |
| | | if (searchMessageAdapter != null) { |
| | | searchMessageAdapter.setList(mList); |
| | | } |
| | | nullDataUpdateUi(); |
| | | } |
| | | }); |
| | | } |
| | |
| | | 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(); |
| | | } |
| | |
| | | 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)); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 没有消息列表的样式 |
| | | */ |
| | | 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); |
| | | } |
| | | |
| | | /** |
| | |
| | | public String getHistoryFileNamePath() { |
| | | return HdlFileLogic.getInstance().getCurrentUserRootPath() + "/message.txt"; |
| | | } |
| | | |
| | | |
| | | } |