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 extends BaseActivity> activity;
+ private Class extends BaseActivity> deviceAddActivity;
+ private Class extends BaseActivity> deviceOperateActivity;
- DeviceTypeEnum(String value, String text, int resId, Class extends BaseActivity> activity) {
+ DeviceTypeEnum(String value, String text, int resId,
+ Class extends BaseActivity> deviceAddActivity,
+ Class extends BaseActivity> 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 extends BaseActivity> getActivity() {
- return activity;
+ public Class extends BaseActivity> getDeviceAddActivity() {
+ return deviceAddActivity;
}
- public void setActivity(Class extends BaseActivity> activity) {
- this.activity = activity;
+ public void setDeviceAddActivity(Class extends BaseActivity> deviceAddActivity) {
+ this.deviceAddActivity = deviceAddActivity;
+ }
+
+ public Class extends BaseActivity> getDeviceOperateActivity() {
+ return deviceOperateActivity;
+ }
+
+ public void setDeviceOperateActivity(Class extends BaseActivity> 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 extends BaseActivity> getDeviceAddActivity(String deviceId) {
+ return getDeviceInfo(deviceId).getDeviceType().getDeviceAddActivity();
+ }
public static Class extends BaseActivity> 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 @@
-
更换图标
参数设置