pull/32/head
kunfei 5 years ago
parent 4dfe1a6774
commit 9ac632a628
  1. 53
      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.AnalyzeRule
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.utils.NetworkUtils import io.legado.app.utils.NetworkUtils
import org.mozilla.javascript.NativeObject
import retrofit2.Response import retrofit2.Response
object BookList { object BookList {
@ -42,20 +41,12 @@ object BookList {
} }
val collections: List<Any> val collections: List<Any>
var reverse = false var reverse = false
var allInOne = false
val bookListRule = if (isSearch) bookSource.getSearchRule() else bookSource.getExploreRule() val bookListRule = if (isSearch) bookSource.getSearchRule() else bookSource.getExploreRule()
var ruleList = bookListRule.bookList ?: "" var ruleList = bookListRule.bookList ?: ""
if (ruleList.startsWith("-")) { if (ruleList.startsWith("-")) {
reverse = true reverse = true
ruleList = ruleList.substring(1) ruleList = ruleList.substring(1)
} }
if (ruleList.startsWith(":")) {
ruleList = ruleList.substring(1)
}
if (ruleList.startsWith("+")) {
allInOne = true
ruleList = ruleList.substring(1)
}
collections = analyzer.getElements(ruleList) collections = analyzer.getElements(ruleList)
if (collections.isEmpty() && bookSource.bookUrlPattern.isNullOrEmpty()) { if (collections.isEmpty() && bookSource.bookUrlPattern.isNullOrEmpty()) {
getInfoItem(analyzer, bookSource, baseUrl)?.let { searchBook -> getInfoItem(analyzer, bookSource, baseUrl)?.let { searchBook ->
@ -63,23 +54,12 @@ object BookList {
bookList.add(searchBook) bookList.add(searchBook)
} }
} else { } else {
if (allInOne) { for (item in collections) {
for (item in collections) { getSearchItem(item, analyzer, bookListRule, bookSource, baseUrl)?.let { searchBook ->
getAllInOneItem(item, analyzer, bookListRule, bookSource, baseUrl)?.let { searchBook -> if (baseUrl == searchBook.bookUrl) {
if (baseUrl == searchBook.bookUrl) { searchBook.bookInfoHtml = body
searchBook.bookInfoHtml = body
}
bookList.add(searchBook)
}
}
} else {
for (item in collections) {
getSearchItem(item, analyzer, bookListRule, bookSource, baseUrl)?.let { searchBook ->
if (baseUrl == searchBook.bookUrl) {
searchBook.bookInfoHtml = body
}
bookList.add(searchBook)
} }
bookList.add(searchBook)
} }
} }
if (reverse) { if (reverse) {
@ -114,29 +94,6 @@ object BookList {
return null 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( private fun getSearchItem(
item: Any, item: Any,
analyzeRule: AnalyzeRule, analyzeRule: AnalyzeRule,

Loading…
Cancel
Save