refactor: 结构重组

This commit is contained in:
niushuai233 2022-10-24 16:03:26 +08:00
parent af5212a0be
commit b301ffff70
7 changed files with 79 additions and 52 deletions

View File

@ -0,0 +1,55 @@
package cc.niushuai.project.devcontrol.base.entity;
import java.io.Serializable;
import java.util.Date;
/**
* vo基类
*
* @author niushuai233
* @date 2022/10/24 15:58
*/
public class BaseVO implements Serializable {
private static final long serialVersionUID = 6464433262287575127L;
private String id;
private Integer isDeleted;
private String remark;
private Date createTime;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public Integer getIsDeleted() {
return isDeleted;
}
public void setIsDeleted(Integer isDeleted) {
this.isDeleted = isDeleted;
}
public String getRemark() {
return remark;
}
public void setRemark(String remark) {
this.remark = remark;
}
public Date getCreateTime() {
return createTime;
}
public void setCreateTime(Date createTime) {
this.createTime = createTime;
}
}

View File

@ -9,7 +9,7 @@ import androidx.appcompat.widget.AppCompatImageButton;
import java.util.Map; import java.util.Map;
import cc.niushuai.project.devcontrol.R; import cc.niushuai.project.devcontrol.R;
import cc.niushuai.project.devcontrol.base.entity.device.DeviceInfo; import cc.niushuai.project.devcontrol.vo.DeviceInfo;
import cc.niushuai.project.devcontrol.base.util.ActivityUtil; import cc.niushuai.project.devcontrol.base.util.ActivityUtil;
import cc.niushuai.project.devcontrol.base.util.Keys; import cc.niushuai.project.devcontrol.base.util.Keys;
import cc.niushuai.project.devcontrol.base.util.UiUtil; import cc.niushuai.project.devcontrol.base.util.UiUtil;

View File

