From 2f41e23d68636ae25951315a3ded71ec27c81d71 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 11 Jul 2019 23:12:52 +0800 Subject: [PATCH] up --- app/build.gradle | 2 +- .../io/legado/app/data/entities/BookSource.kt | 55 ++++++++++++++++--- .../main/java/io/legado/app/model/WebBook.kt | 9 +-- .../io/legado/app/model/webbook/BookList.kt | 4 +- build.gradle | 4 +- 5 files changed, 59 insertions(+), 15 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c15bcc12f..0a9e9b726 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -83,7 +83,7 @@ dependencies { implementation 'androidx.appcompat:appcompat:1.1.0-rc01' implementation 'androidx.preference:preference:1.1.0-rc01' 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' //lifecycle diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index 6e52d5570..eaf37c9be 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -2,6 +2,7 @@ package io.legado.app.data.entities import android.os.Parcelable import androidx.room.Entity +import androidx.room.Ignore import androidx.room.Index import androidx.room.PrimaryKey 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.fromJsonObject import io.legado.app.utils.getPrefString +import kotlinx.android.parcel.IgnoredOnParcel import kotlinx.android.parcel.Parcelize import java.util.* @@ -37,6 +39,25 @@ data class BookSource( var ruleToc: String? = null, // 目录页规则 var ruleContent: String? = null // 正文页规则 ) : 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 { val headerMap = HashMap() @@ -50,23 +71,43 @@ data class BookSource( } - fun getSearchRule(): SearchRule? { - return GSON.fromJsonObject(ruleSearch) + fun getSearchRule(): SearchRule { + searchRuleV?:let { + searchRuleV = GSON.fromJsonObject(ruleSearch) + searchRuleV?:let { searchRuleV = SearchRule() } + } + return searchRuleV!! } - fun getExploreRule(): ExploreRule? { - return GSON.fromJsonObject(ruleExplore) + fun getExploreRule(): ExploreRule { + exploreRuleV?:let { + exploreRuleV = GSON.fromJsonObject(ruleExplore) + exploreRuleV?:let { exploreRuleV = ExploreRule() } + } + return exploreRuleV!! } fun getBookInfoRule(): BookInfoRule? { - return GSON.fromJsonObject(ruleBookInfo) + bookInfoRuleV?:let { + bookInfoRuleV = GSON.fromJsonObject(ruleBookInfo) + bookInfoRuleV?:let { bookInfoRuleV = BookInfoRule() } + } + return bookInfoRuleV!! } fun getTocRule(): TocRule? { - return GSON.fromJsonObject(ruleToc) + tocRuleV?:let { + tocRuleV = GSON.fromJsonObject(ruleToc) + tocRuleV?:let { tocRuleV = TocRule() } + } + return tocRuleV!! } fun getContentRule(): ContentRule? { - return GSON.fromJsonObject(ruleContent) + contentRuleV?:let { + contentRuleV = GSON.fromJsonObject(ruleContent) + contentRuleV?:let { contentRuleV = ContentRule() } + } + return contentRuleV!! } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/model/WebBook.kt b/app/src/main/java/io/legado/app/model/WebBook.kt index 6af5d455d..adcdba288 100644 --- a/app/src/main/java/io/legado/app/model/WebBook.kt +++ b/app/src/main/java/io/legado/app/model/WebBook.kt @@ -3,8 +3,10 @@ package io.legado.app.model import io.legado.app.data.api.IHttpGetApi import io.legado.app.data.api.IHttpPostApi 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.model.analyzeRule.AnalyzeUrl +import io.legado.app.model.webbook.BookList import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers.IO 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)) { launch(IO) { - val searchRule = bookSource.getSearchRule() - searchRule?.searchUrl?.let { searchUrl -> + bookSource.getSearchRule().searchUrl?.let { searchUrl -> val analyzeUrl = AnalyzeUrl(searchUrl) - val res = when { + val response = when { analyzeUrl.method == AnalyzeUrl.Method.POST -> HttpHelper.getApiService( analyzeUrl.baseUrl ).postBody( @@ -31,7 +32,7 @@ class WebBook(val bookSource: BookSource) : CoroutineScope by MainScope() { else -> HttpHelper.getApiService(analyzeUrl.baseUrl) .getMap(analyzeUrl.url, analyzeUrl.fieldMap, analyzeUrl.headerMap).await() } - + val bookList = BookList().analyzeBookList(response, bookSource) } } diff --git a/app/src/main/java/io/legado/app/model/webbook/BookList.kt b/app/src/main/java/io/legado/app/model/webbook/BookList.kt index 0fc7bae82..d399e2386 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookList.kt +++ b/app/src/main/java/io/legado/app/model/webbook/BookList.kt @@ -1,10 +1,12 @@ package io.legado.app.model.webbook +import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.SearchBook +import retrofit2.Response class BookList { - fun analyzeBookList(): ArrayList { + fun analyzeBookList(response: Response, bookSource: BookSource): ArrayList { var bookList = ArrayList() return bookList diff --git a/build.gradle b/build.gradle index dededb69b..4dfd23870 100644 --- a/build.gradle +++ b/build.gradle @@ -1,14 +1,14 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.31' + ext.kotlin_version = '1.3.41' repositories { google() jcenter() maven { url 'https://maven.fabric.io/public' } } 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" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files