| | |
| | | import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; |
| | | |
| | | import android.content.Context; |
| | | 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 com.hdl.photovoltaic.uni.HDLUniMP; |
| | | import com.hdl.photovoltaic.utils.KeyboardStateObserverUtils; |
| | | import com.hdl.photovoltaic.utils.URLEncodingUtils; |
| | | import com.hdl.photovoltaic.widget.refreshlayout.BGARefreshLayout; |
| | | import com.hdl.photovoltaic.widget.refreshlayout.HDLRefreshViewHolder; |
| | | import com.hdl.sdk.link.core.bean.gateway.GatewayBean; |
| | | import com.hdl.sdk.link.core.config.HDLLinkConfig; |
| | | import com.hdl.sdk.link.gateway.HDLLinkLocalGateway; |
| | |
| | | */ |
| | | public class DeviceSearchActivity extends CustomBaseActivity { |
| | | |
| | | |
| | | private Handler handler; |
| | | private Runnable delayedRunnable; |
| | | private ActivityDeviceSearchBinding viewBinding; |
| | | |
| | | SearchDeviceAdapter searchDeviceAdapter;//设备适配器 |
| | |
| | | |
| | | private List<CloudInverterDeviceBean> deviceList = new ArrayList<>(); |
| | | |
| | | private int currentHouseListPage = 0; // 当前电站列表页码 |
| | | private int currentHouseListTotal = 0; // 电站列表总页码 |
| | | private boolean isHouseLoadingMore = false; // 标记电站列表正在加载更多数据 |
| | | private int currentDeviceListPage = 0; // 当前电站列表页码 |
| | | private int currentDeviceListTotal = 0; // 电站列表总页码 |
| | | private boolean isDeviceLoadingMore = false; // 标记电站列表正在加载更多数据 |
| | | |
| | | private String currSearchText; |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 下拉刷新的逻辑 |
| | | */ |
| | | 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(); |
| | | loadNextPageDeviceList(false, 1, 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 (!isDeviceLoadingMore) { |
| | | // 滑动到了底部,执行相应的操作 |
| | | HdlLogLogic.print("--->滑动到了底部"); |
| | | loadNextPageDeviceList(false, ++currentDeviceListPage, 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.historyListParent.setVisibility(View.GONE); |
| | | viewBinding.listParent.setVisibility(View.VISIBLE); |
| | | addSearchTextToList(); |
| | | loadNextPageHouseList(true, 1, true); |
| | | loadNextPageDeviceList(true, 1, true); |
| | | } |
| | | }); |
| | | |
| | | |
| | | //下拉箭头颜色 |
| | | viewBinding.listSrl.setColorSchemeResources(R.color.text_FF245EC3); |
| | | //下拉读取 |
| | | viewBinding.listSrl.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { |
| | | @Override |
| | | public void onRefresh() { |
| | | viewBinding.listSrl.setRefreshing(false); |
| | | loadNextPageHouseList(true, 1, 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 (!isHouseLoadingMore) { |
| | | // 滑动到了底部,执行相应的操作 |
| | | HdlLogLogic.print("--->滑动到了底部"); |
| | | loadNextPageHouseList(false, ++currentHouseListPage, false); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | //清除 |
| | | viewBinding.powerStationClearIv.setOnClickListener(new View.OnClickListener() { |
| | | @Override |
| | |
| | | viewBinding.historyListParent.setVisibility(View.GONE); |
| | | viewBinding.listParent.setVisibility(View.VISIBLE); |
| | | addSearchTextToList(); |
| | | loadNextPageHouseList(true, 1, true); |
| | | loadNextPageDeviceList(true, 1, true); |
| | | } |
| | | }); |
| | | //设备点击是事件 |
| | |
| | | @Override |
| | | public void onSuccess(List<GatewayBean> obj) { |
| | | GatewayBean newGatewayBean = HDLLinkLocalGateway.getInstance().getLocalGateway(deviceBean.getOsn()); |
| | | if (newGatewayBean == null) { |
| | | HdlThreadLogic.toast(_mActivity, getString(R.string.device_off)); |
| | | return; |
| | | } |
| | | if (TextUtils.isEmpty(newGatewayBean.getGatewayId()) || TextUtils.isEmpty(newGatewayBean.getAesKey())) { |
| | | //这里只支持远程调试,远程拿不到mqtt通讯秘钥以及gatewayId; |
| | | HdlThreadLogic.toast(_mActivity,getString(R.string.Device_failed_to_certificate)+"(124004)"); |
| | | return; |
| | | } |
| | | String jsonEncryption = URLEncodingUtils.encodeURIComponent(new Gson().toJson(newGatewayBean)); |
| | | String path = HDLUniMP.UNI_EVENT_OPEN_DEVICE_DETAILS + "?inverterInfo=" + jsonEncryption; |
| | | HdlUniLogic.getInstance().openUniMP(path, null); |
| | | |
| | | } |
| | | |
| | | @Override |
| | |
| | | viewBinding.powerStationSearchEt.requestFocus(); |
| | | } |
| | | }); |
| | | pullToRefresh(); |
| | | |
| | | //在界面中使用 |
| | | KeyboardStateObserverUtils.getKeyboardStateObserver(_mActivity).setKeyboardVisibilityListener(new KeyboardStateObserverUtils.OnKeyboardVisibilityListener() { |
| | |
| | | HdlFileLogic.getInstance().deleteFile(getHistoryFileNamePath()); |
| | | HdlFileLogic.getInstance().appendFile(getHistoryFileNamePath(), new Gson().toJson(searchHistoryTitleList)); |
| | | } |
| | | if (handler != null && delayedRunnable != null) { |
| | | handler.removeCallbacks(delayedRunnable); |
| | | } |
| | | super.onDestroy(); |
| | | } |
| | | |
| | |
| | | * |
| | | * @param isRefreshing 表示是下拉刷新的 |
| | | */ |
| | | private void loadNextPageHouseList(boolean isRefreshing, long pageNo, boolean isClear) { |
| | | private void loadNextPageDeviceList(boolean isRefreshing, long pageNo, boolean isClear) { |
| | | |
| | | //搜索关键字 |
| | | if (TextUtils.isEmpty(currSearchText)) { |
| | |
| | | clearData(); |
| | | } |
| | | //第一页读取数据强制读取 |
| | | if (pageNo > 1 && currentHouseListPage > currentHouseListTotal) { |
| | | --currentHouseListPage; |
| | | if (pageNo > 1 && currentDeviceListPage > currentDeviceListTotal) { |
| | | --currentDeviceListPage; |
| | | //当前页不能大于总页数 |
| | | return; |
| | | } |
| | | isHouseLoadingMore = true;//标记读取状态 |
| | | isDeviceLoadingMore = true;//标记读取状态 |
| | | if (isRefreshing) { |
| | | showLoading(); |
| | | } |
| | |
| | | if (isRefreshing) { |
| | | hideLoading(); |
| | | } |
| | | isHouseLoadingMore = false; |
| | | isDeviceLoadingMore = false; |
| | | if (deviceClass != null) { |
| | | currentHouseListTotal = (int) deviceClass.getTotalPage(); |
| | | currentHouseListPage = (int) deviceClass.getPageNo(); |
| | | currentDeviceListTotal = (int) deviceClass.getTotalPage(); |
| | | currentDeviceListPage = (int) deviceClass.getPageNo(); |
| | | //更新缓存 |
| | | setDeviceList(deviceClass.getList()); |
| | | if (searchDeviceAdapter != null) { |
| | |
| | | HdlThreadLogic.runMainThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (currentHouseListPage > 1) { |
| | | --currentHouseListPage; |
| | | if (currentDeviceListPage > 1) { |
| | | --currentDeviceListPage; |
| | | } |
| | | isHouseLoadingMore = false; |
| | | isDeviceLoadingMore = false; |
| | | if (isRefreshing) { |
| | | hideLoading(); |
| | | } |