Background -这是一个场景,我的应用程序是一个物联网应用程序.现在的情况是我必须在房间部分创建一组物联网设备.但条件总是相同类型的设备必须在该组中 Select ,如果在房间里有4个设备,其中2支持RGB和其他支持温暖和冷白色,然后该组时,我会创建它将显示所有设备与复选框与不同的类别.如果我在任何设备上打勾,那么其他设备类别将被禁用(不是同一个).因为我想让用户创建相同类别的组.
Problem-现在,正如我提到的问题,如果我不在小组中做出任何改变,它也无法挽救它.
private fun createSelectedDevices() {
val selectedNodes = JsonArray()
val disSelectedNodes = JsonArray()
val distinctDevices = devices.distinctBy { it.nodeId } as ArrayList<Device>
if (selectedDevices.isNullOrEmpty()) {
//Error happening when we edit the Group Name or not
alertErrorManagement(
"Please select devices",
"",
ErrorObject.EXCEPTION,
R.drawable.ic_error_background
)
return
} else {
for (device in selectedDevices) {
if (device.selectedState == 1) {
selectedNodes.add(device.nodeId)
} else {
disSelectedNodes.add(device.nodeId)
}
}
if (selectedNodes.isEmpty && disSelectedNodes.isEmpty) {
alertErrorManagement(
"Please select devices",
"",
ErrorObject.EXCEPTION,
R.drawable.ic_error_background
)
return
}
}
if (!disSelectedNodes.isEmpty) {
updateGroupRemove(disSelectedNodes, selectedNodes)
} else {
updateGroupAdd(selectedNodes)
}
}
现在在这段代码alertErrorManagement是一个弹出消息,将显示当用户没有 Select 任何设备(而编辑组我给用户的权限来更改它的组名太).现在假设您创建了一个包含1个设备的组.如果您try 单击组中的编辑按钮,而不更改组名称或设备 Select 等任何内容,则直接单击保存按钮.它将显示弹出消息Please Select Devices,这是错误的,因为已经 Select 了1个 node 或设备.在代码中,它提到了上面的if-condition.但如果我 Select 相同的设备并取消勾选复选框.之后,如果我点击同一设备并勾选复选框.它将显示Group Updated Successfully的弹出消息.
我try 查看SelectedDevice.kt类文件,但没有看到任何错误.
public class SelectiveDevice implements Serializable {
private String nodeId;
private String deviceName;
private String userVisibleName;
private String deviceType;
private String primaryParamName;
private ArrayList<Param> params;
private boolean expanded;
private int selectedState;
public boolean isBluetooth = false;
public boolean selected = false;
private String type = "";
public SelectiveDevice() {
}
public SelectiveDevice(SelectiveDevice device) {
nodeId = device.getNodeId();
deviceName = device.getDeviceName();
userVisibleName = device.getUserVisibleName();
deviceType = device.getDeviceType();
primaryParamName = device.getPrimaryParamName();
params = device.getParams();
expanded = device.isExpanded();
selectedState = device.getSelectedState();
}
public SelectiveDevice(SelectiveDevice device, boolean selected, String type) {
nodeId = device.getNodeId();
deviceName = device.getDeviceName();
userVisibleName = device.getUserVisibleName();
deviceType = device.getDeviceType();
primaryParamName = device.getPrimaryParamName();
params = device.getParams();
expanded = device.isExpanded();
selectedState = device.getSelectedState();
this.selected = selected;
this.type = type;
}
public SelectiveDevice(Device device, boolean selected, String type) {
nodeId = device.getNodeId();
deviceName = device.getDeviceName();
userVisibleName = device.getUserVisibleName();
deviceType = device.getDeviceType();
primaryParamName = device.getPrimaryParamName();
params = device.getParams();
expanded = device.isExpanded();
selectedState = device.getSelectedState();
this.selected = selected;
this.type = type;
}
public SelectiveDevice(String id) {
nodeId = id;
}
public String getNodeId() {
return nodeId;
}
public String getDeviceName() {
return deviceName;
}
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
public String getUserVisibleName() {
return userVisibleName;
}
public void setUserVisibleName(String userVisibleName) {
this.userVisibleName = userVisibleName;
}
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
public String getPrimaryParamName() {
return primaryParamName;
}
public void setPrimaryParamName(String primaryParamName) {
this.primaryParamName = primaryParamName;
}
public ArrayList<Param> getParams() {
return params;
}
public void setParams(ArrayList<Param> params) {
this.params = params;
}
public int getSelectedState() {
return selectedState;
}
public void setSelectedState(int selectedState) {
this.selectedState = selectedState;
}
@Override
public String toString() {
return "EspDevice {" +
"node id = '" + nodeId + '\'' +
"name = '" + deviceName + '\'' +
", type ='" + deviceType + '\'' +
'}';
}
public void setExpanded(boolean expanded) {
this.expanded = expanded;
}
public boolean isExpanded() {
return expanded;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
public boolean isSelected() {
return selected;
}
}
作为一名Android新手,我不太清楚我应该go 哪里看.