From 158cc72eacadbf97e38eefdc177596c18e6e016f Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 22 Oct 2021 12:24:41 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/constant/AppLog.kt | 5 +++++ .../java/io/legado/app/ui/about/AppLogDialog.kt | 14 +++++++++++++- app/src/main/res/menu/app_log.xml | 12 ++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/menu/app_log.xml diff --git a/app/src/main/java/io/legado/app/constant/AppLog.kt b/app/src/main/java/io/legado/app/constant/AppLog.kt index c5c887274..396f0108f 100644 --- a/app/src/main/java/io/legado/app/constant/AppLog.kt +++ b/app/src/main/java/io/legado/app/constant/AppLog.kt @@ -15,4 +15,9 @@ object AppLog { mLogs.add(0, Triple(System.currentTimeMillis(), message, throwable)) } + @Synchronized + fun clear() { + mLogs.clear() + } + } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt b/app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt index f60fab297..258d9cc9a 100644 --- a/app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt +++ b/app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt @@ -2,8 +2,10 @@ package io.legado.app.ui.about import android.content.Context import android.os.Bundle +import android.view.MenuItem import android.view.View import android.view.ViewGroup +import androidx.appcompat.widget.Toolbar import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.BaseDialogFragment @@ -21,7 +23,8 @@ import io.legado.app.utils.viewbindingdelegate.viewBinding import splitties.views.onClick import java.util.* -class AppLogDialog : BaseDialogFragment(R.layout.dialog_recycler_view) { +class AppLogDialog : BaseDialogFragment(R.layout.dialog_recycler_view), + Toolbar.OnMenuItemClickListener { private val binding by viewBinding(DialogRecyclerViewBinding::bind) private val adapter by lazy { @@ -37,12 +40,21 @@ class AppLogDialog : BaseDialogFragment(R.layout.dialog_recycler_view) { binding.run { toolBar.setBackgroundColor(primaryColor) toolBar.setTitle(R.string.log) + toolBar.inflateMenu(R.menu.app_log) + toolBar.setOnMenuItemClickListener(this@AppLogDialog) recyclerView.layoutManager = LinearLayoutManager(requireContext()) recyclerView.adapter = adapter } adapter.setItems(AppLog.logs) } + override fun onMenuItemClick(item: MenuItem?): Boolean { + when (item?.itemId) { + R.id.menu_clear -> AppLog.clear() + } + return true + } + inner class LogAdapter(context: Context) : RecyclerAdapter, ItemAppLogBinding>(context) { diff --git a/app/src/main/res/menu/app_log.xml b/app/src/main/res/menu/app_log.xml new file mode 100644 index 000000000..3d17348bb --- /dev/null +++ b/app/src/main/res/menu/app_log.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file