From 13526640b8debba7b05dd26fbe9b537ddce35c60 Mon Sep 17 00:00:00 2001 From: kunfei Date: Fri, 12 Jul 2019 09:31:16 +0800 Subject: [PATCH] up --- .../main/java/io/legado/app/model/WebBook.kt | 11 +++++------ .../io/legado/app/model/webbook/BookList.kt | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 7 deletions(-) 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 adcdba288..34fd2caf8 100644 --- a/app/src/main/java/io/legado/app/model/WebBook.kt +++ b/app/src/main/java/io/legado/app/model/WebBook.kt @@ -4,18 +4,17 @@ 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.coroutine.Coroutine 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 -import kotlinx.coroutines.launch class WebBook(val bookSource: BookSource) : CoroutineScope by MainScope() { - fun searchBook(key: String, page: Int?, success: (() -> Unit), error: (() -> Unit)) { - launch(IO) { + fun searchBook(key: String, page: Int?): Coroutine> { + return Coroutine.with(this) { bookSource.getSearchRule().searchUrl?.let { searchUrl -> val analyzeUrl = AnalyzeUrl(searchUrl) val response = when { @@ -32,9 +31,9 @@ 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) + return@with BookList().analyzeBookList(response, bookSource, analyzeUrl) } - + ArrayList() } } 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 d399e2386..2078c93d2 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,13 +1,29 @@ package io.legado.app.model.webbook +import io.legado.app.App +import io.legado.app.R import io.legado.app.data.entities.BookSource import io.legado.app.data.entities.SearchBook +import io.legado.app.model.analyzeRule.AnalyzeUrl import retrofit2.Response class BookList { - fun analyzeBookList(response: Response, bookSource: BookSource): ArrayList { + @Throws(Exception::class) + fun analyzeBookList( + response: Response, + bookSource: BookSource, + analyzeUrl: AnalyzeUrl, + isSearch: Boolean = true + ): ArrayList { var bookList = ArrayList() + val body: String? = response.body() + body ?: throw Exception( + App.INSTANCE.getString( + R.string.get_web_content_error, + analyzeUrl.url + ) + ) return bookList }