From 585c19f7a729a113a7a65ebac83d36a982f13f16 Mon Sep 17 00:00:00 2001 From: kunfei Date: Sat, 17 Aug 2019 21:04:06 +0800 Subject: [PATCH] up --- .../app/model/webbook/BookChapterList.kt | 2 +- .../legado/app/model/webbook/BookContent.kt | 2 +- .../io/legado/app/model/webbook/BookInfo.kt | 2 +- .../io/legado/app/model/webbook/BookList.kt | 2 +- .../app/ui/bookinfo/BookInfoActivity.kt | 12 ++++++- .../app/ui/bookinfo/BookInfoViewModel.kt | 27 +++++++++++++--- .../app/ui/readbook/ReadBookViewModel.kt | 4 +-- app/src/main/res/values/strings.xml | 32 ++++++++++++------- 8 files changed, 60 insertions(+), 23 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt b/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt index c387008a7..03e29ea95 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt +++ b/app/src/main/java/io/legado/app/model/webbook/BookChapterList.kt @@ -28,7 +28,7 @@ object BookChapterList { val body: String? = response.body() body ?: throw Exception( App.INSTANCE.getString( - R.string.get_web_content_error, + R.string.error_get_web_content, baseUrl ) ) diff --git a/app/src/main/java/io/legado/app/model/webbook/BookContent.kt b/app/src/main/java/io/legado/app/model/webbook/BookContent.kt index 0b77b10a4..bfa7f76a3 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookContent.kt +++ b/app/src/main/java/io/legado/app/model/webbook/BookContent.kt @@ -29,7 +29,7 @@ object BookContent { val body: String? = response.body() body ?: throw Exception( App.INSTANCE.getString( - R.string.get_web_content_error, + R.string.error_get_web_content, baseUrl ) ) diff --git a/app/src/main/java/io/legado/app/model/webbook/BookInfo.kt b/app/src/main/java/io/legado/app/model/webbook/BookInfo.kt index d3d043a0b..05dfc0fc6 100644 --- a/app/src/main/java/io/legado/app/model/webbook/BookInfo.kt +++ b/app/src/main/java/io/legado/app/model/webbook/BookInfo.kt @@ -19,7 +19,7 @@ object BookInfo { val baseUrl = analyzeUrl.url body ?: throw Exception( App.INSTANCE.getString( - R.string.get_web_content_error, + R.string.error_get_web_content, baseUrl ) ) 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 b5af7027f..4ee99bb7c 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 @@ -24,7 +24,7 @@ object BookList { val body: String? = response.body() body ?: throw Exception( App.INSTANCE.getString( - R.string.get_web_content_error, + R.string.error_get_web_content, baseUrl ) ) diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt index f0e3215c8..058fbe950 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt @@ -12,6 +12,7 @@ import io.legado.app.data.entities.BookChapter import io.legado.app.help.ImageLoader import io.legado.app.ui.bookinfo.edit.BookInfoEditActivity import io.legado.app.ui.changesource.ChangeSourceDialog +import io.legado.app.ui.readbook.ReadBookActivity import io.legado.app.utils.getViewModel import io.legado.app.utils.gone import io.legado.app.utils.visible @@ -105,6 +106,7 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo } private fun showChapter(chapterList: List) { + adapter.clearItems() adapter.addItems(chapterList) } @@ -130,7 +132,15 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo private fun initOnClick() { tv_read.onClick { - + viewModel.bookData.value?.let { + if (!viewModel.inBookshelf) { + viewModel.saveBook { + startActivity(Pair("bookUrl", it.bookUrl)) + } + } else { + startActivity(Pair("bookUrl", it.bookUrl)) + } + } } tv_shelf.onClick { viewModel.saveBook { diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt index 7efde2b00..8958c84d1 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt @@ -4,9 +4,12 @@ import android.app.Application import android.content.Intent import androidx.lifecycle.MutableLiveData import io.legado.app.App +import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter +import io.legado.app.model.WebBook +import kotlinx.coroutines.Dispatchers.IO class BookInfoViewModel(application: Application) : BaseViewModel(application) { @@ -32,7 +35,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { App.db.searchBookDao().getSearchBook(it)?.toBook()?.let { book -> bookData.postValue(book) if (book.tocUrl.isEmpty()) { - loadBookInfo() + loadBookInfo(book) } else { loadChapter(book) } @@ -41,15 +44,31 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { } } - fun loadBookInfo() { + fun loadBookInfo(book: Book) { isLoadingData.postValue(false) + App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> + WebBook(bookSource).getBookInfo(book) + .onSuccess { + it?.let { loadChapter(it) } + }.onError { + toast(R.string.error_get_book_info) + } + } ?: toast(R.string.error_no_source) } fun loadChapter(book: Book) { isLoadingData.postValue(false) - App.db.bookSourceDao().getBookSource(book.origin)?.let { + App.db.bookSourceDao().getBookSource(book.origin)?.let { bookSource -> + WebBook(bookSource).getChapterList(book) + .onSuccess(IO) { + if (inBookshelf) { - } + } + chapterListData.postValue(it) + }.onError { + toast(R.string.error_get_chapter_list) + } + } ?: toast(R.string.error_no_source) } fun saveBook(success: (() -> Unit)?) { diff --git a/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt index a19467341..7ed316cfc 100644 --- a/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/readbook/ReadBookViewModel.kt @@ -53,10 +53,10 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { App.db.bookChapterDao().insert(*cList.toTypedArray()) chapterMaxIndex.postValue(cList.size) } else { - toast(R.string.load_toc_error) + toast(R.string.error_load_toc) } }?.onError { - toast(R.string.load_toc_error) + toast(R.string.error_load_toc) } ?: autoChangeSource() } else { chapterMaxIndex.postValue(count) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 51172e3ed..8a70911dd 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -59,9 +59,6 @@ 版本 本地 搜索 - 没有网络 - 网络连接超时 - 数据解析失败 来源: %s 最近: %s 书名 @@ -69,7 +66,6 @@ 是否将《%s》放入书架? 共%s个Text文件 加载中… - 获取数据失败! 重试 web服务 web编辑书源 @@ -142,7 +138,6 @@ 背景 作者 作者:%s - 站点暂时不支持解析,请反馈 朗读停止 清除缓存 保存 @@ -347,6 +342,7 @@ 成功 当前源没有配置登陆地址 + 书源名称(bookSourceName) 书源URL(bookSourceUrl) 书源分组(bookSourceGroup) @@ -371,6 +367,23 @@ 章节URL规则(chapterUrl) 正文规则(content) 正文下一页URL规则(nextContentUrl) + + + + 没有书源 + 书籍信息获取失败 + 内容获取失败 + 目录获取失败 + 访问网站失败:%s + 文件读取失败 + 加载目录失败 + 获取数据失败! + 加载失败\n%s + 没有网络 + 网络连接超时 + 数据解析失败 + + header 调试书源 二维码导入 @@ -382,7 +395,6 @@ 默认主题 恢复主题为默认配色 加入QQ群 - 文件读取失败 获取背景图片需存储权限 输入书源网址 删除文件 @@ -408,10 +420,6 @@ 输入编码 TXT目录规则 打开外部书籍需获取存储权限 - 书籍信息获取失败 - 内容获取失败 - 目录获取失败 - 访问网站失败:%s 未获取到书名 输入替换规则网址 搜索列表获取成功%d @@ -439,7 +447,6 @@ 文章内容为空 正在换源请等待… 目录列表为空 - 加载失败\n%s 正文边距 Tip边距 字距 @@ -474,5 +481,6 @@ ]]> 阅读 - 加载目录失败 + +