pull/46/head
kunfei 5 years ago
parent 8190b7f711
commit 3f92af5b79
  1. 2
      app/src/main/java/io/legado/app/model/Rss.kt
  2. 10
      app/src/main/java/io/legado/app/model/WebBook.kt
  3. 7
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  4. 4
      app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt
  5. 4
      app/src/main/java/io/legado/app/model/webbook/BookContent.kt
  6. 2
      app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt

@ -17,7 +17,7 @@ object Rss {
context: CoroutineContext = Dispatchers.IO context: CoroutineContext = Dispatchers.IO
): Coroutine<MutableList<RssArticle>> { ): Coroutine<MutableList<RssArticle>> {
return Coroutine.async(scope, context) { return Coroutine.async(scope, context) {
val response = AnalyzeUrl(rssSource.sourceUrl).getResponseAsync().await() val response = AnalyzeUrl(rssSource.sourceUrl).getResponseAwait()
RssParserByRule.parseXML(response, rssSource) RssParserByRule.parseXML(response, rssSource)
} }
} }

@ -38,7 +38,7 @@ class WebBook(val bookSource: BookSource) {
baseUrl = sourceUrl, baseUrl = sourceUrl,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
) )
val response = analyzeUrl.getResponseAsync().await() val response = analyzeUrl.getResponseAwait()
BookList.analyzeBookList( BookList.analyzeBookList(
response.body(), response.body(),
bookSource, bookSource,
@ -66,7 +66,7 @@ class WebBook(val bookSource: BookSource) {
baseUrl = sourceUrl, baseUrl = sourceUrl,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
) )
val response = analyzeUrl.getResponseAsync().await() val response = analyzeUrl.getResponseAwait()
BookList.analyzeBookList( BookList.analyzeBookList(
response.body(), response.body(),
bookSource, bookSource,
@ -93,7 +93,7 @@ class WebBook(val bookSource: BookSource) {
baseUrl = sourceUrl, baseUrl = sourceUrl,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
) )
analyzeUrl.getResponseAsync().await().body() analyzeUrl.getResponseAwait().body()
} else { } else {
book.infoHtml book.infoHtml
} }
@ -120,7 +120,7 @@ class WebBook(val bookSource: BookSource) {
baseUrl = book.bookUrl, baseUrl = book.bookUrl,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
) )
analyzeUrl.getResponseAsync().await().body() analyzeUrl.getResponseAwait().body()
} }
BookChapterList.analyzeChapterList(this, book, body, bookSource, book.tocUrl) BookChapterList.analyzeChapterList(this, book, body, bookSource, book.tocUrl)
} }
@ -150,7 +150,7 @@ class WebBook(val bookSource: BookSource) {
baseUrl = book.tocUrl, baseUrl = book.tocUrl,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
) )
analyzeUrl.getResponseAsync().await().body() analyzeUrl.getResponseAwait().body()
} }
BookContent.analyzeContent( BookContent.analyzeContent(
this, this,

@ -14,7 +14,6 @@ import io.legado.app.help.http.AjaxWebView
import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.HttpHelper
import io.legado.app.help.http.RequestMethod import io.legado.app.help.http.RequestMethod
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.coroutines.Deferred
import okhttp3.FormBody import okhttp3.FormBody
import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody import okhttp3.RequestBody
@ -267,25 +266,29 @@ class AnalyzeUrl(
} }
@Throws(Exception::class) @Throws(Exception::class)
fun getResponseAsync(): Deferred<Response<String>> { suspend fun getResponseAwait(): Response<String> {
return when { return when {
method == RequestMethod.POST -> { method == RequestMethod.POST -> {
if (fieldMap.isNotEmpty()) { if (fieldMap.isNotEmpty()) {
HttpHelper HttpHelper
.getApiService<IHttpPostApi>(baseUrl) .getApiService<IHttpPostApi>(baseUrl)
.postMapAsync(url, fieldMap, headerMap) .postMapAsync(url, fieldMap, headerMap)
.await()
} else { } else {
HttpHelper HttpHelper
.getApiService<IHttpPostApi>(baseUrl) .getApiService<IHttpPostApi>(baseUrl)
.postBodyAsync(url, body!!, headerMap) .postBodyAsync(url, body!!, headerMap)
.await()
} }
} }
fieldMap.isEmpty() -> HttpHelper fieldMap.isEmpty() -> HttpHelper
.getApiService<IHttpGetApi>(baseUrl) .getApiService<IHttpGetApi>(baseUrl)
.getAsync(url, headerMap) .getAsync(url, headerMap)
.await()
else -> HttpHelper else -> HttpHelper
.getApiService<IHttpGetApi>(baseUrl) .getApiService<IHttpGetApi>(baseUrl)
.getMapAsync(url, fieldMap, headerMap) .getMapAsync(url, fieldMap, headerMap)
.await()
} }
} }

@ -50,7 +50,7 @@ object BookChapterList {
ruleUrl = nextUrl, ruleUrl = nextUrl,
book = book, book = book,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
).getResponseAsync().await() ).getResponseAwait()
.body()?.let { nextBody -> .body()?.let { nextBody ->
chapterData = analyzeChapterList( chapterData = analyzeChapterList(
nextBody, nextBody,
@ -82,7 +82,7 @@ object BookChapterList {
ruleUrl = item.nextUrl, ruleUrl = item.nextUrl,
book = book, book = book,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
).getResponseAsync().await() ).getResponseAwait()
val nextChapterData = analyzeChapterList( val nextChapterData = analyzeChapterList(
nextResponse.body() ?: "", nextResponse.body() ?: "",
item.nextUrl, item.nextUrl,

@ -53,7 +53,7 @@ object BookContent {
ruleUrl = nextUrl, ruleUrl = nextUrl,
book = book, book = book,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
).getResponseAsync().await() ).getResponseAwait()
.body()?.let { nextBody -> .body()?.let { nextBody ->
contentData = contentData =
analyzeContent(nextBody, contentRule, book, bookSource, baseUrl, false) analyzeContent(nextBody, contentRule, book, bookSource, baseUrl, false)
@ -75,7 +75,7 @@ object BookContent {
ruleUrl = item.nextUrl, ruleUrl = item.nextUrl,
book = book, book = book,
headerMapF = bookSource.getHeaderMap() headerMapF = bookSource.getHeaderMap()
).getResponseAsync().await() ).getResponseAwait()
.body()?.let { .body()?.let {
contentData = contentData =
analyzeContent( analyzeContent(

@ -54,7 +54,7 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
private fun loadContent(rssArticle: RssArticle, ruleContent: String) { private fun loadContent(rssArticle: RssArticle, ruleContent: String) {
execute { execute {
rssArticle.link?.let { rssArticle.link?.let {
AnalyzeUrl(it, baseUrl = rssArticle.origin).getResponseAsync().await().body() AnalyzeUrl(it, baseUrl = rssArticle.origin).getResponseAwait().body()
?.let { body -> ?.let { body ->
AnalyzeRule().apply { AnalyzeRule().apply {
setContent(body, NetworkUtils.getAbsoluteURL(rssArticle.origin, it)) setContent(body, NetworkUtils.getAbsoluteURL(rssArticle.origin, it))

Loading…
Cancel
Save