From 57dd30ee692f0e5f47a9699e5da9504edf37713e Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 5 Jul 2020 18:40:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=97=A5=E5=BF=97,=E4=BB=8E=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E8=8F=9C=E5=8D=95=E6=B5=8F=E8=A7=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/service/DownloadService.kt | 7 +- .../io/legado/app/service/help/Download.kt | 11 +++ .../app/ui/book/download/DownloadActivity.kt | 4 + .../app/ui/widget/dialog/TextListDialog.kt | 84 +++++++++++++++++++ app/src/main/res/menu/download.xml | 12 ++- app/src/main/res/values-zh-rHK/strings.xml | 1 + app/src/main/res/values-zh-rTW/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 8 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt diff --git a/app/src/main/java/io/legado/app/service/DownloadService.kt b/app/src/main/java/io/legado/app/service/DownloadService.kt index a7c14b119..13b55ac13 100644 --- a/app/src/main/java/io/legado/app/service/DownloadService.kt +++ b/app/src/main/java/io/legado/app/service/DownloadService.kt @@ -17,6 +17,7 @@ import io.legado.app.help.IntentHelp import io.legado.app.help.coroutine.CompositeCoroutine import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.WebBook +import io.legado.app.service.help.Download import io.legado.app.utils.postEvent import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.asCoroutineDispatcher @@ -182,7 +183,11 @@ class DownloadService : BaseService() { bookChapter, scope = this, context = searchPool - ).onSuccess(IO) { content -> + ).onError { + it.localizedMessage?.let { + Download.addLog(it) + } + }.onSuccess(IO) { content -> downloadCount[book.bookUrl]?.increaseSuccess() BookHelp.saveContent(book, bookChapter, content) }.onFinally(IO) { diff --git a/app/src/main/java/io/legado/app/service/help/Download.kt b/app/src/main/java/io/legado/app/service/help/Download.kt index 9f93dc358..844f127b2 100644 --- a/app/src/main/java/io/legado/app/service/help/Download.kt +++ b/app/src/main/java/io/legado/app/service/help/Download.kt @@ -7,6 +7,17 @@ import io.legado.app.service.DownloadService object Download { + val logs = arrayListOf() + + fun addLog(log: String) { + synchronized(this) { + if (logs.size > 30) { + logs.removeAt(0) + } + logs.add(log) + } + } + fun start(context: Context, bookUrl: String, start: Int, end: Int) { Intent(context, DownloadService::class.java).let { it.action = IntentAction.start diff --git a/app/src/main/java/io/legado/app/ui/book/download/DownloadActivity.kt b/app/src/main/java/io/legado/app/ui/book/download/DownloadActivity.kt index 0097c33ac..8e049a369 100644 --- a/app/src/main/java/io/legado/app/ui/book/download/DownloadActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/download/DownloadActivity.kt @@ -22,6 +22,7 @@ import io.legado.app.help.BookHelp import io.legado.app.service.help.Download import io.legado.app.ui.filechooser.FileChooserDialog import io.legado.app.ui.filechooser.FilePicker +import io.legado.app.ui.widget.dialog.TextListDialog import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_download.* import kotlinx.coroutines.Dispatchers @@ -91,6 +92,9 @@ class DownloadActivity : VMBaseActivity(R.layout.activity_dow Download.stop(this@DownloadActivity) } } + R.id.menu_log -> { + TextListDialog.show(supportFragmentManager, Download.logs) + } R.id.menu_no_group -> { title_bar.subtitle = getString(R.string.no_group) groupId = AppConst.bookGroupNone.groupId diff --git a/app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt b/app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt new file mode 100644 index 000000000..ca8e9d6a4 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt @@ -0,0 +1,84 @@ +package io.legado.app.ui.widget.dialog + +import android.content.Context +import android.os.Bundle +import android.util.DisplayMetrics +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.SimpleRecyclerAdapter +import kotlinx.android.synthetic.main.dialog_recycler_view.* +import kotlinx.android.synthetic.main.item_log.view.* + +class TextListDialog : BaseDialogFragment() { + + companion object { + fun show(fragmentManager: FragmentManager, values: ArrayList) { + TextListDialog().apply { + val bundle = Bundle() + bundle.putStringArrayList("values", values) + arguments = bundle + }.show(fragmentManager, "textListDialog") + } + } + + lateinit var adapter: TextAdapter + var values: ArrayList? = null + + override fun onStart() { + super.onStart() + val dm = DisplayMetrics() + activity?.windowManager?.defaultDisplay?.getMetrics(dm) + dialog?.window?.setLayout((dm.widthPixels * 0.9).toInt(), (dm.heightPixels * 0.9).toInt()) + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.dialog_recycler_view, container) + } + + override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { + tool_bar.title = getString(R.string.log) + arguments?.let { + values = it.getStringArrayList("values") + } + recycler_view.layoutManager = LinearLayoutManager(requireContext()) + adapter = TextAdapter(requireContext()) + recycler_view.adapter = adapter + adapter.setItems(values) + } + + class TextAdapter(context: Context) : + SimpleRecyclerAdapter(context, R.layout.item_log) { + override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList) { + holder.itemView.apply { + if (text_view.getTag(R.id.tag1) == null) { + val listener = object : View.OnAttachStateChangeListener { + override fun onViewAttachedToWindow(v: View) { + text_view.isCursorVisible = false + text_view.isCursorVisible = true + } + + override fun onViewDetachedFromWindow(v: View) {} + } + text_view.addOnAttachStateChangeListener(listener) + text_view.setTag(R.id.tag1, listener) + } + text_view.text = item + } + } + + override fun registerListener(holder: ItemViewHolder) { + //nothing + } + } + +} \ No newline at end of file diff --git a/app/src/main/res/menu/download.xml b/app/src/main/res/menu/download.xml index 6c5b7a8f3..6303b5b9d 100644 --- a/app/src/main/res/menu/download.xml +++ b/app/src/main/res/menu/download.xml @@ -1,12 +1,14 @@ - + app:showAsAction="always" + tools:ignore="AlwaysShowAction" /> - + + \ No newline at end of file diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index e1655852a..55423b736 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -618,6 +618,7 @@ 長按文字在操作菜單中顯示閲讀·搜索 文字操作顯示搜索 記錄日誌 + 日誌 中文簡繁體轉換 圖標為矢量圖標,Android8.0 以前不支持 朗讀設置 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 3b228acc2..35f111f2c 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -619,6 +619,7 @@ 長按文字在操作選單中顯示閱讀·搜尋 文字操作顯示搜尋 記錄日誌 + 日誌 中文簡繁體轉換 圖示為向量圖示,Android8.0以前不支援 朗讀設定 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 909721105..e7c595cd2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -620,6 +620,7 @@ 长按文字在操作菜单中显示阅读·搜索 文字操作显示搜索 记录日志 + 日志 中文简繁体转换 图标为矢量图标,Android8.0以前不支持 朗读设置