diff --git a/app/src/main/java/io/legado/app/constant/PreferKey.kt b/app/src/main/java/io/legado/app/constant/PreferKey.kt index 4c8759c31..518d053b0 100644 --- a/app/src/main/java/io/legado/app/constant/PreferKey.kt +++ b/app/src/main/java/io/legado/app/constant/PreferKey.kt @@ -100,5 +100,5 @@ object PreferKey { const val cNBBackground = "colorBottomBackgroundNight" const val bgImageN = "backgroundImageNight" const val bgImageNBlurring = "backgroundImageNightBlurring" - + const val checkSourceMessage = "checkSourceMessage" } diff --git a/app/src/main/java/io/legado/app/help/AppConfig.kt b/app/src/main/java/io/legado/app/help/AppConfig.kt index 16ebb95e1..2c4a781a4 100644 --- a/app/src/main/java/io/legado/app/help/AppConfig.kt +++ b/app/src/main/java/io/legado/app/help/AppConfig.kt @@ -246,6 +246,9 @@ object AppConfig : SharedPreferences.OnSharedPreferenceChangeListener { val fullScreenGesturesSupport: Boolean get() = appCtx.getPrefBoolean(PreferKey.fullScreenGesturesSupport, false) + val checkSourceMessage: Boolean + get() = appCtx.getPrefBoolean(PreferKey.checkSourceMessage) + private fun getPrefUserAgent(): String { val ua = appCtx.getPrefString(PreferKey.userAgent) if (ua.isNullOrBlank()) { diff --git a/app/src/main/java/io/legado/app/model/Debug.kt b/app/src/main/java/io/legado/app/model/Debug.kt index 275f38c67..4151185bd 100644 --- a/app/src/main/java/io/legado/app/model/Debug.kt +++ b/app/src/main/java/io/legado/app/model/Debug.kt @@ -4,6 +4,7 @@ import android.annotation.SuppressLint import android.util.Log import io.legado.app.constant.EventBus 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 @@ -20,7 +21,7 @@ object Debug { private var debugSource: String? = null private val tasks: CompositeCoroutine = CompositeCoroutine() val debugMessageMap = ConcurrentHashMap() - var isChecking: Boolean = false + private var isChecking: Boolean = false @SuppressLint("ConstantLocale") private val DEBUG_TIME_FORMAT = SimpleDateFormat("[mm:ss.SSS]", Locale.getDefault()) @@ -48,8 +49,7 @@ object Debug { it.printLog(state, printMsg) if (sourceUrl != null && printMsg.length < 30) { debugMessageMap[sourceUrl] = printMsg - callback?.printCheckSourceMessage(sourceUrl, printMsg) - Log.d(EventBus.CHECK_SOURCE_MESSAGE, "debugMessage after filter $printMsg") + callback?.postCheckMessageEvent(sourceUrl) } } } @@ -264,7 +264,7 @@ object Debug { interface Callback { fun printLog(state: Int, msg: String) - fun printCheckSourceMessage(sourceUrl: String, msg: String) + fun postCheckMessageEvent(sourceUrl: String) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/service/CheckSourceService.kt b/app/src/main/java/io/legado/app/service/CheckSourceService.kt index d9293cfca..c788fae58 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -1,7 +1,6 @@ package io.legado.app.service import android.content.Intent -import android.util.Log import androidx.core.app.NotificationCompat import io.legado.app.R import io.legado.app.base.BaseService @@ -10,6 +9,7 @@ import io.legado.app.constant.EventBus import io.legado.app.constant.IntentAction import io.legado.app.data.appDb import io.legado.app.data.entities.BookSource +import io.legado.app.help.AppConfig import io.legado.app.help.IntentHelp import io.legado.app.help.coroutine.CompositeCoroutine import io.legado.app.model.Debug @@ -23,23 +23,14 @@ import java.util.concurrent.Executors import kotlin.math.min class CheckSourceService : BaseService() { - private var threadCount = 1 + private var threadCount = AppConfig.threadCount private var searchCoroutine = Executors.newFixedThreadPool(min(threadCount,8)).asCoroutineDispatcher() private var tasks = CompositeCoroutine() private val allIds = ArrayList() private val checkedIds = ArrayList() private var processIndex = 0 private var notificationMsg = "" - private val debugCallback = object : Debug.Callback{ - override fun printLog(state: Int, msg: String) { - } - - @Synchronized - override fun printCheckSourceMessage(sourceUrl: String, msg: String) { - postEvent(EventBus.CHECK_SOURCE_MESSAGE, Pair(sourceUrl, null)) - Log.d(EventBus.CHECK_SOURCE_MESSAGE, "printCheckSourceMessage to post $sourceUrl $msg") - } - } + private var debugCallback : Debug.Callback? = null private val notificationBuilder by lazy { NotificationCompat.Builder(this, AppConst.channelIdReadAloud) .setSmallIcon(R.drawable.ic_network_check) @@ -59,7 +50,18 @@ class CheckSourceService : BaseService() { override fun onCreate() { super.onCreate() notificationMsg = getString(R.string.start) - Debug.callback = debugCallback + 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() } @@ -118,7 +120,9 @@ class CheckSourceService : BaseService() { fun check(source: BookSource) { execute(context = searchCoroutine) { - Debug.startChecking(source) + if (AppConfig.checkSourceMessage) { + Debug.startChecking(source) + } val webBook = WebBook(source) var books = webBook.searchBookAwait(this, CheckSource.keyword) if (books.isEmpty()) { @@ -148,8 +152,10 @@ class CheckSourceService : BaseService() { "error:${it.localizedMessage} ${source.bookSourceComment}" """.trimIndent() - val message = Debug.debugMessageMap[source.bookSourceUrl] + " 失败" - postEvent(EventBus.CHECK_SOURCE_MESSAGE, Pair(source.bookSourceUrl, message)) + debugCallback?.let { + Debug.debugMessageMap[source.bookSourceUrl] = Debug.debugMessageMap[source.bookSourceUrl] + " 失败" + postEvent(EventBus.CHECK_SOURCE_MESSAGE, source.bookSourceUrl) + } appDb.bookSourceDao.update(source) }.onSuccess(searchCoroutine) { source.removeGroup("失效") @@ -158,14 +164,11 @@ class CheckSourceService : BaseService() { ?.filterNot { it.startsWith("error:") }?.joinToString("\n") - Debug.debugMessageMap[source.bookSourceUrl]?.let { lastMessage -> - lastMessage.indexOf("]").let { - if (it > 0) { - val timeMessage = lastMessage.substring(0, it) + " 校验成功" - postEvent(EventBus.CHECK_SOURCE_MESSAGE, Pair(source.bookSourceUrl, timeMessage)) - } - } + debugCallback?.let { debugCallback + Debug.debugMessageMap[source.bookSourceUrl] = Debug.debugMessageMap[source.bookSourceUrl] + " 成功" + postEvent(EventBus.CHECK_SOURCE_MESSAGE, source.bookSourceUrl) } + appDb.bookSourceDao.update(source) }.onFinally(searchCoroutine) { onNext(source.bookSourceUrl, source.bookSourceName) diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt index e3a77be67..7d79dfca2 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugModel.kt @@ -51,9 +51,7 @@ class BookSourceDebugModel(application: Application) : BaseViewModel(application } } - override fun printCheckSourceMessage(sourceUrl: String, msg: String) { - TODO("Not yet implemented") - } + override fun postCheckMessageEvent(sourceUrl: String) {} override fun onCleared() { super.onCleared() diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt index 46f76a628..c3f0e7b9e 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceActivity.kt @@ -340,7 +340,6 @@ class BookSourceActivity : VMBaseActivity -// if (group.contains("失效")) { -// searchView.setQuery("失效", true) -// toastOnUi("发现有失效书源,已为您自动筛选!") -// } -// } + groups.map { group -> + if (group.contains("失效")) { + searchView.setQuery("失效", true) + toastOnUi("发现有失效书源,已为您自动筛选!") + } + } } - observeEvent>(EventBus.CHECK_SOURCE_MESSAGE) { messagePair -> + observeEvent(EventBus.CHECK_SOURCE_MESSAGE) { bookSourceUrl -> sourceFlowJob?.cancel() sourceFlowJob = launch { - appDb.bookSourceDao.flowSearch(messagePair.first) + appDb.bookSourceDao.flowSearch(bookSourceUrl) .map { adapter.getItems().indexOf(it[0]) } .collect { - adapter.notifyItemChanged(it, bundleOf(Pair(EventBus.CHECK_SOURCE_MESSAGE, messagePair.second))) } + adapter.notifyItemChanged(it, bundleOf(Pair(EventBus.CHECK_SOURCE_MESSAGE, null))) } } - - } } diff --git a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt index 4ebddca5e..121f0d3b2 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/manage/BookSourceAdapter.kt @@ -116,22 +116,10 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : payload.keySet().map { when (it) { "selected" -> cbBookSource.isChecked = selected.contains(item) - "startChecking" -> { - ivProgressBar.visibility = if(selected.contains(item)) View.VISIBLE else ivProgressBar.visibility - } - "checkSourceDone" -> { - ivProgressBar.visibility = if(selected.contains(item)) View.GONE else ivProgressBar.visibility - } EventBus.CHECK_SOURCE_MESSAGE -> { - val message = payload[it] as? String? - if (message != null) { - ivDebugText.text = message - ivProgressBar.visibility = View.GONE - } - else{ - ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: "" - } + 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 } } } diff --git a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt index a22f9e531..5d0ada568 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/debug/RssSourceDebugModel.kt @@ -44,9 +44,7 @@ class RssSourceDebugModel(application: Application) : BaseViewModel(application) } } - override fun printCheckSourceMessage(sourceUrl: String, msg: String) { - TODO("Not yet implemented") - } + override fun postCheckMessageEvent(sourceUrl: String) {} override fun onCleared() { super.onCleared() diff --git a/app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt b/app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt index 307f0676e..534a68b47 100644 --- a/app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt +++ b/app/src/main/java/io/legado/app/web/SourceDebugWebSocket.kt @@ -95,7 +95,7 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) : } } - override fun printCheckSourceMessage(sourceUrl: String, msg: String) { + override fun postCheckMessageEvent(sourceUrl: String) { TODO("Not yet implemented") } diff --git a/app/src/main/res/layout/item_book_source.xml b/app/src/main/res/layout/item_book_source.xml index 1b2b3f89b..761f8e2d8 100644 --- a/app/src/main/res/layout/item_book_source.xml +++ b/app/src/main/res/layout/item_book_source.xml @@ -17,7 +17,7 @@ app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toLeftOf="@id/swt_enabled" app:layout_constraintTop_toTopOf="parent" - app:layout_constraintBottom_toBottomOf="@id/iv_menu_more" /> + app:layout_constraintBottom_toTopOf="@id/iv_debug_text" /> + app:layout_constraintBottom_toTopOf="@id/iv_debug_text" /> + app:layout_constraintBottom_toTopOf="@id/iv_debug_text" /> + app:layout_constraintTop_toTopOf="@id/iv_debug_text" + app:layout_constraintBottom_toBottomOf="@id/iv_debug_text" /> diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index 49c3fec0a..da1c304ed 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -849,4 +849,6 @@ 未知错误 end 关闭替换分组/开启添加分组 + La fuente del libro de cheques muestra un mensaje de depuración + 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 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index 1ffd710ea..f42c368c8 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -850,4 +850,6 @@ No export chapter names end 关闭替换分组/开启添加分组 + Check book source shows debug message + Show network status and timestamp during source checking, currently only supports single-thread diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index 78aa4c716..7901a2006 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -849,4 +849,6 @@ 未知错误 end 关闭替换分组/开启添加分组 + Verificar a fonte do livro mostra uma mensagem de depuração + 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 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index 70c62f14b..61b756c1a 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -851,5 +851,7 @@ TXT不導出章節名 end 关闭替换分组/开启添加分组 + 校驗書源顯示詳細信息 + 書源校驗時顯示網絡請求步驟和時間,當前只支持單線程校驗 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index bb8b6827a..e91784874 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -852,5 +852,7 @@ TXT不匯出章節名 end 关闭替换分组/开启添加分组 + 校驗書源顯示詳細信息 + 書源校驗時顯示網絡請求步驟和時間,當前只支持單線程校驗 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 78323bbeb..db964e59f 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -853,5 +853,7 @@ 自动备份失败 结束 关闭替换分组/开启添加分组 + 校验显示详细信息 + 书源校验时显示网络请求步骤和时间,当前只支持单线程校验 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 70aa39e1a..f3430ce78 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -855,5 +855,7 @@ Autobackup failed end 关闭替换分组/开启添加分组 + Check book source shows debug message + Show network status and timestamp during source checking, currently only supports single-thread diff --git a/app/src/main/res/xml/pref_config_other.xml b/app/src/main/res/xml/pref_config_other.xml index 28360973f..bb65cb3bd 100644 --- a/app/src/main/res/xml/pref_config_other.xml +++ b/app/src/main/res/xml/pref_config_other.xml @@ -103,6 +103,13 @@ android:title="@string/threads_num_title" app:iconSpaceReserved="false" /> + +