diff --git a/app/src/main/java/io/legado/app/model/Rss.kt b/app/src/main/java/io/legado/app/model/Rss.kt index cd76e24fe..d9f3da930 100644 --- a/app/src/main/java/io/legado/app/model/Rss.kt +++ b/app/src/main/java/io/legado/app/model/Rss.kt @@ -17,7 +17,7 @@ object Rss { context: CoroutineContext = Dispatchers.IO ): Coroutine> { return Coroutine.async(scope, context) { - val response = AnalyzeUrl(rssSource.sourceUrl).getResponseAsync().await() + val response = AnalyzeUrl(rssSource.sourceUrl).getResponseAwait() RssParserByRule.parseXML(response, rssSource) } } diff --git a/app/src/main/java/io/legado/app/model/WebBook.kt b/app/src/main/java/io/legado/app/model/WebBook.kt index 1f3b12dbc..dd1e86591 100644 --- a/app/src/main/java/io/legado/app/model/WebBook.kt +++ b/app/src/main/java/io/legado/app/model/WebBook.kt @@ -38,7 +38,7 @@ class WebBook(val bookSource: BookSource) { baseUrl = sourceUrl, headerMapF = bookSource.getHeaderMap() ) - val response = analyzeUrl.getResponseAsync().await() + val response = analyzeUrl.getResponseAwait() BookList.analyzeBookList( response.body(), bookSource, @@ -66,7 +66,7 @@ class WebBook(val bookSource: BookSource) { baseUrl = sourceUrl, headerMapF = bookSource.getHeaderMap() ) - val response = analyzeUrl.getResponseAsync().await() + val response = analyzeUrl.getResponseAwait() BookList.analyzeBookList( response.body(), bookSource, @@ -93,7 +93,7 @@ class WebBook(val bookSource: BookSource) { baseUrl = sourceUrl, headerMapF = bookSource.getHeaderMap() ) - analyzeUrl.getResponseAsync().await().body() + analyzeUrl.getResponseAwait().body() } else { book.infoHtml } @@ -120,7 +120,7 @@ class WebBook(val bookSource: BookSource) { baseUrl = book.bookUrl, headerMapF = bookSource.getHeaderMap() ) - analyzeUrl.getResponseAsync().await().body() + analyzeUrl.getResponseAwait().body() } BookChapterList.analyzeChapterList(this, book, body, bookSource, book.tocUrl) } @@ -150,7 +150,7 @@ class WebBook(val bookSource: BookSource) { baseUrl = book.tocUrl, headerMapF = bookSource.getHeaderMap() ) - analyzeUrl.getResponseAsync().await().body() + analyzeUrl.getResponseAwait().body() } BookContent.analyzeContent( this, 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 8cd4149c7..5dd513433 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 @@ -14,7 +14,6 @@ import io.legado.app.help.http.AjaxWebView import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.RequestMethod import io.legado.app.utils.* -import kotlinx.coroutines.Deferred import okhttp3.FormBody import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.RequestBody @@ -267,25 +266,29 @@ class AnalyzeUrl( } @Throws(Exception::class) - fun getResponseAsync(): Deferred> { + suspend fun getResponseAwait(): Response { return when { method == RequestMethod.POST -> { if (fieldMap.isNotEmpty()) { HttpHelper .getApiService(baseUrl) .postMapAsync(url, fieldMap, headerMap) + .await() } else { HttpHelper .getApiService(baseUrl) .postBodyAsync(url, body!!, headerMap) + .await() } } fieldMap.isEmpty() -> HttpHelper .getApiService(baseUrl) .getAsync(url, headerMap) + .await() else -> HttpHelper .getApiService(baseUrl) .getMapAsync(url, fieldMap, headerMap) + .await() } } diff --git a/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt index 29696be30..52cfc7863 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt @@ -50,7 +50,7 @@ object BookChapterList { ruleUrl = nextUrl, book = book, headerMapF = bookSource.getHeaderMap() - ).getResponseAsync().await() + ).getResponseAwait() .body()?.let { nextBody -> chapterData = analyzeChapterList( nextBody, @@ -82,7 +82,7 @@ object BookChapterList { ruleUrl = item.nextUrl, book = book, headerMapF = bookSource.getHeaderMap() - ).getResponseAsync().await() + ).getResponseAwait() val nextChapterData = analyzeChapterList( nextResponse.body() ?: "", item.nextUrl, 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 33f06fc93..33f1083df 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 @@ -53,7 +53,7 @@ object BookContent { ruleUrl = nextUrl, book = book, headerMapF = bookSource.getHeaderMap() - ).getResponseAsync().await() + ).getResponseAwait() .body()?.let { nextBody -> contentData = analyzeContent(nextBody, contentRule, book, bookSource, baseUrl, false) @@ -75,7 +75,7 @@ object BookContent { ruleUrl = item.nextUrl, book = book, headerMapF = bookSource.getHeaderMap() - ).getResponseAsync().await() + ).getResponseAwait() .body()?.let { contentData = analyzeContent( diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index c50127ebd..2d8f000ae 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -54,7 +54,7 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) { private fun loadContent(rssArticle: RssArticle, ruleContent: String) { execute { rssArticle.link?.let { - AnalyzeUrl(it, baseUrl = rssArticle.origin).getResponseAsync().await().body() + AnalyzeUrl(it, baseUrl = rssArticle.origin).getResponseAwait().body() ?.let { body -> AnalyzeRule().apply { setContent(body, NetworkUtils.getAbsoluteURL(rssArticle.origin, it))