mirror of
https://github.com/niushuai233/DevControl.git
synced 2024-10-27 22:43:20 +08:00
fix: 实现开关设备更新操作
This commit is contained in:
parent
5b3497ea4f
commit
3f376200e5
@ -28,7 +28,7 @@ public class GlobalVariables {
|
|||||||
List<Device> deviceList = DB.getDeviceDao().loadAll();
|
List<Device> deviceList = DB.getDeviceDao().loadAll();
|
||||||
|
|
||||||
for (Device device : deviceList) {
|
for (Device device : deviceList) {
|
||||||
DEVICE_INFO_MAP.put(device.getId() + "", DeviceInfo.convert(device));
|
DEVICE_INFO_MAP.put(device.getId() + "", DeviceInfo.parseDevice(device));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
|
|||||||
|
|
||||||
import cc.niushuai.project.devcontrol.R;
|
import cc.niushuai.project.devcontrol.R;
|
||||||
import cc.niushuai.project.devcontrol.base.enums.YesNoEnum;
|
import cc.niushuai.project.devcontrol.base.enums.YesNoEnum;
|
||||||
|
import cc.niushuai.project.devcontrol.base.util.CommonUiUtil;
|
||||||
import cc.niushuai.project.devcontrol.base.util.IdWorker;
|
import cc.niushuai.project.devcontrol.base.util.IdWorker;
|
||||||
import cc.niushuai.project.devcontrol.base.util.UiUtil;
|
import cc.niushuai.project.devcontrol.base.util.UiUtil;
|
||||||
import cc.niushuai.project.devcontrol.db.DB;
|
import cc.niushuai.project.devcontrol.db.DB;
|
||||||
@ -72,18 +73,12 @@ public class DeviceAddPowerSwitchActivity extends BaseActivity {
|
|||||||
* @date: 2022/10/21 14:20
|
* @date: 2022/10/21 14:20
|
||||||
*/
|
*/
|
||||||
private void confirm4SaveDataClickListener(View view) {
|
private void confirm4SaveDataClickListener(View view) {
|
||||||
Device device = new Device();
|
Device device = CommonUiUtil.getDeviceInfo(this, IdWorker.getNextId());
|
||||||
|
|
||||||
device.setId(IdWorker.getNextId());
|
|
||||||
device.setIconId(R.drawable.ic_device_type_switch);
|
device.setIconId(R.drawable.ic_device_type_switch);
|
||||||
device.setDeviceType(DeviceTypeEnum.Power_Switch.getValue());
|
device.setDeviceType(DeviceTypeEnum.Power_Switch.getValue());
|
||||||
device.setOnOff(OnOffEnum.OFF.getValue());
|
device.setOnOff(OnOffEnum.OFF.getValue());
|
||||||
device.setDeviceName(UiUtil.getTextViewTextById(this, R.id.device_add_name));
|
|
||||||
device.setCommandPath(UiUtil.getTextViewTextById(this,R.id.device_add_param_program));
|
|
||||||
device.setCommandStatus(UiUtil.getTextViewTextById(this,R.id.device_add_param_status));
|
|
||||||
device.setCommandOpen(UiUtil.getTextViewTextById(this,R.id.device_add_param_open));
|
|
||||||
device.setCommandClose(UiUtil.getTextViewTextById(this,R.id.device_add_param_close));
|
|
||||||
device.setRemark(UiUtil.getTextViewTextById(this,R.id.device_add_param_remark));
|
|
||||||
device.setCreateTime(DateUtil.now());
|
device.setCreateTime(DateUtil.now());
|
||||||
device.setOrder(1);
|
device.setOrder(1);
|
||||||
device.setIsDeleted(YesNoEnum.NO.getIntegerValue());
|
device.setIsDeleted(YesNoEnum.NO.getIntegerValue());
|
||||||
|
@ -77,7 +77,12 @@ public class NavDeviceFragment extends Fragment {
|
|||||||
|
|
||||||
deviceInfoList = GlobalVariables.DEVICE_INFO_MAP.values()
|
deviceInfoList = GlobalVariables.DEVICE_INFO_MAP.values()
|
||||||
.stream()
|
.stream()
|
||||||
.sorted(Comparator.comparingInt(DeviceInfo::getOrder))
|
.sorted((before, after) -> {
|
||||||
|
if (null == before.getOrder() || null == after.getOrder()) {
|
||||||
|
return 99999;
|
||||||
|
}
|
||||||
|
return before.getOrder() - after.getOrder();
|
||||||
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// GridLayout deviceGridLayout = binding.deviceGridLayout;
|
// GridLayout deviceGridLayout = binding.deviceGridLayout;
|
||||||
|
@ -7,13 +7,20 @@ import android.widget.Toast;
|
|||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import cc.niushuai.project.devcontrol.R;
|
import cc.niushuai.project.devcontrol.R;
|
||||||
|
import cc.niushuai.project.devcontrol.base.enums.DeviceTypeEnum;
|
||||||
|
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.CommonUiUtil;
|
||||||
import cc.niushuai.project.devcontrol.base.util.GlobalVariables;
|
import cc.niushuai.project.devcontrol.base.util.GlobalVariables;
|
||||||
import cc.niushuai.project.devcontrol.base.util.ToastUtil;
|
import cc.niushuai.project.devcontrol.base.util.ToastUtil;
|
||||||
import cc.niushuai.project.devcontrol.base.util.UiUtil;
|
import cc.niushuai.project.devcontrol.base.util.UiUtil;
|
||||||
import cc.niushuai.project.devcontrol.databinding.ActivityPowerSwitchSetParamBinding;
|
import cc.niushuai.project.devcontrol.databinding.ActivityPowerSwitchSetParamBinding;
|
||||||
|
import cc.niushuai.project.devcontrol.db.DB;
|
||||||
|
import cc.niushuai.project.devcontrol.db.entity.Device;
|
||||||
|
import cc.niushuai.project.devcontrol.vo.DeviceInfo;
|
||||||
|
|
||||||
public class PowerSwitchSetParamActivity extends BaseActivity {
|
public class PowerSwitchSetParamActivity extends BaseActivity {
|
||||||
|
|
||||||
@ -36,27 +43,12 @@ public class PowerSwitchSetParamActivity extends BaseActivity {
|
|||||||
|
|
||||||
this.setTitle(null, getString(R.string.power_switch_set_paramSet), null, R.drawable.ic_confrim_32);
|
this.setTitle(null, getString(R.string.power_switch_set_paramSet), null, R.drawable.ic_confrim_32);
|
||||||
|
|
||||||
this.echoData();
|
// 回显数据
|
||||||
|
CommonUiUtil.echoDeviceInfo(this, device);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 回显数据
|
|
||||||
*
|
|
||||||
* @author niushuai
|
|
||||||
* @date: 2022/10/25 9:01
|
|
||||||
*/
|
|
||||||
private void echoData() {
|
|
||||||
|
|
||||||
UiUtil.setTextViewTextById(this, R.id.device_add_name, device.getDeviceName());
|
|
||||||
UiUtil.setTextViewTextById(this, R.id.device_add_param_program, device.getCommandPath());
|
|
||||||
UiUtil.setTextViewTextById(this, R.id.device_add_param_status, device.getCommandStatus());
|
|
||||||
UiUtil.setTextViewTextById(this, R.id.device_add_param_open, device.getCommandOpen());
|
|
||||||
UiUtil.setTextViewTextById(this, R.id.device_add_param_close, device.getCommandClose());
|
|
||||||
UiUtil.setTextViewTextById(this, R.id.device_add_param_remark, device.getRemark());
|
|
||||||
|
|
||||||
UiUtil.setAppImageCompatResource(this, R.id.device_add_select_icon, device.getIconId());
|
|
||||||
}
|
|
||||||
@Override
|
@Override
|
||||||
protected void addListener() {
|
protected void addListener() {
|
||||||
|
|
||||||
@ -66,9 +58,29 @@ public class PowerSwitchSetParamActivity extends BaseActivity {
|
|||||||
super.activityButtonMoreSetClickListener(this::btnSaveParamClickListener);
|
super.activityButtonMoreSetClickListener(this::btnSaveParamClickListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新数据操作
|
||||||
|
*
|
||||||
|
* @param view
|
||||||
|
* @author niushuai
|
||||||
|
* @date: 2022/10/25 13:56
|
||||||
|
*/
|
||||||
private void btnSaveParamClickListener(View view) {
|
private void btnSaveParamClickListener(View view) {
|
||||||
|
// 构建更新数据
|
||||||
|
DeviceInfo deviceInfo = CommonUiUtil.getDeviceInfo(this, device.getId());
|
||||||
|
deviceInfo.setDeviceType(device.getDeviceType());
|
||||||
|
deviceInfo.setOnOff(device.getOnOff());
|
||||||
|
deviceInfo.setOrder(device.getOrder());
|
||||||
|
deviceInfo.setIconId(device.getIconId());
|
||||||
|
deviceInfo.setIsDeleted(device.getIsDeleted());
|
||||||
|
deviceInfo.setCreateTime(device.getCreateTime());
|
||||||
|
DB.getDeviceDao().update(deviceInfo.toDevice());
|
||||||
|
|
||||||
ToastUtil.show(this, "已保存");
|
// 对当前设备引用重新赋值
|
||||||
|
device = deviceInfo;
|
||||||
|
|
||||||
|
// 返回上一层
|
||||||
|
this.finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -6,10 +6,10 @@ import java.util.List;
|
|||||||
import cc.niushuai.project.devcontrol.base.entity.BaseVO;
|
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.DateFormatUtil;
|
||||||
import cc.niushuai.project.devcontrol.base.util.GlobalVariables;
|
import cc.niushuai.project.devcontrol.base.util.GlobalVariables;
|
||||||
import cc.niushuai.project.devcontrol.base.util.IdWorker;
|
import cc.niushuai.project.devcontrol.base.util.IdWorker;
|
||||||
import cc.niushuai.project.devcontrol.db.entity.Device;
|
import cc.niushuai.project.devcontrol.db.entity.Device;
|
||||||
import cn.hutool.core.date.DateUtil;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设备信息实体数据类
|
* 设备信息实体数据类
|
||||||
@ -181,7 +181,15 @@ public class DeviceInfo extends BaseVO {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DeviceInfo convert(Device device) {
|
/**
|
||||||
|
* device to deviceInfo
|
||||||
|
*
|
||||||
|
* @param device
|
||||||
|
* @author niushuai
|
||||||
|
* @date: 2022/10/25 14:13
|
||||||
|
* @return: {@link DeviceInfo}
|
||||||
|
*/
|
||||||
|
public static DeviceInfo parseDevice(Device device) {
|
||||||
|
|
||||||
DeviceInfo _this = new DeviceInfo();
|
DeviceInfo _this = new DeviceInfo();
|
||||||
_this.setId(device.getId() + "");
|
_this.setId(device.getId() + "");
|
||||||
@ -196,8 +204,35 @@ public class DeviceInfo extends BaseVO {
|
|||||||
_this.setCommandClose(device.getCommandClose());
|
_this.setCommandClose(device.getCommandClose());
|
||||||
_this.setOrder(device.getOrder());
|
_this.setOrder(device.getOrder());
|
||||||
_this.setIsDeleted(device.getIsDeleted());
|
_this.setIsDeleted(device.getIsDeleted());
|
||||||
_this.setCreateTime(DateUtil.parseDateTime(device.getCreateTime()));
|
_this.setCreateTime(DateFormatUtil.parseDateTime(device.getCreateTime()));
|
||||||
|
|
||||||
return _this;
|
return _this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deviceInfo to device
|
||||||
|
*
|
||||||
|
* @author niushuai
|
||||||
|
* @date: 2022/10/25 14:13
|
||||||
|
* @return: {@link Device}
|
||||||
|
*/
|
||||||
|
public Device toDevice() {
|
||||||
|
Device to = new Device();
|
||||||
|
to.setId(Long.valueOf(this.getId()));
|
||||||
|
to.setDeviceName(this.getDeviceName());
|
||||||
|
to.setDeviceType(this.getDeviceType().getValue());
|
||||||
|
to.setOnOff(this.getOnOff().getValue());
|
||||||
|
to.setRemark(this.getRemark());
|
||||||
|
to.setIconId(this.getIconId());
|
||||||
|
to.setCommandPath(this.getCommandPath());
|
||||||
|
to.setCommandStatus(this.getCommandStatus());
|
||||||
|
to.setCommandOpen(this.getCommandOpen());
|
||||||
|
to.setCommandClose(this.getCommandClose());
|
||||||
|
to.setOrder(this.getOrder());
|
||||||
|
to.setIsDeleted(this.getIsDeleted());
|
||||||
|
to.setCreateTime(DateFormatUtil.formatDateTime(this.getCreateTime()));
|
||||||
|
|
||||||
|
return to;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user