diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt index 146cb90d7..6b000211a 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeRule.kt @@ -170,8 +170,8 @@ class AnalyzeRule(var book: BaseBook? = null) { * 获取文本 */ @Throws(Exception::class) - fun getString(ruleStr: String, isUrl: Boolean = false): String? { - if (TextUtils.isEmpty(ruleStr)) return null + fun getString(ruleStr: String?, isUrl: Boolean = false): String { + if (TextUtils.isEmpty(ruleStr)) return "" val ruleList = splitSourceRule(ruleStr) return getString(ruleList, isUrl) } diff --git a/app/src/main/java/io/legado/app/model/webbook/BookContent.kt b/app/src/main/java/io/legado/app/model/webbook/BookContent.kt index 9db46adb1..6e05d8e5d 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookContent.kt +++ b/app/src/main/java/io/legado/app/model/webbook/BookContent.kt @@ -132,7 +132,7 @@ object BookContent { } SourceDebug.printLog(bookSource.bookSourceUrl, "└" + nextUrlList.joinToString(","), printLog) } - val content = analyzeRule.getString(contentRule.content ?: "")?.htmlFormat() ?: "" + val content = analyzeRule.getString(contentRule.content).htmlFormat() return ContentData(content, nextUrlList) } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/model/webbook/BookInfo.kt b/app/src/main/java/io/legado/app/model/webbook/BookInfo.kt index 0e9933ae5..ff556130f 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookInfo.kt +++ b/app/src/main/java/io/legado/app/model/webbook/BookInfo.kt @@ -31,43 +31,43 @@ object BookInfo { } } SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取书名") - analyzeRule.getString(infoRule.name ?: "")?.let { + analyzeRule.getString(infoRule.name).let { if (it.isNotEmpty()) book.name = it } SourceDebug.printLog(bookSource.bookSourceUrl, "└${book.name}") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取作者") - analyzeRule.getString(infoRule.author ?: "")?.let { + analyzeRule.getString(infoRule.author).let { if (it.isNotEmpty()) book.author = it } SourceDebug.printLog(bookSource.bookSourceUrl, "└${book.author}") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取分类") - analyzeRule.getString(infoRule.kind ?: "")?.let { + analyzeRule.getString(infoRule.kind).let { if (it.isNotEmpty()) book.kind = it } SourceDebug.printLog(bookSource.bookSourceUrl, "└${book.kind}") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取字数") - analyzeRule.getString(infoRule.wordCount ?: "")?.let { + analyzeRule.getString(infoRule.wordCount).let { if (it.isNotEmpty()) book.wordCount = it } SourceDebug.printLog(bookSource.bookSourceUrl, "└${book.wordCount}") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取最新章节") - analyzeRule.getString(infoRule.lastChapter ?: "")?.let { + analyzeRule.getString(infoRule.lastChapter).let { if (it.isNotEmpty()) book.latestChapterTitle = it } SourceDebug.printLog(bookSource.bookSourceUrl, "└${book.latestChapterTitle}") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取简介") - analyzeRule.getString(infoRule.intro ?: "")?.let { + analyzeRule.getString(infoRule.intro).let { if (it.isNotEmpty()) book.intro = it.htmlFormat() } SourceDebug.printLog(bookSource.bookSourceUrl, "└${book.intro}", isHtml = true) SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取封面链接") - analyzeRule.getString(infoRule.coverUrl ?: "")?.let { + analyzeRule.getString(infoRule.coverUrl).let { if (it.isNotEmpty()) book.coverUrl = NetworkUtils.getAbsoluteURL(baseUrl, it) } SourceDebug.printLog(bookSource.bookSourceUrl, "└${book.coverUrl}") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取目录链接") - book.tocUrl = analyzeRule.getString(infoRule.tocUrl ?: "", true) ?: baseUrl + book.tocUrl = analyzeRule.getString(infoRule.tocUrl, true) ?: baseUrl if (book.tocUrl.isEmpty()) book.tocUrl = baseUrl if (book.tocUrl == baseUrl) { book.tocHtml = body diff --git a/app/src/main/java/io/legado/app/model/webbook/BookList.kt b/app/src/main/java/io/legado/app/model/webbook/BookList.kt index 85e0b9bda..85f6d5424 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookList.kt +++ b/app/src/main/java/io/legado/app/model/webbook/BookList.kt @@ -46,7 +46,7 @@ object BookList { bookSource.getExploreRule().bookList.isNullOrBlank() -> bookSource.getSearchRule() else -> bookSource.getExploreRule() } - var ruleList = bookListRule.bookList ?: "" + var ruleList: String = bookListRule.bookList ?: "" if (ruleList.startsWith("-")) { reverse = true ruleList = ruleList.substring(1) @@ -63,14 +63,14 @@ object BookList { bookList.add(searchBook) } } else { - val ruleName = analyzeRule.splitSourceRule(bookListRule.name ?: "") - val ruleBookUrl = analyzeRule.splitSourceRule(bookListRule.bookUrl ?: "") - val ruleAuthor = analyzeRule.splitSourceRule(bookListRule.author ?: "") - val ruleCoverUrl = analyzeRule.splitSourceRule(bookListRule.coverUrl ?: "") - val ruleIntro = analyzeRule.splitSourceRule(bookListRule.intro ?: "") - val ruleKind = analyzeRule.splitSourceRule(bookListRule.kind ?: "") - val ruleLastChapter = analyzeRule.splitSourceRule(bookListRule.lastChapter ?: "") - val ruleWordCount = analyzeRule.splitSourceRule(bookListRule.wordCount ?: "") + val ruleName = analyzeRule.splitSourceRule(bookListRule.name) + val ruleBookUrl = analyzeRule.splitSourceRule(bookListRule.bookUrl) + val ruleAuthor = analyzeRule.splitSourceRule(bookListRule.author) + val ruleCoverUrl = analyzeRule.splitSourceRule(bookListRule.coverUrl) + val ruleIntro = analyzeRule.splitSourceRule(bookListRule.intro) + val ruleKind = analyzeRule.splitSourceRule(bookListRule.kind) + val ruleLastChapter = analyzeRule.splitSourceRule(bookListRule.lastChapter) + val ruleWordCount = analyzeRule.splitSourceRule(bookListRule.wordCount) SourceDebug.printLog(bookSource.bookSourceUrl, "└列表大小:${collections.size}") for ((index, item) in collections.withIndex()) { getSearchItem( @@ -121,26 +121,26 @@ object BookList { } } SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取书名") - searchBook.name = analyzeRule.getString(name ?: "") ?: "" + searchBook.name = analyzeRule.getString(name) SourceDebug.printLog(bookSource.bookSourceUrl, "└${searchBook.name}") if (searchBook.name.isNotEmpty()) { SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取作者") - searchBook.author = BookHelp.formatAuthor(analyzeRule.getString(author ?: "")) + searchBook.author = BookHelp.formatAuthor(analyzeRule.getString(author)) SourceDebug.printLog(bookSource.bookSourceUrl, "└${searchBook.author}") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取分类") - searchBook.kind = analyzeRule.getString(kind ?: "") + searchBook.kind = analyzeRule.getString(kind) SourceDebug.printLog(bookSource.bookSourceUrl, "└${searchBook.kind}") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取字数") - searchBook.wordCount = analyzeRule.getString(wordCount ?: "") + searchBook.wordCount = analyzeRule.getString(wordCount) SourceDebug.printLog(bookSource.bookSourceUrl, "└${searchBook.wordCount}") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取最新章节") - searchBook.latestChapterTitle = analyzeRule.getString(lastChapter ?: "") + searchBook.latestChapterTitle = analyzeRule.getString(lastChapter) SourceDebug.printLog(bookSource.bookSourceUrl, "└${searchBook.latestChapterTitle}") SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取简介") - searchBook.intro = analyzeRule.getString(intro ?: "") + searchBook.intro = analyzeRule.getString(intro) SourceDebug.printLog(bookSource.bookSourceUrl, "└${searchBook.intro}", true) SourceDebug.printLog(bookSource.bookSourceUrl, "┌获取封面链接") - searchBook.coverUrl = analyzeRule.getString(coverUrl ?: "", true) + searchBook.coverUrl = analyzeRule.getString(coverUrl, true) SourceDebug.printLog(bookSource.bookSourceUrl, "└${searchBook.coverUrl}") return searchBook }