pull/32/head
kunfei 5 years ago
parent ef3f7f770c
commit 2f41e23d68
  1. 2
      app/build.gradle
  2. 55
      app/src/main/java/io/legado/app/data/entities/BookSource.kt
  3. 9
      app/src/main/java/io/legado/app/model/WebBook.kt
  4. 4
      app/src/main/java/io/legado/app/model/webbook/BookList.kt
  5. 4
      build.gradle

@ -83,7 +83,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0-rc01' implementation 'androidx.appcompat:appcompat:1.1.0-rc01'
implementation 'androidx.preference:preference:1.1.0-rc01' implementation 'androidx.preference:preference:1.1.0-rc01'
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta1' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta1'
implementation 'com.google.android.material:material:1.1.0-alpha07' implementation 'com.google.android.material:material:1.1.0-alpha08'
implementation 'com.google.android:flexbox:1.1.0' implementation 'com.google.android:flexbox:1.1.0'
//lifecycle //lifecycle

@ -2,6 +2,7 @@ package io.legado.app.data.entities
import android.os.Parcelable import android.os.Parcelable
import androidx.room.Entity import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.Index import androidx.room.Index
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
import io.legado.app.App import io.legado.app.App
@ -10,6 +11,7 @@ import io.legado.app.data.entities.rule.*
import io.legado.app.utils.GSON import io.legado.app.utils.GSON
import io.legado.app.utils.fromJsonObject import io.legado.app.utils.fromJsonObject
import io.legado.app.utils.getPrefString import io.legado.app.utils.getPrefString
import kotlinx.android.parcel.IgnoredOnParcel
import kotlinx.android.parcel.Parcelize import kotlinx.android.parcel.Parcelize
import java.util.* import java.util.*
@ -37,6 +39,25 @@ data class BookSource(
var ruleToc: String? = null, // 目录页规则 var ruleToc: String? = null, // 目录页规则
var ruleContent: String? = null // 正文页规则 var ruleContent: String? = null // 正文页规则
) : Parcelable { ) : Parcelable {
@Ignore
@IgnoredOnParcel
var searchRuleV:SearchRule? = null
@Ignore
@IgnoredOnParcel
var exploreRuleV:ExploreRule? = null
@Ignore
@IgnoredOnParcel
var bookInfoRuleV:BookInfoRule? = null
@Ignore
@IgnoredOnParcel
var tocRuleV:TocRule? = null
@Ignore
@IgnoredOnParcel
var contentRuleV:ContentRule? = null
fun getHeaderMap(): Map<String, String> { fun getHeaderMap(): Map<String, String> {
val headerMap = HashMap<String, String>() val headerMap = HashMap<String, String>()
@ -50,23 +71,43 @@ data class BookSource(
} }
fun getSearchRule(): SearchRule? { fun getSearchRule(): SearchRule {
return GSON.fromJsonObject<SearchRule>(ruleSearch) searchRuleV?:let {
searchRuleV = GSON.fromJsonObject<SearchRule>(ruleSearch)
searchRuleV?:let { searchRuleV = SearchRule() }
}
return searchRuleV!!
} }
fun getExploreRule(): ExploreRule? { fun getExploreRule(): ExploreRule {
return GSON.fromJsonObject<ExploreRule>(ruleExplore) exploreRuleV?:let {
exploreRuleV = GSON.fromJsonObject<ExploreRule>(ruleExplore)
exploreRuleV?:let { exploreRuleV = ExploreRule() }
}
return exploreRuleV!!
} }
fun getBookInfoRule(): BookInfoRule? { fun getBookInfoRule(): BookInfoRule? {
return GSON.fromJsonObject<BookInfoRule>(ruleBookInfo) bookInfoRuleV?:let {
bookInfoRuleV = GSON.fromJsonObject<BookInfoRule>(ruleBookInfo)
bookInfoRuleV?:let { bookInfoRuleV = BookInfoRule() }
}
return bookInfoRuleV!!
} }
fun getTocRule(): TocRule? { fun getTocRule(): TocRule? {
return GSON.fromJsonObject<TocRule>(ruleToc) tocRuleV?:let {
tocRuleV = GSON.fromJsonObject<TocRule>(ruleToc)
tocRuleV?:let { tocRuleV = TocRule() }
}
return tocRuleV!!
} }
fun getContentRule(): ContentRule? { fun getContentRule(): ContentRule? {
return GSON.fromJsonObject<ContentRule>(ruleContent) contentRuleV?:let {
contentRuleV = GSON.fromJsonObject<ContentRule>(ruleContent)
contentRuleV?:let { contentRuleV = ContentRule() }
}
return contentRuleV!!
} }
} }

