feat: 添加下载错误日志,从下载菜单浏览

pull/274/head
gedoor 4 years ago
parent 362de2d493
commit 57dd30ee69
  1. 7
      app/src/main/java/io/legado/app/service/DownloadService.kt
  2. 11
      app/src/main/java/io/legado/app/service/help/Download.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/download/DownloadActivity.kt
  4. 84
      app/src/main/java/io/legado/app/ui/widget/dialog/TextListDialog.kt
  5. 12
      app/src/main/res/menu/download.xml
  6. 1
      app/src/main/res/values-zh-rHK/strings.xml
  7. 1
      app/src/main/res/values-zh-rTW/strings.xml
  8. 1
      app/src/main/res/values/strings.xml

@ -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) {

@ -7,6 +7,17 @@ import io.legado.app.service.DownloadService
object Download {
val logs = arrayListOf<String>()
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

@ -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<DownloadViewModel>(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

@ -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<String>) {
TextListDialog().apply {
val bundle = Bundle()
bundle.putStringArrayList("values", values)
arguments = bundle
}.show(fragmentManager, "textListDialog")
}
}
lateinit var adapter: TextAdapter
var values: ArrayList<String>? = 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<String>(context, R.layout.item_log) {
override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList<Any>) {
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
}
}
}

@ -1,12 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
<menu xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_download"
android:title="@string/action_download"
android:icon="@drawable/ic_play_24dp"
app:showAsAction="ifRoom" />
app:showAsAction="always"
tools:ignore="AlwaysShowAction" />
<item
android:id="@+id/menu_book_group"
@ -24,9 +26,13 @@
android:id="@+id/menu_all"
android:title="@string/all" />
</menu>
</item>
<item
android:id="@+id/menu_log"
android:title="@string/log"
app:showAsAction="never" />
</menu>

@ -618,6 +618,7 @@
<string name="add_to_text_context_menu_s">長按文字在操作菜單中顯示閲讀·搜索</string>
<string name="add_to_text_context_menu_t">文字操作顯示搜索</string>
<string name="record_log">記錄日誌</string>
<string name="log">日誌</string>
<string name="chinese_converter">中文簡繁體轉換</string>
<string name="chage_icon_error">圖標為矢量圖標,Android8.0 以前不支持</string>
<string name="aloud_config">朗讀設置</string>

@ -619,6 +619,7 @@
<string name="add_to_text_context_menu_s">長按文字在操作選單中顯示閱讀·搜尋</string>
<string name="add_to_text_context_menu_t">文字操作顯示搜尋</string>
<string name="record_log">記錄日誌</string>
<string name="log">日誌</string>
<string name="chinese_converter">中文簡繁體轉換</string>
<string name="chage_icon_error">圖示為向量圖示,Android8.0以前不支援</string>
<string name="aloud_config">朗讀設定</string>

@ -620,6 +620,7 @@
<string name="add_to_text_context_menu_s">长按文字在操作菜单中显示阅读·搜索</string>
<string name="add_to_text_context_menu_t">文字操作显示搜索</string>
<string name="record_log">记录日志</string>
<string name="log">日志</string>
<string name="chinese_converter">中文简繁体转换</string>
<string name="chage_icon_error">图标为矢量图标,Android8.0以前不支持</string>
<string name="aloud_config">朗读设置</string>

Loading…
Cancel
Save