pull/1415/head
gedoor 3 years ago
parent b80afb57ce
commit 158cc72eac
  1. 5
      app/src/main/java/io/legado/app/constant/AppLog.kt
  2. 14
      app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt
  3. 12
      app/src/main/res/menu/app_log.xml

@ -15,4 +15,9 @@ object AppLog {
mLogs.add(0, Triple(System.currentTimeMillis(), message, throwable))
}
@Synchronized
fun clear() {
mLogs.clear()
}
}

@ -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<Triple<Long, String, Throwable?>, ItemAppLogBinding>(context) {

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<menu 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"
tools:ignore="AlwaysShowAction">
<item
android:id="@+id/menu_clear"
android:title="@string/clear"
app:showAsAction="always" />
</menu>
Loading…
Cancel
Save