diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/Global.java b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/Global.java index 2337f8b..709362b 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/base/util/Global.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/base/util/Global.java @@ -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; + } } 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 51a0df9..f664efe 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 @@ -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 { /** diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/log/NavLogFragment.java b/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/log/NavLogFragment.java index 9d5e044..f583a4a 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/log/NavLogFragment.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/log/NavLogFragment.java @@ -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; } diff --git a/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/log/NavLogViewModel.java b/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/log/NavLogViewModel.java index 122ee8b..15066c3 100644 --- a/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/log/NavLogViewModel.java +++ b/app/src/main/java/cc/niushuai/project/devcontrol/ui/nav/log/NavLogViewModel.java @@ -9,7 +9,6 @@ public class NavLogViewModel extends ViewModel { public NavLogViewModel() { this.vText = new MutableLiveData<>(); - this.vText.setValue("this is log view"); } public MutableLiveData getText() { diff --git a/app/src/main/res/layout/main_nav_fragment_log.xml b/app/src/main/res/layout/main_nav_fragment_log.xml index bc34df2..b28c925 100644 --- a/app/src/main/res/layout/main_nav_fragment_log.xml +++ b/app/src/main/res/layout/main_nav_fragment_log.xml @@ -1,20 +1,29 @@ - + android:clipToPadding="false" + android:fillViewport="true"> - \ No newline at end of file + + + + + + + +