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