From 7e5035fb6b2a2c29686be3dcad08b06dfa590ce1 Mon Sep 17 00:00:00 2001 From: niushuai233 Date: Thu, 20 Oct 2022 18:02:23 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=BE=E5=A4=87=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 23 +++++----- .../base/entity/device/DeviceInfo.java | 2 +- .../devcontrol/base/enums/DeviceTypeEnum.java | 43 +++++++++++++++---- .../devcontrol/base/util/GlobalVariables.java | 5 ++- .../DeviceAddPowerSwitchActivity.java | 21 +++++++++ .../nav/device/DeviceAddDialogFragment.java | 8 +++- .../activity_device_add_power_switch.xml | 9 ++++ app/src/main/res/values/strings.xml | 1 - 8 files changed, 87 insertions(+), 25 deletions(-) create mode 100644 app/src/main/java/cc/niushuai/project/devcontrol/ui/deviceadd/DeviceAddPowerSwitchActivity.java create mode 100644 app/src/main/res/layout/activity_device_add_power_switch.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index d30fc9c..8dc5dfd 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -9,8 +9,10 @@ android:roundIcon="@mipmap/app_launcher_round" android:supportsRtl="true" android:theme="@style/Theme.DevControl"> - - + + @@ -19,29 +21,26 @@ - - - + - - - + - - - + + - + 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 3b096e8..fe1417f 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 @@ -148,7 +148,7 @@ public class DeviceInfo { device.setName("卧室灯开关" + (i + 1)); device.setIconId(iconId); device.setDescription("卧室灯开关-树莓派"); - device.setDeviceType(DeviceTypeEnum.Switch); + device.setDeviceType(DeviceTypeEnum.Power_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/enums/DeviceTypeEnum.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/enums/DeviceTypeEnum.java index 356b854..174ef25 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,7 +1,10 @@ package cc.niushuai.project.devcontrol.base.enums; +import android.widget.TextView; + import cc.niushuai.project.devcontrol.R; import cc.niushuai.project.devcontrol.base.ui.BaseActivity; +import cc.niushuai.project.devcontrol.ui.deviceadd.DeviceAddPowerSwitchActivity; import cc.niushuai.project.devcontrol.ui.powerswitch.PowerSwitchActivity; /** @@ -15,20 +18,34 @@ public enum DeviceTypeEnum { /** * 开关 */ - Switch("Switch", "开关", R.drawable.ic_device_type_switch, PowerSwitchActivity.class), - Custom("Custom", "自定义设备", R.drawable.ic_device_type_custom, PowerSwitchActivity.class), + Power_Switch("Power_Switch", "开关", R.drawable.ic_device_type_switch, DeviceAddPowerSwitchActivity.class, PowerSwitchActivity.class), + Custom("Custom", "自定义设备", R.drawable.ic_device_type_custom, DeviceAddPowerSwitchActivity.class, PowerSwitchActivity.class), ; private String value; private String text; private int resId; - private Class activity; + private Class deviceAddActivity; + private Class deviceOperateActivity; - DeviceTypeEnum(String value, String text, int resId, Class activity) { + DeviceTypeEnum(String value, String text, int resId, + Class deviceAddActivity, + Class deviceOperateActivity) { this.value = value; this.text = text; this.resId = resId; - this.activity = activity; + this.deviceAddActivity = deviceAddActivity; + this.deviceOperateActivity = deviceOperateActivity; + } + + public static DeviceTypeEnum matchByValue(String value) { + + for (DeviceTypeEnum deviceTypeEnum : DeviceTypeEnum.values()) { + if (deviceTypeEnum.getValue().equals(value)) { + return deviceTypeEnum; + } + } + return null; } public String getValue() { @@ -55,11 +72,19 @@ public enum DeviceTypeEnum { this.resId = resId; } - public Class getActivity() { - return activity; + public Class getDeviceAddActivity() { + return deviceAddActivity; } - public void setActivity(Class activity) { - this.activity = activity; + public void setDeviceAddActivity(Class deviceAddActivity) { + this.deviceAddActivity = deviceAddActivity; + } + + public Class getDeviceOperateActivity() { + return deviceOperateActivity; + } + + public void setDeviceOperateActivity(Class deviceOperateActivity) { + this.deviceOperateActivity = deviceOperateActivity; } } 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 8553677..d6d8f85 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 @@ -14,8 +14,11 @@ public class GlobalVariables { */ public static final Map DEVICE_INFO_MAP = new HashMap<>(16); + public static Class getDeviceAddActivity(String deviceId) { + return getDeviceInfo(deviceId).getDeviceType().getDeviceAddActivity(); + } public static Class getDeviceOperateActivity(String deviceId) { - return getDeviceInfo(deviceId).getDeviceType().getActivity(); + return getDeviceInfo(deviceId).getDeviceType().getDeviceOperateActivity(); } public static DeviceInfo getDeviceInfo(String deviceId) { diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/ui/deviceadd/DeviceAddPowerSwitchActivity.java b/app/src/main/java/cc/niushuai/project/devcontrol/ui/deviceadd/DeviceAddPowerSwitchActivity.java new file mode 100644 index 0000000..8569066 --- /dev/null +++ b/app/src/main/java/cc/niushuai/project/devcontrol/ui/deviceadd/DeviceAddPowerSwitchActivity.java @@ -0,0 +1,21 @@ +package cc.niushuai.project.devcontrol.ui.deviceadd; + + +import android.os.Bundle; + +import cc.niushuai.project.devcontrol.R; +import cc.niushuai.project.devcontrol.base.ui.BaseActivity; + +public class DeviceAddPowerSwitchActivity extends BaseActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_device_add_power_switch); + } + + @Override + protected void init() { + + } +} \ No newline at end of file diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/device/DeviceAddDialogFragment.java b/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/device/DeviceAddDialogFragment.java index fa93ae5..ec42a34 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/device/DeviceAddDialogFragment.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/device/DeviceAddDialogFragment.java @@ -11,6 +11,7 @@ import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.GridView; import android.widget.SimpleAdapter; +import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; @@ -18,6 +19,8 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.fragment.app.DialogFragment; +import org.w3c.dom.Text; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -25,6 +28,7 @@ import java.util.Map; import cc.niushuai.project.devcontrol.R; import cc.niushuai.project.devcontrol.base.enums.DeviceTypeEnum; +import cc.niushuai.project.devcontrol.base.util.ActivityUtil; import cc.niushuai.project.devcontrol.databinding.DeviceAddBinding; public class DeviceAddDialogFragment extends DialogFragment { @@ -88,7 +92,9 @@ public class DeviceAddDialogFragment extends DialogFragment { * @date: 2022/10/20 16:59 */ private void deviceTypeListItemClickListener(AdapterView parent, View view, int position, long id) { - Toast.makeText(getActivity(), "xxx", Toast.LENGTH_SHORT).show(); + TextView keyView = view.findViewById(R.id.device_type_list_key); + + ActivityUtil.startActivity(getActivity(), DeviceTypeEnum.matchByValue(keyView.getText().toString()).getDeviceAddActivity()); } /** diff --git a/app/src/main/res/layout/activity_device_add_power_switch.xml b/app/src/main/res/layout/activity_device_add_power_switch.xml new file mode 100644 index 0000000..a7b70cd --- /dev/null +++ b/app/src/main/res/layout/activity_device_add_power_switch.xml @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0597e86..e9f4335 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -38,7 +38,6 @@ - 更换图标 参数设置