mirror of
https://github.com/niushuai233/DevControl.git
synced 2024-10-27 22:43:20 +08:00
feat: 设置初始化数据
This commit is contained in:
parent
cac566ecf6
commit
0b815f783a
@ -25,22 +25,23 @@ public class XLog {
|
|||||||
/**
|
/**
|
||||||
* 日志总开关
|
* 日志总开关
|
||||||
*/
|
*/
|
||||||
public static boolean LOG_SWITCH = true;
|
public static Boolean LOG_SWITCH = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 是否写入到文件
|
* 是否写入到文件
|
||||||
*/
|
*/
|
||||||
public static boolean LOG_SWITCH_TO_FILE = true;
|
public static Boolean LOG_SWITCH_TO_FILE = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日志级别 默认info
|
* 日志级别 默认info
|
||||||
*/
|
*/
|
||||||
public static int SET_ROOT_LEVEL = Level.INFO;
|
public static Integer SET_ROOT_LEVEL = Level.INFO;
|
||||||
|
public static String SET_ROOT_LEVEL_NAME = Level.INFO_NAME;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 日志保存最长时间
|
* 日志保存最长时间
|
||||||
*/
|
*/
|
||||||
public static int LOG_SAVE_DAYS = 7;
|
public static Integer LOG_KEEP_DAY = 7;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
|
@ -4,6 +4,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import cc.niushuai.project.devcontrol.db.DB;
|
import cc.niushuai.project.devcontrol.db.DB;
|
||||||
import cc.niushuai.project.devcontrol.db.entity.SysConfig;
|
import cc.niushuai.project.devcontrol.db.entity.SysConfig;
|
||||||
|
import cn.hutool.core.collection.CollUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 抽取的公共方法
|
* 抽取的公共方法
|
||||||
@ -19,4 +20,10 @@ public class DBHelper {
|
|||||||
|
|
||||||
return DB.getSysConfigDao().queryRaw(WHERE_KEY, key);
|
return DB.getSysConfigDao().queryRaw(WHERE_KEY, key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static SysConfig configOneByKey(String key) {
|
||||||
|
|
||||||
|
List<SysConfig> list = DB.getSysConfigDao().queryRaw(WHERE_KEY, key);
|
||||||
|
return CollUtil.isEmpty(list) ? null : list.get(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import androidx.annotation.NonNull;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import cc.niushuai.project.devcontrol.R;
|
||||||
import cc.niushuai.project.devcontrol.base.ui.BaseFragment;
|
import cc.niushuai.project.devcontrol.base.ui.BaseFragment;
|
||||||
import cc.niushuai.project.devcontrol.base.util.IdWorker;
|
import cc.niushuai.project.devcontrol.base.util.IdWorker;
|
||||||
import cc.niushuai.project.devcontrol.base.util.Keys;
|
import cc.niushuai.project.devcontrol.base.util.Keys;
|
||||||
@ -43,6 +44,34 @@ public class NavSetUpFragment extends BaseFragment {
|
|||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
|
|
||||||
|
SysConfig switchConfig = DBHelper.configOneByKey(Keys.SETUP_LOG_SWITCH);
|
||||||
|
if (null == switchConfig) {
|
||||||
|
dealConfig(Keys.SETUP_LOG_SWITCH, XLog.LOG_SWITCH.toString());
|
||||||
|
} else {
|
||||||
|
binding.setupLogSwitchSwitch.setChecked(Boolean.parseBoolean(switchConfig.getValue()));
|
||||||
|
}
|
||||||
|
|
||||||
|
SysConfig levelConfig = DBHelper.configOneByKey(Keys.SETUP_LOG_LEVEL);
|
||||||
|
if (null == levelConfig) {
|
||||||
|
dealConfig(Keys.SETUP_LOG_LEVEL, XLog.SET_ROOT_LEVEL_NAME);
|
||||||
|
} else {
|
||||||
|
String[] logLevel = getResources().getStringArray(R.array.logLevel);
|
||||||
|
for (int i = 0; i < logLevel.length; i++) {
|
||||||
|
String level = logLevel[i];
|
||||||
|
if (level.equals(levelConfig.getValue())) {
|
||||||
|
binding.setupLogLevelSpinner.setSelection(i);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SysConfig keepDayConfig = DBHelper.configOneByKey(Keys.SETUP_LOG_KEEP_DAY);
|
||||||
|
if (null == keepDayConfig) {
|
||||||
|
dealConfig(Keys.SETUP_LOG_KEEP_DAY, XLog.LOG_KEEP_DAY.toString());
|
||||||
|
} else {
|
||||||
|
binding.setupLogKeepDayDisplay.setText(keepDayConfig.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addListener() {
|
private void addListener() {
|
||||||
@ -95,15 +124,17 @@ public class NavSetUpFragment extends BaseFragment {
|
|||||||
|
|
||||||
|
|
||||||
private void setupKeepDayClickListener(View view) {
|
private void setupKeepDayClickListener(View view) {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void dealConfig(String key, String level) {
|
private void dealConfig(String key, String value) {
|
||||||
List<SysConfig> list = DBHelper.configListByKey(key);
|
List<SysConfig> list = DBHelper.configListByKey(key);
|
||||||
if (CollUtil.isNotEmpty(list)) {
|
if (CollUtil.isNotEmpty(list)) {
|
||||||
configUpdate(level, list.get(0));
|
configUpdate(value, list.get(0));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
configInsert(key, level);
|
configInsert(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void configInsert(String key, String value) {
|
private void configInsert(String key, String value) {
|
||||||
|
@ -110,6 +110,7 @@
|
|||||||
<Spinner
|
<Spinner
|
||||||
android:id="@+id/setup_log_level_spinner"
|
android:id="@+id/setup_log_level_spinner"
|
||||||
style="@style/SetupExt"
|
style="@style/SetupExt"
|
||||||
|
android:padding="0dp"
|
||||||
android:entries="@array/logLevel"
|
android:entries="@array/logLevel"
|
||||||
|
|
||||||
/>
|
/>
|
||||||
@ -133,6 +134,7 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/setup_log_keep_day_display"
|
android:id="@+id/setup_log_keep_day_display"
|
||||||
style="@style/SetupExt"
|
style="@style/SetupExt"
|
||||||
|
android:text="7"
|
||||||
/>
|
/>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@
|
|||||||
</style>
|
</style>
|
||||||
|
|
||||||
<style name="SetupExt">
|
<style name="SetupExt">
|
||||||
<item name="android:layout_width">64dp</item>
|
<item name="android:layout_width">128dp</item>
|
||||||
<item name="android:layout_height">match_parent</item>
|
<item name="android:layout_height">match_parent</item>
|
||||||
<item name="android:layout_weight">1</item>
|
<item name="android:layout_weight">1</item>
|
||||||
<item name="android:textSize">12dp</item>
|
<item name="android:textSize">12dp</item>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user