From b301ffff70a2b6381be504a23118d17a3e05b701 Mon Sep 17 00:00:00 2001 From: niushuai233 Date: Mon, 24 Oct 2022 16:03:26 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=BB=93=E6=9E=84=E9=87=8D?= =?UTF-8?q?=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../devcontrol/base/entity/BaseVO.java | 55 +++++++++++++++++++ .../devcontrol/base/ui/BaseActivity.java | 2 +- .../devcontrol/base/util/GlobalVariables.java | 2 +- .../DeviceAddPowerSwitchActivity.java | 9 ++- .../ui/nav/device/NavDeviceFragment.java | 4 +- .../ui/powerswitch/PowerSwitchActivity.java | 5 +- .../entity/device => vo}/DeviceInfo.java | 54 +++++------------- 7 files changed, 79 insertions(+), 52 deletions(-) create mode 100644 app/src/main/java/cc/niushuai/project/devcontrol/base/entity/BaseVO.java rename app/src/main/java/cc/niushuai/project/devcontrol/{base/entity/device => vo}/DeviceInfo.java (74%) diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/entity/BaseVO.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/entity/BaseVO.java new file mode 100644 index 0000000..c699762 --- /dev/null +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/entity/BaseVO.java @@ -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; + } +} diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/ui/BaseActivity.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/ui/BaseActivity.java index 20d0a39..c35d03c 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/ui/BaseActivity.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/ui/BaseActivity.java @@ -9,7 +9,7 @@ import androidx.appcompat.widget.AppCompatImageButton; import java.util.Map; 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.Keys; import cc.niushuai.project.devcontrol.base.util.UiUtil; 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 d6d8f85..33d9033 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 @@ -3,7 +3,7 @@ package cc.niushuai.project.devcontrol.base.util; import java.util.HashMap; 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; public class GlobalVariables { 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 index 1cad308..29d3f4b 100644 --- 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 @@ -3,10 +3,9 @@ package cc.niushuai.project.devcontrol.ui.deviceadd; import android.os.Bundle; import android.view.View; -import android.widget.Toast; 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.OnOffEnum; 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.setDeviceType(DeviceTypeEnum.Power_Switch); device.setOnOff(OnOffEnum.OFF); - device.setName(binding.deviceAddName.getText().toString()); - device.setDescription("默认设备"); + device.setDeviceName(binding.deviceAddName.getText().toString()); + device.setRemark("默认设备"); device.setCommandPath(binding.deviceAddParamProgram.getText().toString()); device.setCommandOpen(binding.deviceAddParamOpen.getText().toString()); device.setCommandClose(binding.deviceAddParamClose.getText().toString()); GlobalVariables.DEVICE_INFO_MAP.put(device.getId(), device); - ToastUtil.show(this, StrUtil.format("设备: {} 已新增", device.getName())); + ToastUtil.show(this, StrUtil.format("设备: {} 已新增", device.getDeviceName())); this.finish(); ActivityUtil.startActivity(this, PowerSwitchActivity.class, new String[]{Keys.ID}, new String[]{device.getId()}); 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 442f081..82ecdf7 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 @@ -20,7 +20,7 @@ import java.util.HashMap; import java.util.List; 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.Keys; 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_image", deviceInfo.getIconId()); - m1.put("device_item_cardView_text", deviceInfo.getName()); + m1.put("device_item_cardView_text", deviceInfo.getDeviceName()); // 统一添加到data中 gvData.add(m1); diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchActivity.java b/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchActivity.java index 1d858f4..e208fea 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchActivity.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/ui/powerswitch/PowerSwitchActivity.java @@ -9,7 +9,6 @@ import androidx.appcompat.widget.AppCompatImageView; import java.util.HashMap; 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.ui.BaseActivity; import cc.niushuai.project.devcontrol.base.util.GlobalVariables; @@ -44,10 +43,10 @@ public class PowerSwitchActivity extends BaseActivity { 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); - contentTextTextView.setText(device.getName()); + contentTextTextView.setText(device.getDeviceName()); } /** 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/vo/DeviceInfo.java similarity index 74% rename from app/src/main/java/cc/niushuai/project/devcontrol/base/entity/device/DeviceInfo.java rename to app/src/main/java/cc/niushuai/project/devcontrol/vo/DeviceInfo.java index 2d900bc..9bbeba2 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/entity/device/DeviceInfo.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/vo/DeviceInfo.java @@ -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.List; +import cc.niushuai.project.devcontrol.base.entity.BaseVO; import cc.niushuai.project.devcontrol.base.enums.DeviceTypeEnum; import cc.niushuai.project.devcontrol.base.enums.OnOffEnum; import cc.niushuai.project.devcontrol.base.util.GlobalVariables; -import cn.hutool.core.util.IdUtil; -import cn.hutool.core.util.StrUtil; +import cc.niushuai.project.devcontrol.base.util.IdWorker; /** * 设备信息实体数据类 @@ -15,17 +15,12 @@ import cn.hutool.core.util.StrUtil; * @author niushuai * @date: 2022/10/17 16:47 */ -public class DeviceInfo { - - /** - * 主id 唯一标识 - */ - private String id; +public class DeviceInfo extends BaseVO { /** * 设备名称 */ - private String name; + private String deviceName; /** * 设备类型 @@ -37,11 +32,6 @@ public class DeviceInfo { */ private OnOffEnum onOff; - /** - * 设备描述信息 - */ - private String description; - /** * 设备列表界面 list icon id */ @@ -70,20 +60,12 @@ public class DeviceInfo { */ private List commandExtra; - public String getId() { - return id; + public String getDeviceName() { + return deviceName; } - public void setId(String id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; + public void setDeviceName(String deviceName) { + this.deviceName = deviceName; } public DeviceTypeEnum getDeviceType() { @@ -102,20 +84,12 @@ public class DeviceInfo { this.onOff = onOff; } - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - public int getIconId() { return iconId; } - public void setIconId(int listIconId) { - this.iconId = listIconId; + public void setIconId(int iconId) { + this.iconId = iconId; } public String getCommandPath() { @@ -162,10 +136,10 @@ public class DeviceInfo { for (int i = 0; i < size; i++) { DeviceInfo device = new DeviceInfo(); - device.setId(IdUtil.nanoId()); - device.setName("卧室灯开关" + (i + 1)); + device.setId(IdWorker.getNextIdStr()); + device.setDeviceName("卧室灯开关" + (i + 1)); device.setIconId(iconId); - device.setDescription("卧室灯开关-树莓派"); + device.setRemark("卧室灯开关-树莓派"); device.setDeviceType(DeviceTypeEnum.Power_Switch); device.setOnOff(OnOffEnum.OFF); device.setCommandPath("/path/file");