pull/32/head
kunfei 5 years ago
parent fecd36ac65
commit 84fa535ec8
  1. 2
      app/src/main/java/io/legado/app/model/WebBook.kt
  2. 24
      app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt
  3. 2
      app/src/main/java/io/legado/app/model/webbook/ChapterData.kt

@ -47,7 +47,7 @@ class WebBook(private val bookSource: BookSource) {
Coroutine.async {
val analyzeUrl = AnalyzeUrl(book = book, ruleUrl = book.tocUrl)
val response = analyzeUrl.getResponseAsync().await()
BookChapterList.analyzeChapterList(book, response, bookSource, analyzeUrl, success)
BookChapterList.analyzeChapterList(this, book, response, bookSource, analyzeUrl, success)
}
}
}

@ -9,11 +9,14 @@ import io.legado.app.data.entities.rule.TocRule
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.NetworkUtils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import retrofit2.Response
object BookChapterList {
fun analyzeChapterList(
coroutineScope: CoroutineScope,
book: Book,
response: Response<String>,
bookSource: BookSource,
@ -35,17 +38,17 @@ object BookChapterList {
chapterData.chapterList?.let {
chapterList.addAll(it)
}
if (chapterData.nextUrlList.size == 1) {
var nextUrl = chapterData.nextUrlList[0]
if (chapterData.nextUrl.size == 1) {
var nextUrl = chapterData.nextUrl[0]
while (nextUrl.isNotEmpty() && !nextUrlList.contains(nextUrl)) {
nextUrlList.add(nextUrl)
AnalyzeUrl(ruleUrl = nextUrl, book = book).getResponse().execute()
.body()?.let { nextBody ->
chapterData = analyzeChapterList(nextBody, nextUrl, tocRule, book)
nextUrl = if (chapterData.nextUrlList.isEmpty()) {
nextUrl = if (chapterData.nextUrl.isEmpty()) {
""
} else {
chapterData.nextUrlList[0]
chapterData.nextUrl[0]
}
chapterData.chapterList?.let {
chapterList.addAll(it)
@ -53,16 +56,23 @@ object BookChapterList {
}
}
success(chapterList)
} else if (chapterData.nextUrlList.size > 1) {
} else if (chapterData.nextUrl.size > 1) {
val chapterDataList = arrayListOf<ChapterData<String>>()
for (item in chapterData.nextUrlList) {
for (item in chapterData.nextUrl) {
if (!nextUrlList.contains(item)) {
val data = ChapterData(nextUrlList = item)
val data = ChapterData(nextUrl = item)
chapterDataList.add(data)
}
}
var successCount = 0
for (item in chapterDataList) {
coroutineScope.launch {
AnalyzeUrl(ruleUrl = item.nextUrl, book = book).getResponse().execute().body()
}
}
}
}
private fun analyzeChapterList(
body: String,

@ -4,5 +4,5 @@ import io.legado.app.data.entities.BookChapter
data class ChapterData<T>(
var chapterList: List<BookChapter>? = null,
var nextUrlList: T
var nextUrl: T
)
Loading…
Cancel
Save