@ -3,7 +3,7 @@ package cc.niushuai.project.devcontrol.base.util;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import cc.niushuai.project.devcontrol.base.entity.device.DeviceInfo; import cc.niushuai.project.devcontrol.vo.DeviceInfo;
import cc.niushuai.project.devcontrol.base.ui.BaseActivity; import cc.niushuai.project.devcontrol.base.ui.BaseActivity;
public class GlobalVariables { public class GlobalVariables {

View File

@ -3,10 +3,9 @@ package cc.niushuai.project.devcontrol.ui.deviceadd;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.widget.Toast;
import cc.niushuai.project.devcontrol.R; import cc.niushuai.project.devcontrol.R;
import cc.niushuai.project.devcontrol.base.entity.device.DeviceInfo; import cc.niushuai.project.devcontrol.vo.DeviceInfo;
import cc.niushuai.project.devcontrol.base.enums.DeviceTypeEnum; import cc.niushuai.project.devcontrol.base.enums.DeviceTypeEnum;
import cc.niushuai.project.devcontrol.base.enums.OnOffEnum; import cc.niushuai.project.devcontrol.base.enums.OnOffEnum;
import cc.niushuai.project.devcontrol.base.ui.BaseActivity; import cc.niushuai.project.devcontrol.base.ui.BaseActivity;
@ -70,15 +69,15 @@ public class DeviceAddPowerSwitchActivity extends BaseActivity {
device.setIconId(R.drawable.ic_device_type_switch); device.setIconId(R.drawable.ic_device_type_switch);
device.setDeviceType(DeviceTypeEnum.Power_Switch); device.setDeviceType(DeviceTypeEnum.Power_Switch);
device.setOnOff(OnOffEnum.OFF); device.setOnOff(OnOffEnum.OFF);
device.setName(binding.deviceAddName.getText().toString()); device.setDeviceName(binding.deviceAddName.getText().toString());
device.setDescription("默认设备"); device.setRemark("默认设备");
device.setCommandPath(binding.deviceAddParamProgram.getText().toString()); device.setCommandPath(binding.deviceAddParamProgram.getText().toString());
device.setCommandOpen(binding.deviceAddParamOpen.getText().toString()); device.setCommandOpen(binding.deviceAddParamOpen.getText().toString());
device.setCommandClose(binding.deviceAddParamClose.getText().toString()); device.setCommandClose(binding.deviceAddParamClose.getText().toString());
GlobalVariables.DEVICE_INFO_MAP.put(device.getId(), device); GlobalVariables.DEVICE_INFO_MAP.put(device.getId(), device);
ToastUtil.show(this, StrUtil.format("设备: {} 已新增", device.getName())); ToastUtil.show(this, StrUtil.format("设备: {} 已新增", device.getDeviceName()));
this.finish(); this.finish();
ActivityUtil.startActivity(this, PowerSwitchActivity.class, new String[]{Keys.ID}, new String[]{device.getId()}); ActivityUtil.startActivity(this, PowerSwitchActivity.class, new String[]{Keys.ID}, new String[]{device.getId()});

View File

@ -20,7 +20,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import cc.niushuai.project.devcontrol.R; import cc.niushuai.project.devcontrol.R;
import cc.niushuai.project.devcontrol.base.entity.device.DeviceInfo; import cc.niushuai.project.devcontrol.vo.DeviceInfo;
import cc.niushuai.project.devcontrol.base.util.GlobalVariables; import cc.niushuai.project.devcontrol.base.util.GlobalVariables;
import cc.niushuai.project.devcontrol.base.util.Keys; import cc.niushuai.project.devcontrol.base.util.Keys;
import cc.niushuai.project.devcontrol.databinding.DeviceItemBinding; import cc.niushuai.project.devcontrol.databinding.DeviceItemBinding;
@ -107,7 +107,7 @@ public class NavDeviceFragment extends Fragment {
// 设置当前设备的图标和名称 // 设置当前设备的图标和名称
m1.put("device_item_cardView_id", deviceInfo.getId()); m1.put("device_item_cardView_id", deviceInfo.getId());
m1.put("device_item_cardView_image", deviceInfo.getIconId()); m1.put("device_item_cardView_image", deviceInfo.getIconId());
m1.put("device_item_cardView_text", deviceInfo.getName()); m1.put("device_item_cardView_text", deviceInfo.getDeviceName());
// 统一添加到data中 // 统一添加到data中
gvData.add(m1); gvData.add(m1);

View File

@ -9,7 +9,6 @@ import androidx.appcompat.widget.AppCompatImageView;
import java.util.HashMap; import java.util.HashMap;
import cc.niushuai.project.devcontrol.R; import cc.niushuai.project.devcontrol.R;
import cc.niushuai.project.devcontrol.base.entity.device.DeviceInfo;
import cc.niushuai.project.devcontrol.base.enums.OnOffEnum; import cc.niushuai.project.devcontrol.base.enums.OnOffEnum;
import cc.niushuai.project.devcontrol.base.ui.BaseActivity; import cc.niushuai.project.devcontrol.base.ui.BaseActivity;
import cc.niushuai.project.devcontrol.base.util.GlobalVariables; import cc.niushuai.project.devcontrol.base.util.GlobalVariables;
@ -44,10 +43,10 @@ public class PowerSwitchActivity extends BaseActivity {
this.device = GlobalVariables.getDeviceInfo(getIntentDeviceId()); this.device = GlobalVariables.getDeviceInfo(getIntentDeviceId());
// 标题名称 // 标题名称
super.setTitle(this.device.getName(), this.device.getDescription()); super.setTitle(this.device.getDeviceName(), this.device.getRemark());
// 开关底部的名称 // 开关底部的名称
TextView contentTextTextView = findViewById(R.id.power_switch_activity_content_text); TextView contentTextTextView = findViewById(R.id.power_switch_activity_content_text);
contentTextTextView.setText(device.getName()); contentTextTextView.setText(device.getDeviceName());
} }
/** /**

View File

@ -1,13 +1,13 @@
package cc.niushuai.project.devcontrol.base.entity.device; package cc.niushuai.project.devcontrol.vo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import cc.niushuai.project.devcontrol.base.entity.BaseVO;
import cc.niushuai.project.devcontrol.base.enums.DeviceTypeEnum; import cc.niushuai.project.devcontrol.base.enums.DeviceTypeEnum;
import cc.niushuai.project.devcontrol.base.enums.OnOffEnum; import cc.niushuai.project.devcontrol.base.enums.OnOffEnum;
import cc.niushuai.project.devcontrol.base.util.GlobalVariables; import cc.niushuai.project.devcontrol.base.util.GlobalVariables;
import cn.hutool.core.util.IdUtil; import cc.niushuai.project.devcontrol.base.util.IdWorker;
import cn.hutool.core.util.StrUtil;
/** /**
* 设备信息实体数据类 * 设备信息实体数据类
@ -15,17 +15,12 @@ import cn.hutool.core.util.StrUtil;
* @author niushuai * @author niushuai
* @date: 2022/10/17 16:47 * @date: 2022/10/17 16:47
*/ */
public class DeviceInfo { public class DeviceInfo extends BaseVO {
/**
* 主id 唯一标识
*/
private String id;
/** /**
* 设备名称 * 设备名称
*/ */
private String name; private String deviceName;
/** /**
* 设备类型 * 设备类型
@ -37,11 +32,6 @@ public class DeviceInfo {
*/ */
private OnOffEnum onOff; private OnOffEnum onOff;
/**
* 设备描述信息
*/
private String description;
/** /**
* 设备列表界面 list icon id * 设备列表界面 list icon id
*/ */
@ -70,20 +60,12 @@ public class DeviceInfo {
*/ */
private List<String> commandExtra; private List<String> commandExtra;
public String getId() { public String getDeviceName() {
return id; return deviceName;
} }
public void setId(String id) { public void setDeviceName(String deviceName) {
this.id = id; this.deviceName = deviceName;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
} }
public DeviceTypeEnum getDeviceType() { public DeviceTypeEnum getDeviceType() {
@ -102,20 +84,12 @@ public class DeviceInfo {
this.onOff = onOff; this.onOff = onOff;
} }
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public int getIconId() { public int getIconId() {
return iconId; return iconId;
} }
public void setIconId(int listIconId) { public void setIconId(int iconId) {
this.iconId = listIconId; this.iconId = iconId;
} }
public String getCommandPath() { public String getCommandPath() {
@ -162,10 +136,10 @@ public class DeviceInfo {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
DeviceInfo device = new DeviceInfo(); DeviceInfo device = new DeviceInfo();
device.setId(IdUtil.nanoId()); device.setId(IdWorker.getNextIdStr());
device.setName("卧室灯开关" + (i + 1)); device.setDeviceName("卧室灯开关" + (i + 1));
device.setIconId(iconId); device.setIconId(iconId);
device.setDescription("卧室灯开关-树莓派"); device.setRemark("卧室灯开关-树莓派");
device.setDeviceType(DeviceTypeEnum.Power_Switch); device.setDeviceType(DeviceTypeEnum.Power_Switch);
device.setOnOff(OnOffEnum.OFF); device.setOnOff(OnOffEnum.OFF);
device.setCommandPath("/path/file"); device.setCommandPath("/path/file");