package com.hdl.sdk.ttl_sdk.activity;
|
|
|
import android.app.ProgressDialog;
|
import android.content.Context;
|
import android.content.Intent;
|
import android.os.Bundle;
|
import android.text.TextUtils;
|
import android.view.View;
|
import android.widget.Button;
|
import android.widget.RelativeLayout;
|
import android.widget.TextView;
|
import android.widget.Toast;
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.RecyclerView;
|
|
import com.hdl.sdk.ttl.HDLAppliances.Config.HDLApConfig;
|
import com.hdl.sdk.ttl.HDLDeviceManger.Bean.AppliancesInfo;
|
import com.hdl.sdk.ttl.HDLDeviceManger.Bean.DevicesData;
|
import com.hdl.sdk.ttl.HDLDeviceManger.Bean.ScenesData;
|
import com.hdl.sdk.ttl.HDLDeviceManger.Core.HDLCommand;
|
import com.hdl.sdk.ttl.HDLDeviceManger.Core.HDLDeviceManager;
|
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.DevicesInfoEvent;
|
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.LogicFeedBackEvent;
|
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.SceneFeedBackEvent;
|
import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.ScenesInfoEvent;
|
import com.hdl.sdk.ttl.Utils.LogUtils.HDLLog;
|
import com.hdl.sdk.ttl_sdk.R;
|
import com.hdl.sdk.ttl_sdk.adapter.HDLMainListAdapter;
|
import com.hdl.sdk.ttl_sdk.adapter.HDLSceneListAdapter;
|
import com.hdl.sdk.ttl_sdk.base.BaseActivity;
|
|
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.ThreadMode;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
|
/**
|
* Created by panlili on 2024/01/19
|
* 场景控制页面
|
*/
|
public class CtrlSceneActivity extends BaseActivity {
|
/**
|
* Topbar
|
*/
|
private RelativeLayout topBarBack;
|
private TextView topBarTitle;
|
private Button btnSearch;
|
private RecyclerView mRecyclerView;
|
private TextView tvResult;
|
|
private List<ScenesData> mScenesDataList = new ArrayList<>();
|
private ScenesData scenesData;
|
private HDLSceneListAdapter hdlSceneListAdapter;
|
private String subnetID, deviceID;
|
private ProgressDialog mProgressDialog;
|
|
public static void open(Context mContext, String subnetID, String deviceID) {
|
Intent intent = new Intent(mContext, CtrlSceneActivity.class);
|
intent.putExtra("subnetID", subnetID);
|
intent.putExtra("deviceID", deviceID);
|
mContext.startActivity(intent);
|
}
|
|
/**
|
* 复写isRegisterEventBus() 要注册使用EventBus,这里要设置返回true
|
*
|
* @return true
|
*/
|
@Override
|
protected boolean isRegisterEventBus() {
|
return true;
|
}
|
|
@Override
|
protected void onCreate(Bundle savedInstanceState) {
|
super.onCreate(savedInstanceState);
|
setContentView(R.layout.activity_ctrl_scene);
|
|
subnetID = getIntent().getStringExtra("subnetID");
|
deviceID = getIntent().getStringExtra("deviceID");
|
initToolbar();
|
initView();
|
}
|
|
/**
|
* 初始化Toolbar
|
*/
|
private void initToolbar() {
|
topBarBack = findViewById(R.id.ll_top_b_left);
|
setViewVisible(topBarBack);
|
topBarTitle = findViewById(R.id.tv_top_b_header_title);
|
topBarTitle.setText("场景");
|
topBarBack.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View view) {
|
finish();
|
}
|
});
|
}
|
|
private void initView() {
|
btnSearch = findViewById(R.id.btn_search);
|
btnSearch.setOnClickListener(new View.OnClickListener() {
|
@Override
|
public void onClick(View v) {
|
if (TextUtils.isEmpty(subnetID) || TextUtils.isEmpty(deviceID)) {
|
Toast.makeText(CtrlSceneActivity.this, "请输入网关的子网号设备号!", Toast.LENGTH_SHORT).show();
|
return;
|
}
|
/**全部重新搜索,清空原场景列表数据*/
|
clearListView();
|
|
HDLCommand.getHomeScenes(Integer.parseInt(subnetID), Integer.parseInt(deviceID));
|
mProgressDialog.show();
|
}
|
});
|
|
tvResult = findViewById(R.id.tv_scene);
|
|
mRecyclerView = findViewById(R.id.listView_scenes);
|
// 定义一个线性布局管理器
|
LinearLayoutManager manager = new LinearLayoutManager(this);
|
// 设置布局管理器
|
mRecyclerView.setLayoutManager(manager);
|
// 设置adapter
|
hdlSceneListAdapter = new HDLSceneListAdapter(this, mScenesDataList);
|
mRecyclerView.setAdapter(hdlSceneListAdapter);
|
|
hdlSceneListAdapter.setOnItemClickLitener(new HDLSceneListAdapter.OnItemClickLitener() {
|
@Override
|
public void onItemClick(int position) {
|
//执行场景
|
scenesData = mScenesDataList.get(position);
|
HDLCommand.sceneCtrl(scenesData);
|
}
|
});
|
|
mProgressDialog = new ProgressDialog(CtrlSceneActivity.this);
|
mProgressDialog.setTitle("正在获取数据...");
|
mProgressDialog.setMessage("请耐心等待");
|
mProgressDialog.onStart();
|
|
}
|
|
/**
|
* 清空数据并刷新列表
|
*/
|
private void clearListView() {
|
if (mScenesDataList != null) mScenesDataList.clear();
|
|
hdlSceneListAdapter.notifyDataSetChanged();
|
}
|
|
/**
|
* ====================EventBus 订阅事件 ====================
|
*/
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
public void onScenesInfoEventMain(ScenesInfoEvent event) {
|
mProgressDialog.dismiss();
|
if (!event.isSuccess()) {
|
Toast.makeText(CtrlSceneActivity.this, "搜索超时,请重新再试", Toast.LENGTH_SHORT).show();
|
tvResult.setText("搜索超时,请重新再试");
|
return;
|
}
|
mScenesDataList = event.getDesSceneList();
|
HDLLog.I("onScenesInfoEventMain size=" + mScenesDataList.size());
|
hdlSceneListAdapter.setData(mScenesDataList);
|
hdlSceneListAdapter.notifyDataSetChanged();
|
}
|
|
/**
|
* 场景控制回调Event
|
*
|
* @param event
|
*/
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
public void onSceneFeedBackEventMain(SceneFeedBackEvent event) {
|
// 先判断是否超时
|
if (event.getSceneCtrlBackInfo().getAreaCodeID() == scenesData.getAreaCodeID()
|
&& event.getSceneCtrlBackInfo().getSceneID() == scenesData.getSceneID()) {
|
if (!event.isSuccess()) {
|
showToast("场景控制超时,请重新再试");
|
return;
|
}
|
showToast("场景控制成功");
|
}
|
}
|
|
|
}
|