From c4bc2ef199fde26efa1f709a6fb55200cf7ef72d Mon Sep 17 00:00:00 2001 From: gedoor Date: Fri, 10 Sep 2021 10:34:42 +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 --- .../io/legado/app/ui/about/AppLogDialog.kt | 49 ++++++++++++++++++- .../main/java/io/legado/app/utils/LogUtils.kt | 2 + app/src/main/res/layout/item_app_log.xml | 18 +++++++ 3 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/layout/item_app_log.xml 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 301a3de4a..e5b45e01d 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 @@ -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, ItemAppLogBinding>(context) { + + override fun getViewBinding(parent: ViewGroup): ItemAppLogBinding { + return ItemAppLogBinding.inflate(inflater, parent, false) + } + + override fun convert( + holder: ItemViewHolder, + binding: ItemAppLogBinding, + item: Triple, + payloads: MutableList + ) { + binding.textTime.text = LogUtils.logTimeFormat.format(Date(item.first)) + binding.textMessage.text = item.second + } + + override fun registerListener(holder: ItemViewHolder, binding: ItemAppLogBinding) { + binding.root.onClick { + + } + } } diff --git a/app/src/main/java/io/legado/app/utils/LogUtils.kt b/app/src/main/java/io/legado/app/utils/LogUtils.kt index 6aea8719d..f7e804d77 100644 --- a/app/src/main/java/io/legado/app/utils/LogUtils.kt +++ b/app/src/main/java/io/legado/app/utils/LogUtils.kt @@ -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) { diff --git a/app/src/main/res/layout/item_app_log.xml b/app/src/main/res/layout/item_app_log.xml new file mode 100644 index 000000000..dbad7fa2e --- /dev/null +++ b/app/src/main/res/layout/item_app_log.xml @@ -0,0 +1,18 @@ + + + + + + + + \ No newline at end of file