refactor: 修改字段名为deviceType

This commit is contained in:
niushuai233 2022-10-19 15:32:04 +08:00
parent d238867bc4
commit 61e6a875ed
3 changed files with 11 additions and 8 deletions

View File

@ -30,7 +30,7 @@ public class DeviceInfo {
/**
* 设备类型
*/
private DeviceTypeEnum type;
private DeviceTypeEnum deviceType;
/**
* 开关状态
@ -79,12 +79,12 @@ public class DeviceInfo {
this.name = name;
}
public DeviceTypeEnum getType() {
return type;
public DeviceTypeEnum getDeviceType() {
return deviceType;
}
public void setType(DeviceTypeEnum type) {
this.type = type;
public void setDeviceType(DeviceTypeEnum deviceType) {
this.deviceType = deviceType;
}
public OnOffEnum getOnOff() {
@ -148,7 +148,7 @@ public class DeviceInfo {
device.setName("卧室灯开关" + (i + 1));
device.setIconId(iconId);
device.setDescription("卧室灯开关-树莓派");
device.setType(DeviceTypeEnum.Switch);
device.setDeviceType(DeviceTypeEnum.Switch);
device.setOnOff(OnOffEnum.OFF);
device.setCommandPath("/path/file");
device.setCommandArgs("-c light -t 1");

View File

@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.Map;
import cc.niushuai.project.devcontrol.base.entity.device.DeviceInfo;
import cc.niushuai.project.devcontrol.base.ui.BaseActivity;
public class GlobalVariables {
@ -13,5 +14,8 @@ public class GlobalVariables {
*/
public static final Map<String, DeviceInfo> DEVICE_INFO_MAP = new HashMap<>(16);
public static Class<? extends BaseActivity> getDeviceOperateActivity(String deviceId) {
return DEVICE_INFO_MAP.get(deviceId).getDeviceType().getActivity();
}
}

View File

@ -117,8 +117,7 @@ public class NavDeviceFragment extends Fragment {
private void onItemClick(AdapterView<?> parent, View view, int position, long id) {
TextView textId = view.findViewById(R.id.device_item_cardView_id);
DeviceInfo deviceInfo = GlobalVariables.DEVICE_INFO_MAP.get(textId.getText());
Intent intent = new Intent(getActivity(), deviceInfo.getType().getActivity());
Intent intent = new Intent(getActivity(), GlobalVariables.getDeviceOperateActivity(textId.getText().toString()));
intent.putExtra(Keys.ID, textId.getText());
startActivity(intent);
}