mirror of
https://github.com/niushuai233/DevControl.git
synced 2024-10-27 22:43:20 +08:00
feat: 日志总开关设置
This commit is contained in:
parent
d74da75b35
commit
8f948be1bf
@ -12,6 +12,10 @@ public interface Keys {
|
|||||||
|
|
||||||
String LOG_SUFFIX = ".log";
|
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 {
|
interface Tag {
|
||||||
String MY_OPEN_HELPER = "MyOpenHelper";
|
String MY_OPEN_HELPER = "MyOpenHelper";
|
||||||
|
|
||||||
|
@ -210,26 +210,31 @@ public class XLog {
|
|||||||
* 详细
|
* 详细
|
||||||
*/
|
*/
|
||||||
public static final int VERBOSE = 2;
|
public static final int VERBOSE = 2;
|
||||||
|
public static final String VERBOSE_NAME = "VERBOSE";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 调试
|
* 调试
|
||||||
*/
|
*/
|
||||||
public static final int DEBUG = 3;
|
public static final int DEBUG = 3;
|
||||||
|
public static final String DEBUG_NAME = "DEBUG";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 一般
|
* 一般
|
||||||
*/
|
*/
|
||||||
public static final int INFO = 4;
|
public static final int INFO = 4;
|
||||||
|
public static final String INFO_NAME = "INFO";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 警告
|
* 警告
|
||||||
*/
|
*/
|
||||||
public static final int WARN = 5;
|
public static final int WARN = 5;
|
||||||
|
public static final String WARN_NAME = "WARN";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 错误
|
* 错误
|
||||||
*/
|
*/
|
||||||
public static final int ERROR = 6;
|
public static final int ERROR = 6;
|
||||||
|
public static final String ERROR_NAME = "ERROR";
|
||||||
|
|
||||||
public static String transform(int level) {
|
public static String transform(int level) {
|
||||||
String str = "VERBOSE";
|
String str = "VERBOSE";
|
||||||
@ -246,5 +251,20 @@ public class XLog {
|
|||||||
}
|
}
|
||||||
return String.format("%7s", str);
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,11 @@ import android.content.Context;
|
|||||||
|
|
||||||
import cc.niushuai.project.devcontrol.base.util.Keys;
|
import cc.niushuai.project.devcontrol.base.util.Keys;
|
||||||
import cc.niushuai.project.devcontrol.base.util.XLog;
|
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.DaoMaster;
|
||||||
import cc.niushuai.project.devcontrol.db.greendao.gen.DaoSession;
|
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.DeviceDao;
|
||||||
|
import cc.niushuai.project.devcontrol.db.greendao.gen.SysConfigDao;
|
||||||
import cc.niushuai.project.devcontrol.db.util.MyOpenHelper;
|
import cc.niushuai.project.devcontrol.db.util.MyOpenHelper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -56,6 +58,28 @@ public class DB {
|
|||||||
return session().getDeviceDao();
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化数据库表结构
|
* 初始化数据库表结构
|
||||||
*
|
*
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -4,27 +4,34 @@ import android.os.Bundle;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.AdapterView;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import androidx.lifecycle.LifecycleObserver;
|
import java.util.List;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
|
||||||
|
|
||||||
import cc.niushuai.project.devcontrol.base.ui.BaseFragment;
|
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.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 {
|
public class NavSetUpFragment extends BaseFragment {
|
||||||
|
|
||||||
private MainNavFragmentSetUpBinding navFragmentSetUpBinding;
|
private MainNavFragmentSetUpBinding binding;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
|
|
||||||
navFragmentSetUpBinding = MainNavFragmentSetUpBinding.inflate(getLayoutInflater());
|
binding = MainNavFragmentSetUpBinding.inflate(getLayoutInflater());
|
||||||
|
|
||||||
View rootView = navFragmentSetUpBinding.getRoot();
|
View rootView = binding.getRoot();
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
this.addListener();
|
this.addListener();
|
||||||
@ -33,18 +40,73 @@ public class NavSetUpFragment extends BaseFragment {
|
|||||||
return rootView;
|
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<SysConfig> 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
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
navFragmentSetUpBinding = null;
|
binding = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -107,9 +107,11 @@
|
|||||||
style="@style/SetupText"
|
style="@style/SetupText"
|
||||||
android:text="@string/setup_log_level" />
|
android:text="@string/setup_log_level" />
|
||||||
|
|
||||||
<TextView
|
<Spinner
|
||||||
android:id="@+id/setup_log_level_display"
|
android:id="@+id/setup_log_level_spinner"
|
||||||
style="@style/SetupExt"
|
style="@style/SetupExt"
|
||||||
|
android:entries="@array/logLevel"
|
||||||
|
|
||||||
/>
|
/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@ -35,6 +35,14 @@
|
|||||||
<string name="setup_log_switch">总开关</string>
|
<string name="setup_log_switch">总开关</string>
|
||||||
<string name="setup_log_level">日志级别</string>
|
<string name="setup_log_level">日志级别</string>
|
||||||
<string name="setup_log_keep_day">保留天数</string>
|
<string name="setup_log_keep_day">保留天数</string>
|
||||||
|
|
||||||
|
<string-array name="logLevel">
|
||||||
|
<item>VERBOSE</item>
|
||||||
|
<item>DEBUG</item>
|
||||||
|
<item>INFO</item>
|
||||||
|
<item>WARN</item>
|
||||||
|
<item>ERROR</item>
|
||||||
|
</string-array>
|
||||||
<!--设置页面 end-->
|
<!--设置页面 end-->
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user