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;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
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.entity.Device;
|
||||
import cc.niushuai.project.devcontrol.vo.DeviceInfo;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.text.StrPool;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
@ -52,4 +54,15 @@ public class Global {
|
||||
public static DeviceInfo getDeviceInfo(String 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) {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当前日志文件的绝对路径
|
||||
*
|
||||
* @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 {
|
||||
|
||||
/**
|
||||
|
@ -6,10 +6,14 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
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 cn.hutool.core.io.FileUtil;
|
||||
|
||||
|
||||
public class NavLogFragment extends Fragment {
|
||||
@ -22,12 +26,12 @@ public class NavLogFragment extends Fragment {
|
||||
|
||||
navFragmentLogBinding = MainNavFragmentLogBinding.inflate(inflater, container, false);
|
||||
|
||||
NavLogViewModel navLogViewModel = new ViewModelProvider(this).get(NavLogViewModel.class);
|
||||
View rootView = navFragmentLogBinding.getRoot();
|
||||
|
||||
TextView textView = navFragmentLogBinding.navLogFragmentTextview;
|
||||
textView.setText(FileUtil.readUtf8String(Global.logAbsolutePath()));
|
||||
|
||||
navLogViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
|
||||
rootView.requestLayout();
|
||||
|
||||
return rootView;
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ public class NavLogViewModel extends ViewModel {
|
||||
|
||||
public NavLogViewModel() {
|
||||
this.vText = new MutableLiveData<>();
|
||||
this.vText.setValue("this is log view");
|
||||
}
|
||||
|
||||
public MutableLiveData<String> getText() {
|
||||
|
@ -1,20 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
tools:context=".ui.nav.log.NavLogFragment">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clipToPadding="false"
|
||||
android:fillViewport="true">
|
||||
|
||||
<HorizontalScrollView
|
||||
android:layout_width="match_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:textAlignment="center"
|
||||
android:text="@string/hello_blank_fragment"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"/>
|
||||
android:scrollHorizontally="true"
|
||||
android:text="@string/hello_blank_fragment" />
|
||||
|
||||
</HorizontalScrollView>
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
x
Reference in New Issue
Block a user