From d238867bc4870ea811cc95950abd19b3fb54da08 Mon Sep 17 00:00:00 2001 From: niushuai233 Date: Wed, 19 Oct 2022 15:28:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=8F=AF=E6=A0=B9=E6=8D=AE=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E7=B1=BB=E5=9E=8B=E8=B7=B3=E8=BD=AC=E5=88=B0=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E7=9A=84=E8=AE=BE=E5=A4=87=E6=93=8D=E4=BD=9C=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devcontrol/base/enums/DeviceTypeEnum.java | 33 ++++++++++++++++--- .../ui/nav/device/NavDeviceFragment.java | 4 ++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/enums/DeviceTypeEnum.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/enums/DeviceTypeEnum.java index 0916ce3..4a8669f 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/enums/DeviceTypeEnum.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/enums/DeviceTypeEnum.java @@ -1,5 +1,8 @@ package cc.niushuai.project.devcontrol.base.enums; +import cc.niushuai.project.devcontrol.base.ui.BaseActivity; +import cc.niushuai.project.devcontrol.ui.powerswitch.PowerSwitchActivity; + /** * 设备类型枚举 * @@ -11,11 +14,31 @@ public enum DeviceTypeEnum { /** * 开关 */ - Switch, + Switch("Switch", PowerSwitchActivity.class), + ; - /** - * 未知 - */ - Unknown; + private String value; + private Class activity; + + DeviceTypeEnum(String value, Class activity) { + this.value = value; + this.activity = activity; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public Class getActivity() { + return activity; + } + + public void setActivity(Class activity) { + this.activity = activity; + } } 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 8743b62..4fccf29 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 @@ -21,6 +21,7 @@ import java.util.List; import cc.niushuai.project.devcontrol.R; import cc.niushuai.project.devcontrol.base.entity.device.DeviceInfo; +import cc.niushuai.project.devcontrol.base.util.GlobalVariables; import cc.niushuai.project.devcontrol.base.util.Keys; import cc.niushuai.project.devcontrol.databinding.DeviceItemBinding; import cc.niushuai.project.devcontrol.databinding.MainNavFragmentDeviceBinding; @@ -116,7 +117,8 @@ 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); - Intent intent = new Intent(getActivity(), PowerSwitchActivity.class); + DeviceInfo deviceInfo = GlobalVariables.DEVICE_INFO_MAP.get(textId.getText()); + Intent intent = new Intent(getActivity(), deviceInfo.getType().getActivity()); intent.putExtra(Keys.ID, textId.getText()); startActivity(intent); }