From 8f948be1bf21842b02e604dde427130ccfdbd76a Mon Sep 17 00:00:00 2001 From: niushuai233 Date: Thu, 27 Oct 2022 17:20:33 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=97=A5=E5=BF=97=E6=80=BB=E5=BC=80?= =?UTF-8?q?=E5=85=B3=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../project/devcontrol/base/util/Keys.java | 4 + .../project/devcontrol/base/util/XLog.java | 20 +++++ .../cc/niushuai/project/devcontrol/db/DB.java | 24 ++++++ .../devcontrol/db/entity/SysConfig.java | 82 ++++++++++++++++++ .../ui/nav/setup/NavSetUpFragment.java | 84 ++++++++++++++++--- .../res/layout/main_nav_fragment_set_up.xml | 6 +- app/src/main/res/values/strings.xml | 8 ++ 7 files changed, 215 insertions(+), 13 deletions(-) create mode 100644 app/src/main/java/cc/niushuai/project/devcontrol/db/entity/SysConfig.java diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/Keys.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/Keys.java index 98e3abc..c49bd1e 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/Keys.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/Keys.java @@ -12,6 +12,10 @@ public interface Keys { String LOG_SUFFIX = ".log"; + String SETUP_LOG_SWITCH = "setup_log_switch"; + String SETUP_LOG_LEVEL = "setup_log_level"; + String SETUP_LOG_KEEP_DAY = "setup_log_keep_day"; + interface Tag { String MY_OPEN_HELPER = "MyOpenHelper"; diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/XLog.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/XLog.java index f664efe..6af5b92 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/XLog.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/XLog.java @@ -210,26 +210,31 @@ public class XLog { * 详细 */ public static final int VERBOSE = 2; + public static final String VERBOSE_NAME = "VERBOSE"; /** * 调试 */ public static final int DEBUG = 3; + public static final String DEBUG_NAME = "DEBUG"; /** * 一般 */ public static final int INFO = 4; + public static final String INFO_NAME = "INFO"; /** * 警告 */ public static final int WARN = 5; + public static final String WARN_NAME = "WARN"; /** * 错误 */ public static final int ERROR = 6; + public static final String ERROR_NAME = "ERROR"; public static String transform(int level) { String str = "VERBOSE"; @@ -246,5 +251,20 @@ public class XLog { } return String.format("%7s", str); } + + public static int transform(String level) { + if (VERBOSE_NAME.equals(level)) { + return VERBOSE; + } else if (DEBUG_NAME.equals(level)) { + return DEBUG; + } else if (INFO_NAME.equals(level)) { + return INFO; + } else if (WARN_NAME.equals(level)) { + return WARN; + } else if (ERROR_NAME.equals(level)) { + return ERROR; + } + return -1; + } } } diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/db/DB.java b/app/src/main/java/cc/niushuai/project/devcontrol/db/DB.java index 1cb6708..b5026a7 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/db/DB.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/db/DB.java @@ -4,9 +4,11 @@ import android.content.Context; import cc.niushuai.project.devcontrol.base.util.Keys; import cc.niushuai.project.devcontrol.base.util.XLog; +import cc.niushuai.project.devcontrol.db.greendao.gen.CommandExtDao; import cc.niushuai.project.devcontrol.db.greendao.gen.DaoMaster; import cc.niushuai.project.devcontrol.db.greendao.gen.DaoSession; import cc.niushuai.project.devcontrol.db.greendao.gen.DeviceDao; +import cc.niushuai.project.devcontrol.db.greendao.gen.SysConfigDao; import cc.niushuai.project.devcontrol.db.util.MyOpenHelper; /** @@ -56,6 +58,28 @@ public class DB { return session().getDeviceDao(); } + /** + * 设备扩展命令操作入口 + * + * @author niushuai + * @date: 2022/10/24 11:05 + * @return: {@link DeviceDao} + */ + public static CommandExtDao getCommandExtDao() { + return session().getCommandExtDao(); + } + + /** + * 系统设置操作入口 + * + * @author niushuai + * @date: 2022/10/24 11:05 + * @return: {@link DeviceDao} + */ + public static SysConfigDao getSysConfigDao() { + return session().getSysConfigDao(); + } + /** * 初始化数据库表结构 * diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/db/entity/SysConfig.java b/app/src/main/java/cc/niushuai/project/devcontrol/db/entity/SysConfig.java new file mode 100644 index 0000000..a28adc2 --- /dev/null +++ b/app/src/main/java/cc/niushuai/project/devcontrol/db/entity/SysConfig.java @@ -0,0 +1,82 @@ +package cc.niushuai.project.devcontrol.db.entity; + +import org.greenrobot.greendao.annotation.Entity; +import org.greenrobot.greendao.annotation.Id; +import org.greenrobot.greendao.annotation.Index; +import org.greenrobot.greendao.annotation.Generated; + +/** + * 设置项 + * + * @author niushuai233 + * @date 2022/10/27 16:19 + */ +@Entity(nameInDb = "tb_dc_config") +public class SysConfig { + + @Id + private Long id; + + @Index + private String key; + + private String value; + + private String createTime; + + private String updateTime; + + @Generated(hash = 1067865333) + public SysConfig(Long id, String key, String value, String createTime, + String updateTime) { + this.id = id; + this.key = key; + this.value = value; + this.createTime = createTime; + this.updateTime = updateTime; + } + + @Generated(hash = 1454359576) + public SysConfig() { + } + + public Long getId() { + return this.id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getKey() { + return this.key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getValue() { + return this.value; + } + + public void setValue(String value) { + this.value = value; + } + + public String getCreateTime() { + return this.createTime; + } + + public void setCreateTime(String createTime) { + this.createTime = createTime; + } + + public String getUpdateTime() { + return this.updateTime; + } + + public void setUpdateTime(String updateTime) { + this.updateTime = updateTime; + } +} diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/setup/NavSetUpFragment.java b/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/setup/NavSetUpFragment.java index 74e92fe..8e776c4 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/setup/NavSetUpFragment.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/setup/NavSetUpFragment.java @@ -4,27 +4,34 @@ import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; +import android.widget.AdapterView; -import androidx.annotation.Nullable; -import androidx.fragment.app.Fragment; -import androidx.lifecycle.LifecycleObserver; -import androidx.lifecycle.ViewModelProvider; +import androidx.annotation.NonNull; + +import java.util.List; import cc.niushuai.project.devcontrol.base.ui.BaseFragment; +import cc.niushuai.project.devcontrol.base.util.Global; +import cc.niushuai.project.devcontrol.base.util.IdWorker; +import cc.niushuai.project.devcontrol.base.util.Keys; +import cc.niushuai.project.devcontrol.base.util.XLog; import cc.niushuai.project.devcontrol.databinding.MainNavFragmentSetUpBinding; +import cc.niushuai.project.devcontrol.db.DB; +import cc.niushuai.project.devcontrol.db.entity.SysConfig; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.date.DateUtil; public class NavSetUpFragment extends BaseFragment { - private MainNavFragmentSetUpBinding navFragmentSetUpBinding; + private MainNavFragmentSetUpBinding binding; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - navFragmentSetUpBinding = MainNavFragmentSetUpBinding.inflate(getLayoutInflater()); + binding = MainNavFragmentSetUpBinding.inflate(getLayoutInflater()); - View rootView = navFragmentSetUpBinding.getRoot(); + View rootView = binding.getRoot(); this.init(); this.addListener(); @@ -33,18 +40,73 @@ public class NavSetUpFragment extends BaseFragment { return rootView; } - private void addListener() { + private void init() { } - private void init() { + private void addListener() { + // 备份点击事件 + binding.setupLlGeneralBackup.setOnClickListener(this::setupBackupClickListener); + // 恢复点击事件 + binding.setupLlGeneralRestore.setOnClickListener(this::setupRestoreClickListener); + // 日志总开关点击事件 + binding.setupLogSwitchSwitch.setOnClickListener(this::setupLogSwitchClickListener); + // 日志级别点击事件 + binding.setupLogLevelSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView parent, View view, int position, long id) { + + } + + @Override + public void onNothingSelected(AdapterView parent) { + + } + }); + // 日志保留天数点击事件 + binding.setupLlLogKeepDay.setOnClickListener(this::setupKeepDayClickListener); + + } + + private void setupBackupClickListener(View view) { + } + + private void setupRestoreClickListener(View view) { + } + + /** + * 日志总开关点击触发 + * + * @param view + * @author niushuai + * @date: 2022/10/27 17:00 + */ + private void setupLogSwitchClickListener(View view) { + Boolean checked = binding.setupLogSwitchSwitch.isChecked(); + XLog.LOG_SWITCH = checked; + + List list = DB.getSysConfigDao().queryRaw("where key = ?", Keys.SETUP_LOG_SWITCH); + if (CollUtil.isNotEmpty(list)) { + // 已存在 更新操作 + SysConfig updateEntity = list.get(0); + updateEntity.setValue(checked.toString()); + updateEntity.setUpdateTime(DateUtil.now()); + + DB.getSysConfigDao().update(updateEntity); + return; + } + // 新增操作 + DB.getSysConfigDao().insert(new SysConfig(IdWorker.getNextId(), Keys.SETUP_LOG_SWITCH, checked.toString(), DateUtil.now(), DateUtil.now())); + } + + private void setupKeepDayClickListener(View view) { } @Override public void onDestroyView() { super.onDestroyView(); - navFragmentSetUpBinding = null; + binding = null; } } \ No newline at end of file diff --git a/app/src/main/res/layout/main_nav_fragment_set_up.xml b/app/src/main/res/layout/main_nav_fragment_set_up.xml index 135cded..9770e32 100644 --- a/app/src/main/res/layout/main_nav_fragment_set_up.xml +++ b/app/src/main/res/layout/main_nav_fragment_set_up.xml @@ -107,9 +107,11 @@ style="@style/SetupText" android:text="@string/setup_log_level" /> - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 71e2bf0..80cfbad 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -35,6 +35,14 @@ 总开关 日志级别 保留天数 + + + VERBOSE + DEBUG + INFO + WARN + ERROR +