pull/32/head
kunfei 5 years ago
parent 4dfe1a6774
commit 9ac632a628
  1. 43
      app/src/main/java/io/legado/app/model/webbook/BookList.kt

@ -8,7 +8,6 @@ import io.legado.app.data.entities.rule.BookListRule
import io.legado.app.model.analyzeRule.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.NetworkUtils
import org.mozilla.javascript.NativeObject
import retrofit2.Response
object BookList {
@ -42,36 +41,18 @@ object BookList {
}
val collections: List<Any>
var reverse = false
var allInOne = false
val bookListRule = if (isSearch) bookSource.getSearchRule() else bookSource.getExploreRule()
var ruleList = bookListRule.bookList ?: ""
if (ruleList.startsWith("-")) {
reverse = true
ruleList = ruleList.substring(1)
}
if (ruleList.startsWith(":")) {
ruleList = ruleList.substring(1)
}
if (ruleList.startsWith("+")) {
allInOne = true
ruleList = ruleList.substring(1)
}
collections = analyzer.getElements(ruleList)
if (collections.isEmpty() && bookSource.bookUrlPattern.isNullOrEmpty()) {
getInfoItem(analyzer, bookSource, baseUrl)?.let { searchBook ->
searchBook.bookInfoHtml = body
bookList.add(searchBook)
}
} else {
if (allInOne) {
for (item in collections) {
getAllInOneItem(item, analyzer, bookListRule, bookSource, baseUrl)?.let { searchBook ->
if (baseUrl == searchBook.bookUrl) {
searchBook.bookInfoHtml = body
}
bookList.add(searchBook)
}
}
} else {
for (item in collections) {
getSearchItem(item, analyzer, bookListRule, bookSource, baseUrl)?.let { searchBook ->
@ -81,7 +62,6 @@ object BookList {
bookList.add(searchBook)
}
}
}
if (reverse) {
bookList.reverse()
}
@ -114,29 +94,6 @@ object BookList {
return null
}
private fun getAllInOneItem(
item: Any,
analyzeRule: AnalyzeRule,
bookListRule: BookListRule,
bookSource: BookSource,
baseUrl: String
): SearchBook? {
val searchBook = SearchBook()
searchBook.origin = bookSource.bookSourceUrl
searchBook.originName = bookSource.bookSourceName
val nativeObject = item as NativeObject
searchBook.name = nativeObject[bookListRule.name]?.toString()
searchBook.name?.let {
searchBook.author = nativeObject[bookListRule.author]?.toString()
searchBook.coverUrl = nativeObject[bookListRule.coverUrl]?.toString()
searchBook.intro = nativeObject[bookListRule.intro]?.toString()
searchBook.kind = nativeObject[bookListRule.kind]?.toString()
searchBook.wordCount = nativeObject[bookListRule.wordCount]?.toString()
return searchBook
}
return null
}
private fun getSearchItem(
item: Any,
analyzeRule: AnalyzeRule,

Loading…
Cancel
Save