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
): Coroutine<MutableList<RssArticle>> {
return Coroutine.async(scope, context) {
val response = AnalyzeUrl(rssSource.sourceUrl).getResponseAsync().await()
val response = AnalyzeUrl(rssSource.sourceUrl).getResponseAwait()
RssParserByRule.parseXML(response, rssSource)
}
}

@ -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,

@ -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<Response<String>> {
suspend fun getResponseAwait(): Response<String> {
return when {
method == RequestMethod.POST -> {
if (fieldMap.isNotEmpty()) {
HttpHelper
.getApiService<IHttpPostApi>(baseUrl)
.postMapAsync(url, fieldMap, headerMap)
.await()
} else {
HttpHelper
.getApiService<IHttpPostApi>(baseUrl)
.postBodyAsync(url, body!!, headerMap)
.await()
}
}
fieldMap.isEmpty() -> HttpHelper
.getApiService<IHttpGetApi>(baseUrl)
.getAsync(url, headerMap)
.await()
else -> HttpHelper
.getApiService<IHttpGetApi>(baseUrl)
.getMapAsync(url, fieldMap, headerMap)
.await()
}
}

@ -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,

@ -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(

@ -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))

Loading…
Cancel
Save