Merge remote-tracking branch 'origin/master'

pull/1259/head
gedoor 3 years ago
commit afb55e45fd
  1. 41
      app/src/main/java/io/legado/app/model/Debug.kt
  2. 28
      app/src/main/java/io/legado/app/service/CheckSourceService.kt
  3. 2
      app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt
  4. 40
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt
  5. 16
      app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt
  6. 2
      app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt
  7. 4
      app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt
  8. 2
      app/src/main/res/values-es-rES/strings.xml
  9. 2
      app/src/main/res/values-ja-rJP/strings.xml
  10. 2
      app/src/main/res/values-pt-rBR/strings.xml
  11. 2
      app/src/main/res/values-zh-rHK/strings.xml
  12. 2
      app/src/main/res/values-zh-rTW/strings.xml
  13. 2
      app/src/main/res/values-zh/strings.xml
  14. 2
      app/src/main/res/values/strings.xml

@ -2,6 +2,7 @@ package io.legado.app.model
import android.annotation.SuppressLint
import io.legado.app.data.entities.*
import io.legado.app.help.AppConfig
import io.legado.app.help.coroutine.CompositeCoroutine
import io.legado.app.model.rss.Rss
import io.legado.app.model.webBook.WebBook
@ -11,14 +12,15 @@ import io.legado.app.utils.msg
import kotlinx.coroutines.CoroutineScope
import java.text.SimpleDateFormat
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import kotlin.collections.HashMap
object Debug {
var callback: Callback? = null
private var debugSource: String? = null
private val tasks: CompositeCoroutine = CompositeCoroutine()
val debugMessageMap = ConcurrentHashMap<String, String>()
private var isChecking: Boolean = false
val debugMessageMap = HashMap<String, String>()
private val debugTimeMap = HashMap<String, Long>()
var isChecking: Boolean = false
@SuppressLint("ConstantLocale")
private val DEBUG_TIME_FORMAT = SimpleDateFormat("[mm:ss.SSS]", Locale.getDefault())
@ -33,8 +35,20 @@ object Debug {
showTime: Boolean = true,
state: Int = 1
) {
if (AppConfig.checkSourceMessage && isChecking) {
if (sourceUrl != null && (msg ?: "").length < 30) {
var printMsg = msg ?: ""
if (isHtml) {
printMsg = HtmlFormatter.format(msg)
}
if (showTime && debugTimeMap[sourceUrl] != null) {
val time = DEBUG_TIME_FORMAT.format(Date(System.currentTimeMillis() - debugTimeMap[sourceUrl]!!))
printMsg = "$time $printMsg"
debugMessageMap[sourceUrl] = printMsg
}
} else {
callback?.let {
if ((debugSource != sourceUrl || !print) && !isChecking) return
if ((debugSource != sourceUrl || !print)) return
var printMsg = msg ?: ""
if (isHtml) {
printMsg = HtmlFormatter.format(msg)
@ -44,9 +58,7 @@ object Debug {
printMsg = "$time $printMsg"
}
it.printLog(state, printMsg)
if (sourceUrl != null && printMsg.length < 30) {
debugMessageMap[sourceUrl] = printMsg
callback?.postCheckMessageEvent(sourceUrl)
}
}
}
}
@ -66,16 +78,23 @@ object Debug {
}
fun startChecking(source: BookSource) {
startTime = System.currentTimeMillis()
isChecking = true
debugMessageMap[source.bookSourceUrl] = "开始校验"
debugTimeMap[source.bookSourceUrl] = System.currentTimeMillis()
debugMessageMap[source.bookSourceUrl] = "${DEBUG_TIME_FORMAT.format(Date(0))} 开始校验"
}
fun finishChecking() {
callback = null
isChecking = false
}
fun updateFinalMessage(sourceUrl: String, state: String) {
if (debugTimeMap[sourceUrl] != null && debugMessageMap[sourceUrl] != null) {
val time = DEBUG_TIME_FORMAT.format(Date(System.currentTimeMillis() - debugTimeMap[sourceUrl]!!))
val originalMessage = debugMessageMap[sourceUrl]!!.substringAfter("] ")
debugMessageMap[sourceUrl] = "$time $originalMessage $state"
}
}
fun startDebug(scope: CoroutineScope, rssSource: RssSource) {
cancelDebug()
debugSource = rssSource.sourceUrl
@ -261,7 +280,5 @@ object Debug {
interface Callback {
fun printLog(state: Int, msg: String)
fun postCheckMessageEvent(sourceUrl: String)
}
}

@ -30,7 +30,7 @@ class CheckSourceService : BaseService() {
private val checkedIds = ArrayList<String>()
private var processIndex = 0
private var notificationMsg = ""
private var debugCallback : Debug.Callback? = null
private val showCheckSourceMessage = AppConfig.checkSourceMessage
private val notificationBuilder by lazy {
NotificationCompat.Builder(this, AppConst.channelIdReadAloud)
.setSmallIcon(R.drawable.ic_network_check)
@ -50,18 +50,6 @@ class CheckSourceService : BaseService() {
override fun onCreate() {
super.onCreate()
notificationMsg = getString(R.string.start)
if (AppConfig.checkSourceMessage) {
debugCallback = object : Debug.Callback {
override fun printLog(state: Int, msg: String) {}
@Synchronized
override fun postCheckMessageEvent(sourceUrl: String) {
postEvent(EventBus.CHECK_SOURCE_MESSAGE, sourceUrl)
}
}
Debug.callback = debugCallback
threadCount = 1
}
upNotification()
}
@ -77,6 +65,7 @@ class CheckSourceService : BaseService() {
override fun onDestroy() {
super.onDestroy()
Debug.finishChecking()
tasks.clear()
searchCoroutine.close()
postEvent(EventBus.CHECK_SOURCE_DONE, 0)
@ -120,7 +109,7 @@ class CheckSourceService : BaseService() {
fun check(source: BookSource) {
execute(context = searchCoroutine) {
if (AppConfig.checkSourceMessage) {
if (showCheckSourceMessage) {
Debug.startChecking(source)
}
val webBook = WebBook(source)
@ -152,9 +141,8 @@ class CheckSourceService : BaseService() {
"error:${it.localizedMessage}
${source.bookSourceComment}"
""".trimIndent()
debugCallback?.let {
Debug.debugMessageMap[source.bookSourceUrl] = Debug.debugMessageMap[source.bookSourceUrl] + " 失败"
postEvent(EventBus.CHECK_SOURCE_MESSAGE, source.bookSourceUrl)
if (showCheckSourceMessage) {
Debug.updateFinalMessage(source.bookSourceUrl, "失败")
}
appDb.bookSourceDao.update(source)
}.onSuccess(searchCoroutine) {
@ -164,11 +152,9 @@ class CheckSourceService : BaseService() {
?.filterNot {
it.startsWith("error:")
}?.joinToString("\n")
debugCallback?.let { debugCallback
Debug.debugMessageMap[source.bookSourceUrl] = Debug.debugMessageMap[source.bookSourceUrl] + " 成功"
postEvent(EventBus.CHECK_SOURCE_MESSAGE, source.bookSourceUrl)
if (showCheckSourceMessage) {
Debug.updateFinalMessage(source.bookSourceUrl, "成功")
}
appDb.bookSourceDao.update(source)
}.onFinally(searchCoroutine) {
onNext(source.bookSourceUrl, source.bookSourceName)

@ -51,8 +51,6 @@ class BookSourceDebugModel(application: Application) : BaseViewModel(application
}
}
override fun postCheckMessageEvent(sourceUrl: String) {}
override fun onCleared() {
super.onCleared()
Debug.cancelDebug(true)

@ -21,6 +21,7 @@ import io.legado.app.data.appDb
import io.legado.app.data.entities.BookSource
import io.legado.app.databinding.ActivityBookSourceBinding
import io.legado.app.databinding.DialogEditTextBinding
import io.legado.app.help.AppConfig
import io.legado.app.help.LocalConfig
import io.legado.app.lib.dialogs.alert
import io.legado.app.lib.theme.ATH
@ -40,10 +41,10 @@ import io.legado.app.ui.widget.recycler.ItemTouchCallback
import io.legado.app.ui.widget.recycler.VerticalDivider
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Job
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import java.io.File
import kotlin.math.min
class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceViewModel>(),
PopupMenu.OnMenuItemClickListener,
@ -340,6 +341,9 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
}
}
CheckSource.start(this@BookSourceActivity, adapter.selection)
if(AppConfig.checkSourceMessage) {
checkMessageRefreshJob().start()
}
}
noButton()
}.show()
@ -432,11 +436,14 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
.make(binding.root, msg, Snackbar.LENGTH_INDEFINITE)
.setAction(R.string.cancel) {
CheckSource.stop(this)
if (AppConfig.checkSourceMessage) {
Debug.finishChecking()
adapter.notifyItemRangeChanged(0, adapter.itemCount, bundleOf(Pair("checkSourceMessage", null)))
}
}.apply { show() }
}
}
observeEvent<Int>(EventBus.CHECK_SOURCE_DONE) {
Debug.finishChecking()
snackBar?.dismiss()
snackBar = null
groups.map { group ->
@ -446,13 +453,26 @@ class BookSourceActivity : VMBaseActivity<ActivityBookSourceBinding, BookSourceV
}
}
}
observeEvent<String>(EventBus.CHECK_SOURCE_MESSAGE) { bookSourceUrl ->
sourceFlowJob?.cancel()
sourceFlowJob = launch {
appDb.bookSourceDao.flowSearch(bookSourceUrl)
.map { adapter.getItems().indexOf(it[0]) }
.collect {
adapter.notifyItemChanged(it, bundleOf(Pair(EventBus.CHECK_SOURCE_MESSAGE, null))) }
}
private fun checkMessageRefreshJob(): Job {
val firstIndex = adapter.getItems().indexOf(adapter.selection.first())
val lastIndex = adapter.getItems().indexOf(adapter.selection.last())
var refreshCount = 0
Debug.isChecking = true
return async(start = CoroutineStart.LAZY) {
flow {
while (true) {
refreshCount += 1
emit(refreshCount)
delay(300L)
}
}.collect {
adapter.notifyItemRangeChanged(firstIndex, lastIndex + 1, bundleOf(Pair("checkSourceMessage", null)))
if (!Debug.isChecking || (refreshCount > (600 * (lastIndex + 1 - firstIndex) / min(AppConfig.threadCount,8)))) {
Debug.finishChecking()
this.cancel()
}
}
}
}

@ -13,7 +13,6 @@ import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.RecyclerAdapter
import io.legado.app.constant.EventBus
import io.legado.app.data.entities.BookSource
import io.legado.app.databinding.ItemBookSourceBinding
import io.legado.app.lib.theme.backgroundColor
@ -116,10 +115,19 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) :
payload.keySet().map {
when (it) {
"selected" -> cbBookSource.isChecked = selected.contains(item)
EventBus.CHECK_SOURCE_MESSAGE -> {
"checkSourceMessage" -> {
ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: ""
ivDebugText.visibility = if(ivDebugText.text.toString().length > 1) View.VISIBLE else View.GONE
ivProgressBar.visibility = if(ivDebugText.text.toString().contains(Regex("成功|失败"))) View.GONE else View.VISIBLE
val isEmpty = ivDebugText.text.toString().isEmpty()
var isFinalMessage = ivDebugText.text.toString().contains(Regex("成功|失败"))
if (!isEmpty && !Debug.isChecking && !isFinalMessage){
Debug.updateFinalMessage(item.bookSourceUrl, "失败")
ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: ""
isFinalMessage = true
}
ivDebugText.visibility =
if (!isEmpty) View.VISIBLE else View.GONE
ivProgressBar.visibility =
if (isFinalMessage || isEmpty) View.GONE else View.VISIBLE
}
}
}

@ -44,8 +44,6 @@ class RssSourceDebugModel(application: Application) : BaseViewModel(application)
}
}
override fun postCheckMessageEvent(sourceUrl: String) {}
override fun onCleared() {
super.onCleared()
Debug.cancelDebug(true)

@ -95,8 +95,4 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) :
}
}
override fun postCheckMessageEvent(sourceUrl: String) {
TODO("Not yet implemented")
}
}

@ -854,5 +854,5 @@
<string name="pref_media_button_per_next_summary">上一段|下一段/上一章|下一章</string>
<string name="read_aloud_by_page_summary">及时翻页,翻页时会停顿一下</string>
<string name="check_source_show_debug_message">La fuente del libro de cheques muestra un mensaje de depuración</string>
<string name="check_source_show_debug_message_summary">Muestra los pasos y el tiempo de la solicitud de red durante la verificación de la fuente del libro; actualmente solo admite la verificación de un solo hilo</string>
<string name="check_source_show_debug_message_summary">Muestra los pasos y el tiempo de la solicitud de red durante la verificación de la fuente del libro</string>
</resources>

@ -855,5 +855,5 @@
<string name="pref_media_button_per_next_summary">上一段|下一段/上一章|下一章</string>
<string name="read_aloud_by_page_summary">及时翻页,翻页时会停顿一下</string>
<string name="check_source_show_debug_message">Check book source shows debug message</string>
<string name="check_source_show_debug_message_summary">Show network status and timestamp during source checking, currently only supports single-thread</string>
<string name="check_source_show_debug_message_summary">Show network status and timestamp during source checking</string>
</resources>

@ -854,5 +854,5 @@
<string name="pref_media_button_per_next_summary">上一段|下一段/上一章|下一章</string>
<string name="read_aloud_by_page_summary">及时翻页,翻页时会停顿一下</string>
<string name="check_source_show_debug_message">Verificar a fonte do livro mostra uma mensagem de depuração</string>
<string name="check_source_show_debug_message_summary">Exibir etapas de solicitação de rede e tempo durante a verificação da fonte do livro; atualmente, oferece suporte apenas à verificação de thread único</string>
<string name="check_source_show_debug_message_summary">Exibir etapas de solicitação de rede e tempo durante a verificação da fonte do livro</string>
</resources>

@ -856,6 +856,6 @@
<string name="pref_media_button_per_next_summary">上一段|下一段/上一章|下一章</string>
<string name="read_aloud_by_page_summary">及时翻页,翻页时会停顿一下</string>
<string name="check_source_show_debug_message">校驗書源顯示詳細信息</string>
<string name="check_source_show_debug_message_summary">書源校驗時顯示網絡請求步驟和時間,當前只支持單線程校驗</string>
<string name="check_source_show_debug_message_summary">書源校驗時顯示網絡請求步驟和時間</string>
</resources>

@ -857,6 +857,6 @@
<string name="pref_media_button_per_next_summary">上一段|下一段/上一章|下一章</string>
<string name="read_aloud_by_page_summary">及时翻页,翻页时会停顿一下</string>
<string name="check_source_show_debug_message">校驗書源顯示詳細信息</string>
<string name="check_source_show_debug_message_summary">書源校驗時顯示網絡請求步驟和時間,當前只支持單線程校驗</string>
<string name="check_source_show_debug_message_summary">書源校驗時顯示網絡請求步驟和時間</string>
</resources>

@ -858,6 +858,6 @@
<string name="pref_media_button_per_next_summary">上一段|下一段/上一章|下一章</string>
<string name="read_aloud_by_page_summary">及时翻页,翻页时会停顿一下</string>
<string name="check_source_show_debug_message">校验显示详细信息</string>
<string name="check_source_show_debug_message_summary">书源校验时显示网络请求步骤和时间,当前只支持单线程校验</string>
<string name="check_source_show_debug_message_summary">书源校验时显示网络请求步骤和时间</string>
</resources>

@ -859,6 +859,6 @@
<string name="pref_media_button_per_next_summary">上一段|下一段/上一章|下一章</string>
<string name="read_aloud_by_page_summary">及时翻页,翻页时会停顿一下</string>
<string name="check_source_show_debug_message">Check book source shows debug message</string>
<string name="check_source_show_debug_message_summary">Show network status and timestamp during source checking, currently only supports single-thread</string>
<string name="check_source_show_debug_message_summary">Show network status and timestamp during source checking</string>
</resources>

Loading…
Cancel
Save