| | |
| | | package com.hdl.photovoltaic.ui.message; |
| | | |
| | | |
| | | import android.content.Intent; |
| | | import android.os.Bundle; |
| | | import android.text.Editable; |
| | | import android.text.TextUtils; |
| | |
| | | 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.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 java.util.ArrayList; |
| | | import java.util.Collections; |
| | |
| | | SearchMessageAdapter searchMessageAdapter;//设备适配器 |
| | | SearchHistoryAdapter searchHistoryAdapter;//历史记录适配器 |
| | | |
| | | private List<DeviceBean> deviceList = new ArrayList<>(); |
| | | |
| | | private int currentHouseListPage = 0; // 当前电站列表页码 |
| | | private int currentHouseListTotal = 0; // 电站列表总页码 |
| | | private boolean isHouseLoadingMore = false; // 标记电站列表正在加载更多数据 |
| | | private final List<MessageBean> mList = new ArrayList<>(); |
| | | private int mCurrentPage = 0; // 当前页码 |
| | | private int mCurrentTotal = 0; // 总页码 |
| | | private boolean isLoadingMore = false; // 标记正在加载更多数据 |
| | | |
| | | private String currSearchText; |
| | | |
| | | List<String> searchHistoryTitleList = new ArrayList<>(); |
| | | |
| | | String mMessageStateType = ""; |
| | | |
| | | @Override |
| | | public Object getContentView() { |
| | |
| | | @Override |
| | | public void onBindView(Bundle savedInstanceState) { |
| | | setStatusBarTranslucent(); |
| | | mMessageStateType = getIntent().getStringExtra("MessageStateType"); |
| | | //历史记录文件夹创建 |
| | | HdlFileLogic.getInstance().createFileDir(HdlFileLogic.getInstance().getCurrentUserRootPath()); |
| | | //初始化数据 |
| | |
| | | } |
| | | }); |
| | | viewBinding.messageSearchEt.addTextChangedListener(textWatcher); |
| | | |
| | | |
| | | //搜索 |
| | | viewBinding.powerStationSearchTv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | |
| | | viewBinding.historyListParent.setVisibility(View.GONE); |
| | | viewBinding.listParent.setVisibility(View.VISIBLE); |
| | | addSearchTextToList(); |
| | | loadNextPageHouseList(true, 1, true); |
| | | loadNextPageMessageList(true, 1, viewBinding.messageSearchEt.getText().toString(), true); |
| | | } |
| | | }); |
| | | |
| | |
| | | @Override |
| | | public void onRefresh() { |
| | | viewBinding.listSrl.setRefreshing(false); |
| | | loadNextPageHouseList(true, 1, true); |
| | | loadNextPageMessageList(true, 1, viewBinding.messageSearchEt.getText().toString(), true); |
| | | } |
| | | }); |
| | | //上拉读取 |
| | |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | viewBinding.historyListParent.setVisibility(View.VISIBLE); |
| | | viewBinding.listParent.setVisibility(View.GONE); |
| | | searchHistoryAdapter.setList(searchHistoryTitleList); |
| | | clearData(); |
| | | clearCacheData(); |
| | | } |
| | | }); |
| | | //删除 |
| | |
| | | viewBinding.messageSearchEt.setText(title); |
| | | } |
| | | }); |
| | | //电站点击是事件 |
| | | //消息点击是事件 |
| | | 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); |
| | | } |
| | | }); |
| | | |
| | |
| | | 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); |
| | |
| | | }; |
| | | |
| | | /** |
| | | * 刷新列表数据 |
| | | */ |
| | | private void updateListData() { |
| | | HdlThreadLogic.runMainThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (searchMessageAdapter != null) { |
| | | searchMessageAdapter.setList(mList); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | | * 物理按键返回事件 |
| | | */ |
| | | @Override |
| | |
| | | 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++) { |
| | |
| | | /** |
| | | * 添加设备到列表里面 |
| | | * |
| | | * @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(); |
| | |
| | | * 添加历史记录 |
| | | */ |
| | | 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) { |
| | | if (searchHistoryTitleList.size() > maxValue) { |
| | | //历史记录不能超出10 |
| | | searchHistoryTitleList.remove(searchHistoryTitleList.get(11)); |
| | | searchHistoryTitleList.remove(searchHistoryTitleList.get(maxValue + 1)); |
| | | } |
| | | |
| | | } |