mirror of
https://github.com/niushuai233/DevControl.git
synced 2024-10-27 22:43:20 +08:00
feat: 开关新增保存到数据库
This commit is contained in:
@@ -2,5 +2,32 @@ package cc.niushuai.project.devcontrol.base.enums;
|
||||
|
||||
public enum OnOffEnum {
|
||||
|
||||
ON, OFF;
|
||||
ON("ON", "开"),
|
||||
OFF("OFF", "关"),
|
||||
;
|
||||
|
||||
private String value;
|
||||
private String text;
|
||||
|
||||
OnOffEnum(String value, String text) {
|
||||
this.value = value;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public static OnOffEnum matchByValue(String value) {
|
||||
for (OnOffEnum onOffEnum : OnOffEnum.values()) {
|
||||
if (onOffEnum.getValue().equals(value)) {
|
||||
return onOffEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
package cc.niushuai.project.devcontrol.base.enums;
|
||||
|
||||
public enum YesNoEnum {
|
||||
|
||||
YES("1", 1, "是"),
|
||||
NO("0",0, "否"),
|
||||
;
|
||||
|
||||
private String value;
|
||||
private Integer integerValue;
|
||||
private String text;
|
||||
|
||||
YesNoEnum(String value, Integer integerValue, String text) {
|
||||
this.value = value;
|
||||
this.integerValue = integerValue;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public Integer getIntegerValue() {
|
||||
return integerValue;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public static YesNoEnum matchByValue(String value) {
|
||||
for (YesNoEnum onOffEnum : YesNoEnum.values()) {
|
||||
if (onOffEnum.getValue().equals(value)) {
|
||||
return onOffEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import androidx.appcompat.widget.AppCompatImageButton;
|
||||
import java.util.Map;
|
||||
|
||||
import cc.niushuai.project.devcontrol.R;
|
||||
import cc.niushuai.project.devcontrol.base.util.GlobalVariables;
|
||||
import cc.niushuai.project.devcontrol.vo.DeviceInfo;
|
||||
import cc.niushuai.project.devcontrol.base.util.ActivityUtil;
|
||||
import cc.niushuai.project.devcontrol.base.util.Keys;
|
||||
@@ -146,4 +147,13 @@ public abstract class BaseActivity extends AppCompatActivity {
|
||||
findViewById(R.id.activity_title_more_set).setOnClickListener(onClickListener);
|
||||
}
|
||||
|
||||
/**
|
||||
* 重建缓存
|
||||
*
|
||||
* @author niushuai
|
||||
* @date: 2022/10/24 17:09
|
||||
*/
|
||||
public void rebuildDeviceInfoMapCache() {
|
||||
GlobalVariables.initDeviceInfoMap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package cc.niushuai.project.devcontrol.base.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import cc.niushuai.project.devcontrol.db.DB;
|
||||
import cc.niushuai.project.devcontrol.db.entity.Device;
|
||||
import cc.niushuai.project.devcontrol.vo.DeviceInfo;
|
||||
import cc.niushuai.project.devcontrol.base.ui.BaseActivity;
|
||||
|
||||
@@ -14,6 +17,21 @@ public class GlobalVariables {
|
||||
*/
|
||||
public static final Map<String, DeviceInfo> DEVICE_INFO_MAP = new HashMap<>(16);
|
||||
|
||||
/**
|
||||
* 初始化设备列表到缓存中
|
||||
*
|
||||
* @author niushuai
|
||||
* @date: 2022/10/24 17:08
|
||||
*/
|
||||
public static void initDeviceInfoMap() {
|
||||
DEVICE_INFO_MAP.clear();
|
||||
List<Device> deviceList = DB.getDeviceDao().loadAll();
|
||||
|
||||
for (Device device : deviceList) {
|
||||
DEVICE_INFO_MAP.put(device.getId() + "", DeviceInfo.convert(device));
|
||||
}
|
||||
}
|
||||
|
||||
public static Class<? extends BaseActivity> getDeviceAddActivity(String deviceId) {
|
||||
return getDeviceInfo(deviceId).getDeviceType().getDeviceAddActivity();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user