@ -3,8 +3,10 @@ package io.legado.app.model
import io.legado.app.data.api.IHttpGetApi import io.legado.app.data.api.IHttpGetApi
import io.legado.app.data.api.IHttpPostApi import io.legado.app.data.api.IHttpPostApi
import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.SearchBook
import io.legado.app.help.http.HttpHelper import io.legado.app.help.http.HttpHelper
import io.legado.app.model.analyzeRule.AnalyzeUrl import io.legado.app.model.analyzeRule.AnalyzeUrl
import io.legado.app.model.webbook.BookList
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.MainScope import kotlinx.coroutines.MainScope
@ -14,10 +16,9 @@ class WebBook(val bookSource: BookSource) : CoroutineScope by MainScope() {
fun searchBook(key: String, page: Int?, success: (() -> Unit), error: (() -> Unit)) { fun searchBook(key: String, page: Int?, success: (() -> Unit), error: (() -> Unit)) {
launch(IO) { launch(IO) {
val searchRule = bookSource.getSearchRule() bookSource.getSearchRule().searchUrl?.let { searchUrl ->
searchRule?.searchUrl?.let { searchUrl ->
val analyzeUrl = AnalyzeUrl(searchUrl) val analyzeUrl = AnalyzeUrl(searchUrl)
val res = when { val response = when {
analyzeUrl.method == AnalyzeUrl.Method.POST -> HttpHelper.getApiService<IHttpPostApi>( analyzeUrl.method == AnalyzeUrl.Method.POST -> HttpHelper.getApiService<IHttpPostApi>(
analyzeUrl.baseUrl analyzeUrl.baseUrl
).postBody( ).postBody(
@ -31,7 +32,7 @@ class WebBook(val bookSource: BookSource) : CoroutineScope by MainScope() {
else -> HttpHelper.getApiService<IHttpGetApi>(analyzeUrl.baseUrl) else -> HttpHelper.getApiService<IHttpGetApi>(analyzeUrl.baseUrl)
.getMap(analyzeUrl.url, analyzeUrl.fieldMap, analyzeUrl.headerMap).await() .getMap(analyzeUrl.url, analyzeUrl.fieldMap, analyzeUrl.headerMap).await()
} }
val bookList = BookList().analyzeBookList(response, bookSource)
} }
} }

@ -1,10 +1,12 @@
package io.legado.app.model.webbook package io.legado.app.model.webbook
import io.legado.app.data.entities.BookSource
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import retrofit2.Response
class BookList { class BookList {
fun analyzeBookList(): ArrayList<SearchBook> { fun analyzeBookList(response: Response<String>, bookSource: BookSource): ArrayList<SearchBook> {
var bookList = ArrayList<SearchBook>() var bookList = ArrayList<SearchBook>()
return bookList return bookList

@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript { buildscript {
ext.kotlin_version = '1.3.31' ext.kotlin_version = '1.3.41'
repositories { repositories {
google() google()
jcenter() jcenter()
maven { url 'https://maven.fabric.io/public' } maven { url 'https://maven.fabric.io/public' }
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:3.4.1' classpath 'com.android.tools.build:gradle:3.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // in the individual module build.gradle files

Loading…
Cancel
Save