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); }