diff --git a/app/src/androidTest/java/io/legado/app/ExampleInstrumentedTest.kt b/app/src/androidTest/java/io/legado/app/ExampleInstrumentedTest.kt index 9820b40fb..4059bc269 100644 --- a/app/src/androidTest/java/io/legado/app/ExampleInstrumentedTest.kt +++ b/app/src/androidTest/java/io/legado/app/ExampleInstrumentedTest.kt @@ -4,12 +4,9 @@ import android.net.Uri import android.util.Log import androidx.test.InstrumentationRegistry import androidx.test.runner.AndroidJUnit4 - import org.junit.Test import org.junit.runner.RunWith -import org.junit.Assert.* - /** * Instrumented test, which will execute on an Android device. * diff --git a/app/src/main/java/io/legado/app/constant/EventBus.kt b/app/src/main/java/io/legado/app/constant/EventBus.kt index 1cb16afd5..5257596fa 100644 --- a/app/src/main/java/io/legado/app/constant/EventBus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.kt @@ -22,6 +22,7 @@ object EventBus { const val UP_DOWNLOAD = "upDownload" const val SAVE_CONTENT = "saveContent" const val CHECK_SOURCE = "checkSource" + const val CHECK_SOURCE_MESSAGE = "checkSourceMessage" const val CHECK_SOURCE_DONE = "checkSourceDone" const val TIP_COLOR = "tipColor" const val SOURCE_CHANGED = "sourceChanged" 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 fd0c75376..94c7249a6 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 834d53efa..cb08cf6f9 100644 --- a/app/src/main/java/io/legado/app/model/Debug.kt +++ b/app/src/main/java/io/legado/app/model/Debug.kt @@ -1,10 +1,7 @@ package io.legado.app.model import android.annotation.SuppressLint -import io.legado.app.data.entities.Book -import io.legado.app.data.entities.BookChapter -import io.legado.app.data.entities.RssArticle -import io.legado.app.data.entities.RssSource +import io.legado.app.data.entities.* import io.legado.app.help.coroutine.CompositeCoroutine import io.legado.app.model.rss.Rss import io.legado.app.model.webBook.WebBook @@ -14,11 +11,14 @@ import io.legado.app.utils.msg import kotlinx.coroutines.CoroutineScope import java.text.SimpleDateFormat import java.util.* +import java.util.concurrent.ConcurrentHashMap object Debug { var callback: Callback? = null private var debugSource: String? = null private val tasks: CompositeCoroutine = CompositeCoroutine() + val debugMessageMap = ConcurrentHashMap() + private var isChecking: Boolean = false @SuppressLint("ConstantLocale") private val DEBUG_TIME_FORMAT = SimpleDateFormat("[mm:ss.SSS]", Locale.getDefault()) @@ -34,7 +34,7 @@ object Debug { state: Int = 1 ) { callback?.let { - if (debugSource != sourceUrl || !print) return + if ((debugSource != sourceUrl || !print) && !isChecking) return var printMsg = msg ?: "" if (isHtml) { printMsg = HtmlFormatter.format(msg) @@ -44,6 +44,10 @@ object Debug { printMsg = "$time $printMsg" } it.printLog(state, printMsg) + if (sourceUrl != null && printMsg.length < 30) { + debugMessageMap[sourceUrl] = printMsg + callback?.postCheckMessageEvent(sourceUrl) + } } } @@ -61,6 +65,17 @@ object Debug { } } + fun startChecking(source: BookSource) { + startTime = System.currentTimeMillis() + isChecking = true + debugMessageMap[source.bookSourceUrl] = "开始校验" + } + + fun finishChecking() { + callback = null + isChecking = false + } + fun startDebug(scope: CoroutineScope, rssSource: RssSource) { cancelDebug() debugSource = rssSource.sourceUrl @@ -246,6 +261,7 @@ object Debug { interface Callback { fun printLog(state: Int, 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 0c19e7445..c788fae58 100644 --- a/app/src/main/java/io/legado/app/service/CheckSourceService.kt +++ b/app/src/main/java/io/legado/app/service/CheckSourceService.kt @@ -12,6 +12,7 @@ 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 import io.legado.app.model.webBook.WebBook import io.legado.app.service.help.CheckSource import io.legado.app.ui.book.source.manage.BookSourceActivity @@ -29,6 +30,7 @@ class CheckSourceService : BaseService() { private val checkedIds = ArrayList() private var processIndex = 0 private var notificationMsg = "" + private var debugCallback : Debug.Callback? = null private val notificationBuilder by lazy { NotificationCompat.Builder(this, AppConst.channelIdReadAloud) .setSmallIcon(R.drawable.ic_network_check) @@ -48,6 +50,18 @@ 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() } @@ -106,6 +120,9 @@ class CheckSourceService : BaseService() { fun check(source: BookSource) { execute(context = searchCoroutine) { + if (AppConfig.checkSourceMessage) { + Debug.startChecking(source) + } val webBook = WebBook(source) var books = webBook.searchBookAwait(this, CheckSource.keyword) if (books.isEmpty()) { @@ -135,6 +152,10 @@ 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) + } appDb.bookSourceDao.update(source) }.onSuccess(searchCoroutine) { source.removeGroup("失效") @@ -143,6 +164,11 @@ 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) + } + appDb.bookSourceDao.update(source) }.onFinally(searchCoroutine) { onNext(source.bookSourceUrl, source.bookSourceName) @@ -156,7 +182,7 @@ class CheckSourceService : BaseService() { notificationMsg = getString(R.string.progress_show, sourceName, checkedIds.size, allIds.size) upNotification() - if (processIndex >= allIds.size + threadCount - 1) { + if (processIndex > allIds.size + threadCount - 1) { stopSelf() } } 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 991591029..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,6 +51,8 @@ class BookSourceDebugModel(application: Application) : BaseViewModel(application } } + override fun postCheckMessageEvent(sourceUrl: String) {} + override fun onCleared() { super.onCleared() Debug.cancelDebug(true) 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 277335dd4..a107c178b 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 @@ -9,6 +9,7 @@ import android.view.SubMenu import androidx.activity.viewModels import androidx.appcompat.widget.PopupMenu import androidx.appcompat.widget.SearchView +import androidx.core.os.bundleOf import androidx.documentfile.provider.DocumentFile import androidx.recyclerview.widget.ItemTouchHelper import com.google.android.material.snackbar.Snackbar @@ -24,6 +25,7 @@ import io.legado.app.help.LocalConfig import io.legado.app.lib.dialogs.alert import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor +import io.legado.app.model.Debug import io.legado.app.service.help.CheckSource import io.legado.app.ui.association.ImportBookSourceDialog import io.legado.app.ui.book.source.debug.BookSourceDebugActivity @@ -39,7 +41,7 @@ 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.flow.collect +import kotlinx.coroutines.flow.* import kotlinx.coroutines.launch import java.io.File @@ -434,6 +436,7 @@ class BookSourceActivity : VMBaseActivity(EventBus.CHECK_SOURCE_DONE) { + Debug.finishChecking() snackBar?.dismiss() snackBar = null groups.map { group -> @@ -443,6 +446,15 @@ class BookSourceActivity : VMBaseActivity(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))) } + } + } } override fun upCountView() { 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 7669362fc..7e0937b3c 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 @@ -13,9 +13,11 @@ 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 +import io.legado.app.model.Debug import io.legado.app.ui.widget.recycler.DragSelectTouchHelper import io.legado.app.ui.widget.recycler.ItemTouchCallback.Callback import io.legado.app.utils.ColorUtils @@ -107,11 +109,18 @@ class BookSourceAdapter(context: Context, val callBack: CallBack) : } swtEnabled.isChecked = item.enabled cbBookSource.isChecked = selected.contains(item) + ivDebugText.text = Debug.debugMessageMap[item.bookSourceUrl] ?: "" + ivDebugText.visibility = if(ivDebugText.text.toString().length > 1) View.VISIBLE else View.GONE upShowExplore(ivExplore, item) } else { payload.keySet().map { when (it) { "selected" -> cbBookSource.isChecked = selected.contains(item) + EventBus.CHECK_SOURCE_MESSAGE -> { + 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 23892dc6f..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,6 +44,8 @@ class RssSourceDebugModel(application: Application) : BaseViewModel(application) } } + override fun postCheckMessageEvent(sourceUrl: String) {} + override fun onCleared() { super.onCleared() Debug.cancelDebug(true) 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 c2c2f893f..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,4 +95,8 @@ class SourceDebugWebSocket(handshakeRequest: NanoHTTPD.IHTTPSession) : } } + 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 4f3584999..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="parent" /> + app:layout_constraintBottom_toTopOf="@id/iv_debug_text" /> + app:layout_constraintBottom_toTopOf="@id/iv_debug_text" /> + app:layout_constraintBottom_toTopOf="@id/iv_debug_text" /> + + + + \ No newline at end of file diff --git a/app/src/main/res/values-es-rES/strings.xml b/app/src/main/res/values-es-rES/strings.xml index f5d756348..216dd64f1 100644 --- a/app/src/main/res/values-es-rES/strings.xml +++ b/app/src/main/res/values-es-rES/strings.xml @@ -853,4 +853,6 @@ 媒体按钮•上一首|下一首 上一段|下一段/上一章|下一章 及时翻页,翻页时会停顿一下 + 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 011813ba0..081b09ee5 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -854,4 +854,6 @@ 媒体按钮•上一首|下一首 上一段|下一段/上一章|下一章 及时翻页,翻页时会停顿一下 + 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 d79a5f2da..03cdc19b9 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -853,4 +853,6 @@ 媒体按钮•上一首|下一首 上一段|下一段/上一章|下一章 及时翻页,翻页时会停顿一下 + 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 3c2a27676..aea6f7aae 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -855,5 +855,7 @@ 媒体按钮•上一首|下一首 上一段|下一段/上一章|下一章 及时翻页,翻页时会停顿一下 + 校驗書源顯示詳細信息 + 書源校驗時顯示網絡請求步驟和時間,當前只支持單線程校驗 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index 263d3a6d9..d5984a40f 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -856,5 +856,7 @@ 媒体按钮•上一首|下一首 上一段|下一段/上一章|下一章 及时翻页,翻页时会停顿一下 + 校驗書源顯示詳細信息 + 書源校驗時顯示網絡請求步驟和時間,當前只支持單線程校驗 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index d714d20e5..bae9c5131 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -857,5 +857,7 @@ 媒体按钮•上一首|下一首 上一段|下一段/上一章|下一章 及时翻页,翻页时会停顿一下 + 校验显示详细信息 + 书源校验时显示网络请求步骤和时间,当前只支持单线程校验 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 2c9741162..b721a2de9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -858,5 +858,7 @@ 媒体按钮•上一首|下一首 上一段|下一段/上一章|下一章 及时翻页,翻页时会停顿一下 + 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" /> + +