pull/1319/head
gedoor 3 years ago
parent ec970564cd
commit c4bc2ef199
  1. 49
      app/src/main/java/io/legado/app/ui/about/AppLogDialog.kt
  2. 2
      app/src/main/java/io/legado/app/utils/LogUtils.kt
  3. 18
      app/src/main/res/layout/item_app_log.xml

@ -1,13 +1,25 @@
package io.legado.app.ui.about
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.R
import io.legado.app.base.BaseDialogFragment
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.constant.AppLog
import io.legado.app.databinding.DialogRecyclerViewBinding
import io.legado.app.databinding.ItemAppLogBinding
import io.legado.app.lib.theme.primaryColor
import io.legado.app.utils.LogUtils
import io.legado.app.utils.viewbindingdelegate.viewBinding
import io.legado.app.utils.windowSize
import splitties.views.onClick
import java.util.*
class AppLogDialog : BaseDialogFragment() {
@ -17,6 +29,11 @@ class AppLogDialog : BaseDialogFragment() {
}
}
private val binding by viewBinding(DialogRecyclerViewBinding::bind)
private val adapter by lazy {
LogAdapter(requireContext())
}
override fun onStart() {
super.onStart()
val dm = requireActivity().windowSize
@ -31,10 +48,40 @@ class AppLogDialog : BaseDialogFragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return inflater.inflate(R.layout.dialog_book_group_edit, container)
return inflater.inflate(R.layout.dialog_recycler_view, container)
}
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) {
binding.run {
toolBar.setBackgroundColor(primaryColor)
recyclerView.layoutManager = LinearLayoutManager(requireContext())
recyclerView.adapter = adapter
}
adapter.setItems(AppLog.logs)
}
inner class LogAdapter(context: Context) :
RecyclerAdapter<Triple<Long, String, Throwable?>, ItemAppLogBinding>(context) {
override fun getViewBinding(parent: ViewGroup): ItemAppLogBinding {
return ItemAppLogBinding.inflate(inflater, parent, false)
}
override fun convert(
holder: ItemViewHolder,
binding: ItemAppLogBinding,
item: Triple<Long, String, Throwable?>,
payloads: MutableList<Any>
) {
binding.textTime.text = LogUtils.logTimeFormat.format(Date(item.first))
binding.textMessage.text = item.second
}
override fun registerListener(holder: ItemViewHolder, binding: ItemAppLogBinding) {
binding.root.onClick {
}
}
}

@ -9,9 +9,11 @@ import java.text.SimpleDateFormat
import java.util.*
import java.util.logging.*
@SuppressLint("SimpleDateFormat")
@Suppress("unused")
object LogUtils {
const val TIME_PATTERN = "yy-MM-dd HH:mm:ss.SSS"
val logTimeFormat by lazy { SimpleDateFormat(TIME_PATTERN) }
@JvmStatic
fun d(tag: String, msg: String) {

@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/text_time"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/text_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:autoLink="web" />
</LinearLayout>
Loading…
Cancel
Save