From 4ac1c916c159e4939955bfe9f25ba0a60fc9ca50 Mon Sep 17 00:00:00 2001 From: Xwite <1797350009@qq.com> Date: Sun, 15 May 2022 08:12:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=B8=8B=E8=BD=BD=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=97=B6=E6=B7=BB=E5=8A=A0=E4=B9=A6=E6=BA=90=E7=9A=84=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=A4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/ui/association/ImportOnLineBookFileViewModel.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/association/ImportOnLineBookFileViewModel.kt b/app/src/main/java/io/legado/app/ui/association/ImportOnLineBookFileViewModel.kt index bfa3370e9..3ece288ad 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportOnLineBookFileViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportOnLineBookFileViewModel.kt @@ -10,6 +10,7 @@ import io.legado.app.constant.AppLog import io.legado.app.constant.EventBus import io.legado.app.data.appDb import io.legado.app.data.entities.Book +import io.legado.app.data.entities.BookSource import io.legado.app.exception.NoStackTraceException import io.legado.app.model.analyzeRule.AnalyzeRule import io.legado.app.model.analyzeRule.AnalyzeUrl @@ -22,13 +23,14 @@ class ImportOnLineBookFileViewModel(app: Application) : BaseViewModel(app) { val errorLiveData = MutableLiveData() val successLiveData = MutableLiveData() val savedFileUriData = MutableLiveData() + var bookSource: BookSource? = null fun initData(bookUrl: String?) { execute { bookUrl ?: throw NoStackTraceException("书籍详情页链接为空") val book = appDb.searchBookDao.getSearchBook(bookUrl)?.toBook() ?: throw NoStackTraceException("book is null") - val bookSource = appDb.bookSourceDao.getBookSource(book.origin) + bookSource = appDb.bookSourceDao.getBookSource(book.origin) ?: throw NoStackTraceException("bookSource is null") val ruleDownloadUrls = bookSource?.getBookInfoRule()?.downloadUrls val content = AnalyzeUrl(bookUrl, source = bookSource).getStrResponse().body @@ -53,7 +55,7 @@ class ImportOnLineBookFileViewModel(app: Application) : BaseViewModel(app) { fun downloadUrl(url: String, fileName: String, success: () -> Unit) { execute { - LocalBook.saveBookFile(url, fileName).let { + LocalBook.saveBookFile(url, fileName, bookSource).let { savedFileUriData.postValue(it) } }.onSuccess { @@ -65,7 +67,7 @@ class ImportOnLineBookFileViewModel(app: Application) : BaseViewModel(app) { fun importOnLineBookFile(url: String, fileName: String, success: () -> Unit) { execute { - LocalBook.importFileOnLine(url, fileName).let { + LocalBook.importFileOnLine(url, fileName, bookSource).let { postEvent(EventBus.BOOK_URL_CHANGED, it.bookUrl) } }.onSuccess {