From 8d45c9e573907638dad803dd51b98a96188a68f0 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 12 Dec 2020 09:54:07 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/entities/BookChapter.kt | 2 +- .../io/legado/app/model/analyzeRule/AnalyzeUrl.kt | 2 +- .../io/legado/app/model/rss/RssParserByRule.kt | 2 +- .../io/legado/app/ui/book/cache/CacheViewModel.kt | 5 ++--- .../ui/book/read/page/provider/ChapterProvider.kt | 15 +++++++-------- .../main/java/io/legado/app/utils/NetworkUtils.kt | 5 ++--- 6 files changed, 14 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt index 4d2e1e9e3..ea97c94f8 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookChapter.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookChapter.kt @@ -63,7 +63,7 @@ data class BookChapter( fun getAbsoluteURL(): String { val urlArray = url.split(AnalyzeUrl.splitUrlRegex) - var absoluteUrl = NetworkUtils.getAbsoluteURL(baseUrl, urlArray[0])!! + var absoluteUrl = NetworkUtils.getAbsoluteURL(baseUrl, urlArray[0]) if (urlArray.size > 1) { absoluteUrl = "$absoluteUrl,${urlArray[1]}" } diff --git a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt index e36750a1f..3e1f6079f 100644 --- a/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt +++ b/app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt @@ -165,7 +165,7 @@ class AnalyzeUrl( */ private fun initUrl() { var urlArray = ruleUrl.split(splitUrlRegex, 2) - url = NetworkUtils.getAbsoluteURL(baseUrl, urlArray[0])!! + url = NetworkUtils.getAbsoluteURL(baseUrl, urlArray[0]) urlHasQuery = urlArray[0] NetworkUtils.getBaseUrl(url)?.let { baseUrl = it diff --git a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt index 955df439b..13503e510 100644 --- a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt +++ b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt @@ -112,7 +112,7 @@ object RssParserByRule { rssArticle.image = analyzeRule.getString(ruleImage, true) Debug.log(sourceUrl, "└${rssArticle.image}", log) Debug.log(sourceUrl, "┌获取文章链接", log) - rssArticle.link = NetworkUtils.getAbsoluteURL(sourceUrl, analyzeRule.getString(ruleLink))!! + rssArticle.link = NetworkUtils.getAbsoluteURL(sourceUrl, analyzeRule.getString(ruleLink)) Debug.log(sourceUrl, "└${rssArticle.link}", log) if (rssArticle.title.isBlank()) { return null diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index d0fd4f34a..2df117411 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -109,9 +109,8 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { content.split("\n").forEachIndexed { index, text -> val matcher = AppPattern.imgPattern.matcher(text) if (matcher.find()) { - var src = matcher.group(1) - src = NetworkUtils.getAbsoluteURL(chapter.url, src) - src?.let { + matcher.group(1)?.let { + val src = NetworkUtils.getAbsoluteURL(chapter.url, it) srcList.add(Triple(chapter.title, index, src)) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt index f81ddfffb..399666b14 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/page/provider/ChapterProvider.kt @@ -95,14 +95,13 @@ object ChapterProvider { contents.forEachIndexed { index, text -> val matcher = AppPattern.imgPattern.matcher(text) if (matcher.find()) { - var src = matcher.group(1) - if (!book.isEpub()) { - src = NetworkUtils.getAbsoluteURL(bookChapter.url, src) - } - src?.let { - durY = setTypeImage( - book, bookChapter, src, durY, textPages, imageStyle - ) + matcher.group(1)?.let { + if (!book.isEpub()) { + val src = NetworkUtils.getAbsoluteURL(bookChapter.url, it) + durY = setTypeImage( + book, bookChapter, src, durY, textPages, imageStyle + ) + } } } else { val isTitle = index == 0 diff --git a/app/src/main/java/io/legado/app/utils/NetworkUtils.kt b/app/src/main/java/io/legado/app/utils/NetworkUtils.kt index 79dcb5790..87be05e05 100644 --- a/app/src/main/java/io/legado/app/utils/NetworkUtils.kt +++ b/app/src/main/java/io/legado/app/utils/NetworkUtils.kt @@ -69,9 +69,8 @@ object NetworkUtils { /** * 获取绝对地址 */ - fun getAbsoluteURL(baseURL: String?, relativePath: String?): String? { + fun getAbsoluteURL(baseURL: String?, relativePath: String): String { if (baseURL.isNullOrEmpty()) return relativePath - if (relativePath.isNullOrEmpty()) return baseURL if (relativePath.isAbsUrl()) return relativePath var relativeUrl = relativePath try { @@ -88,7 +87,7 @@ object NetworkUtils { /** * 获取绝对地址 */ - fun getAbsoluteURL(baseURL: URL?, relativePath: String): String? { + fun getAbsoluteURL(baseURL: URL?, relativePath: String): String { if (baseURL == null) return relativePath var relativeUrl = relativePath try {