mirror of
https://github.com/niushuai233/DevControl.git
synced 2024-10-27 22:43:20 +08:00
feat: 日志页面完成
This commit is contained in:
parent
a3c0c5bd8c
commit
d695239b6d
@ -1,5 +1,6 @@
|
|||||||
package cc.niushuai.project.devcontrol.base.util;
|
package cc.niushuai.project.devcontrol.base.util;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -9,6 +10,7 @@ import cc.niushuai.project.devcontrol.base.ui.BaseActivity;
|
|||||||
import cc.niushuai.project.devcontrol.db.DB;
|
import cc.niushuai.project.devcontrol.db.DB;
|
||||||
import cc.niushuai.project.devcontrol.db.entity.Device;
|
import cc.niushuai.project.devcontrol.db.entity.Device;
|
||||||
import cc.niushuai.project.devcontrol.vo.DeviceInfo;
|
import cc.niushuai.project.devcontrol.vo.DeviceInfo;
|
||||||
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.text.StrPool;
|
import cn.hutool.core.text.StrPool;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
@ -52,4 +54,15 @@ public class Global {
|
|||||||
public static DeviceInfo getDeviceInfo(String deviceId) {
|
public static DeviceInfo getDeviceInfo(String deviceId) {
|
||||||
return DEVICE_INFO_MAP.get(deviceId);
|
return DEVICE_INFO_MAP.get(deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前日志文件的绝对路径
|
||||||
|
*
|
||||||
|
* @author niushuai
|
||||||
|
* @date: 2022/10/26 15:33
|
||||||
|
* @return: {@link String}
|
||||||
|
*/
|
||||||
|
public static String logAbsolutePath() {
|
||||||
|
return Global.LOG_ROOT_PATH + DateUtil.formatDate(new Date()) + Keys.LOG_SUFFIX;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ public class XLog {
|
|||||||
|
|
||||||
if (LOG_SWITCH_TO_FILE) {
|
if (LOG_SWITCH_TO_FILE) {
|
||||||
String logContent = concatFinalLog(tag, level, message);
|
String logContent = concatFinalLog(tag, level, message);
|
||||||
FileUtil.appendUtf8String(logContent + System.lineSeparator(), currentAbsoluteLogPath());
|
FileUtil.appendUtf8String(logContent + System.lineSeparator(), Global.logAbsolutePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,17 +204,6 @@ public class XLog {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 当前日志文件的绝对路径
|
|
||||||
*
|
|
||||||
* @author niushuai
|
|
||||||
* @date: 2022/10/26 15:33
|
|
||||||
* @return: {@link String}
|
|
||||||
*/
|
|
||||||
private static String currentAbsoluteLogPath() {
|
|
||||||
return Global.LOG_ROOT_PATH + DateUtil.formatDate(new Date()) + Keys.LOG_SUFFIX;
|
|
||||||
}
|
|
||||||
|
|
||||||
static class Level {
|
static class Level {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,10 +6,14 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
||||||
|
import cc.niushuai.project.devcontrol.R;
|
||||||
|
import cc.niushuai.project.devcontrol.base.util.Global;
|
||||||
import cc.niushuai.project.devcontrol.databinding.MainNavFragmentLogBinding;
|
import cc.niushuai.project.devcontrol.databinding.MainNavFragmentLogBinding;
|
||||||
|
import cn.hutool.core.io.FileUtil;
|
||||||
|
|
||||||
|
|
||||||
public class NavLogFragment extends Fragment {
|
public class NavLogFragment extends Fragment {
|
||||||
@ -22,12 +26,12 @@ public class NavLogFragment extends Fragment {
|
|||||||
|
|
||||||
navFragmentLogBinding = MainNavFragmentLogBinding.inflate(inflater, container, false);
|
navFragmentLogBinding = MainNavFragmentLogBinding.inflate(inflater, container, false);
|
||||||
|
|
||||||
NavLogViewModel navLogViewModel = new ViewModelProvider(this).get(NavLogViewModel.class);
|
|
||||||
View rootView = navFragmentLogBinding.getRoot();
|
View rootView = navFragmentLogBinding.getRoot();
|
||||||
|
|
||||||
TextView textView = navFragmentLogBinding.navLogFragmentTextview;
|
TextView textView = navFragmentLogBinding.navLogFragmentTextview;
|
||||||
|
textView.setText(FileUtil.readUtf8String(Global.logAbsolutePath()));
|
||||||
|
|
||||||
navLogViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
|
rootView.requestLayout();
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ public class NavLogViewModel extends ViewModel {
|
|||||||
|
|
||||||
public NavLogViewModel() {
|
public NavLogViewModel() {
|
||||||
this.vText = new MutableLiveData<>();
|
this.vText = new MutableLiveData<>();
|
||||||
this.vText.setValue("this is log view");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutableLiveData<String> getText() {
|
public MutableLiveData<String> getText() {
|
||||||
|
@ -1,20 +1,29 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
|
||||||
tools:context=".ui.nav.log.NavLogFragment">
|
tools:context=".ui.nav.log.NavLogFragment">
|
||||||
|
|
||||||
<TextView
|
<androidx.core.widget.NestedScrollView
|
||||||
android:id="@+id/nav_log_fragment_textview"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:textAlignment="center"
|
android:clipToPadding="false"
|
||||||
android:text="@string/hello_blank_fragment"
|
android:fillViewport="true">
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
<HorizontalScrollView
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
android:layout_width="match_parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"/>
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/nav_log_fragment_textview"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:scrollHorizontally="true"
|
||||||
|
android:text="@string/hello_blank_fragment" />
|
||||||
|
|
||||||
|
</HorizontalScrollView>
|
||||||
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user