From 61e6a875ed317bf54f9cdf34e04329ec51c81800 Mon Sep 17 00:00:00 2001 From: niushuai233 Date: Wed, 19 Oct 2022 15:32:04 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BF=AE=E6=94=B9=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=90=8D=E4=B8=BAdeviceType?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devcontrol/base/entity/device/DeviceInfo.java | 12 ++++++------ .../devcontrol/base/util/GlobalVariables.java | 4 ++++ .../devcontrol/ui/nav/device/NavDeviceFragment.java | 3 +-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/entity/device/DeviceInfo.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/entity/device/DeviceInfo.java index 43601e9..3b096e8 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/entity/device/DeviceInfo.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/entity/device/DeviceInfo.java @@ -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"); diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/GlobalVariables.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/GlobalVariables.java index e513fbc..ca67353 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/GlobalVariables.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/GlobalVariables.java @@ -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 DEVICE_INFO_MAP = new HashMap<>(16); + public static Class getDeviceOperateActivity(String deviceId) { + return DEVICE_INFO_MAP.get(deviceId).getDeviceType().getActivity(); + } } diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/device/NavDeviceFragment.java b/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/device/NavDeviceFragment.java index 4fccf29..039944d 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/device/NavDeviceFragment.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/device/NavDeviceFragment.java @@ -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); }