diff --git a/app/src/main/java/io/legado/app/help/book/ContentProcessor.kt b/app/src/main/java/io/legado/app/help/book/ContentProcessor.kt index 7153c3d2f..7f1de2870 100644 --- a/app/src/main/java/io/legado/app/help/book/ContentProcessor.kt +++ b/app/src/main/java/io/legado/app/help/book/ContentProcessor.kt @@ -83,14 +83,14 @@ class ContentProcessor private constructor( var mContent = content if (content != "null") { //去除重复标题 - try { - val name = Pattern.quote(book.name) - val title = Pattern.quote(chapter.title) - val titleRegex = "^(\\s|\\p{P}|${name})*${title}(\\s)*".toRegex() - mContent = mContent.replace(titleRegex, "") - } catch (e: Exception) { - AppLog.put("去除重复标题出错\n${e.localizedMessage}", e) - } +// try { +// val name = Pattern.quote(book.name) +// val title = Pattern.quote(chapter.title) +// val titleRegex = "^(\\s|\\p{P}|${name})*${title}(\\s)*".toRegex() +// mContent = mContent.replace(titleRegex, "") +// } catch (e: Exception) { +// AppLog.put("去除重复标题出错\n${e.localizedMessage}", e) +// } if (reSegment && book.getReSegment()) { //重新分段 mContent = ContentHelp.reSegment(mContent, chapter.title) diff --git a/app/src/main/java/io/legado/app/help/source/BookSourceExtensions.kt b/app/src/main/java/io/legado/app/help/source/BookSourceExtensions.kt index 946d6d42a..a94f30581 100644 --- a/app/src/main/java/io/legado/app/help/source/BookSourceExtensions.kt +++ b/app/src/main/java/io/legado/app/help/source/BookSourceExtensions.kt @@ -35,8 +35,8 @@ suspend fun BookSource.exploreKinds(): List { withContext(Dispatchers.IO) { kotlin.runCatching { var ruleStr = exploreUrl - if (exploreUrl.startsWith("", false) - || exploreUrl.startsWith("@js:", false) + if (exploreUrl.startsWith("", true) + || exploreUrl.startsWith("@js:", true) ) { ruleStr = aCache.getAsString(exploreKindsKey) if (ruleStr.isNullOrBlank()) { @@ -50,8 +50,8 @@ suspend fun BookSource.exploreKinds(): List { } } if (ruleStr.isJsonArray()) { - GSON.fromJsonArray(ruleStr).getOrThrow()?.let { - kinds.addAll(it) + GSON.fromJsonArray(ruleStr).getOrThrow()?.let { + kinds.addAll(it.filterNotNull()) } } else { ruleStr.split("(&&|\n)+".toRegex()).forEach { kindStr -> diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt index f1d0df3aa..ee9aed5af 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt @@ -216,6 +216,7 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_ } R.id.menu_start_stop -> viewModel.startOrStopSearch() R.id.menu_source_manage -> startActivity() + R.id.menu_refresh_list -> viewModel.startRefreshList() else -> if (item?.groupId == R.id.source_group) { if (!item.isChecked) { item.isChecked = true diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt index ed4ba5443..5bab273c6 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt @@ -46,6 +46,7 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a private var tasks = CompositeCoroutine() private var screenKey: String = "" private var bookSourceList = arrayListOf() + private var searchBookList = arrayListOf() private val searchBooks = Collections.synchronizedList(arrayListOf()) private val tocMap = ConcurrentHashMap>() private var searchCallback: SourceCallback? = null @@ -136,6 +137,9 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a } } + /** + * 搜索书籍 + */ fun startSearch() { execute { stopSearch() @@ -235,6 +239,58 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a } } + /** + * 刷新列表 + */ + fun startRefreshList() { + execute { + stopSearch() + searchBookList.clear() + searchBookList.addAll(searchBooks) + searchBooks.clear() + searchStateData.postValue(true) + initSearchPool() + for (i in 0 until threadCount) { + refreshList() + } + } + } + + private fun refreshList() { + synchronized(this) { + if (searchIndex >= searchBookList.lastIndex) { + return + } + searchIndex++ + } + val searchBook = searchBookList[searchIndex] + val task = Coroutine.async(scope = viewModelScope, context = searchPool!!) { + val source = appDb.bookSourceDao.getBookSource(searchBook.origin) ?: return@async + loadBookInfo(source, searchBook.toBook()) + }.timeout(60000L) + .onError { + nextRefreshList() + } + .onSuccess { + nextRefreshList() + } + tasks.add(task) + } + + private fun nextRefreshList() { + synchronized(this) { + if (searchIndex < searchBookList.lastIndex) { + refreshList() + } else { + searchIndex++ + } + if (searchIndex >= searchBookList.lastIndex + min(searchBookList.size, threadCount)) { + searchStateData.postValue(false) + tasks.clear() + } + } + } + private fun getDbSearchBooks(): List { return if (screenKey.isEmpty()) { if (AppConfig.changeSourceCheckAuthor) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index c063033bf..f5123bc8f 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -70,6 +70,10 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { book != null -> initBook(book) else -> ReadBook.upMsg(context.getString(R.string.no_book)) } + }.onError { + val msg = "初始化数据失败\n${it.localizedMessage}" + ReadBook.upMsg(msg) + AppLog.put(msg, it) }.onFinally { ReadBook.saveRead() } diff --git a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt index 4f893e56a..6c817e48b 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/debug/BookSourceDebugActivity.kt @@ -108,28 +108,10 @@ class BookSourceDebugActivity : VMBaseActivity + + 多分组/书源 替换(启用/禁用) 显示上次更新时间 + 刷新列表 diff --git a/app/src/main/res/values-ja-rJP/strings.xml b/app/src/main/res/values-ja-rJP/strings.xml index d9546b052..98ca97c84 100644 --- a/app/src/main/res/values-ja-rJP/strings.xml +++ b/app/src/main/res/values-ja-rJP/strings.xml @@ -1061,4 +1061,5 @@ 多分组/书源 替换(启用/禁用) 显示上次更新时间 + 刷新列表 diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml index d84082c7f..21e9402c0 100644 --- a/app/src/main/res/values-pt-rBR/strings.xml +++ b/app/src/main/res/values-pt-rBR/strings.xml @@ -1061,4 +1061,5 @@ 多分组/书源 替换(启用/禁用) 显示上次更新时间 + 刷新列表 diff --git a/app/src/main/res/values-zh-rHK/strings.xml b/app/src/main/res/values-zh-rHK/strings.xml index b1a80e43d..18005bc08 100644 --- a/app/src/main/res/values-zh-rHK/strings.xml +++ b/app/src/main/res/values-zh-rHK/strings.xml @@ -1058,4 +1058,5 @@ 多分组/书源 替换(启用/禁用) 显示上次更新时间 + 刷新列表 diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index d1716cfe8..02e02daca 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -1060,4 +1060,5 @@ 多分組/書源 取代(啟用/禁用) 顯示上次更新時間 + 刷新列表 diff --git a/app/src/main/res/values-zh/strings.xml b/app/src/main/res/values-zh/strings.xml index 8433944e3..823eac757 100644 --- a/app/src/main/res/values-zh/strings.xml +++ b/app/src/main/res/values-zh/strings.xml @@ -1060,4 +1060,5 @@ 多分组/书源 替换(启用/禁用) 显示上次更新时间 + 刷新列表 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7c14c2118..820f50c0c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1061,4 +1061,5 @@ 多分组/书源 替换(启用/禁用) 显示上次更新时间 + 刷新列表