From 6e632bf7e3ada1beb15547529dd70385ebdb76a5 Mon Sep 17 00:00:00 2001 From: 821938089 <821938089@qq.com> Date: Sun, 10 Jul 2022 20:01:37 +0800 Subject: [PATCH] fix bookimport bug --- .../java/io/legado/app/ui/book/cache/CacheViewModel.kt | 2 +- .../io/legado/app/ui/book/local/ImportBookActivity.kt | 8 ++++---- .../io/legado/app/ui/book/local/ImportBookViewModel.kt | 4 ++++ 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt index 7b66ff6c7..ecd5bb2bf 100644 --- a/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/cache/CacheViewModel.kt @@ -102,7 +102,7 @@ class CacheViewModel(application: Application) : BaseViewModel(application) { val filename = "${getExportFileName(book)}.txt" DocumentUtils.delete(doc, filename) val bookDoc = DocumentUtils.createFileIfNotExist(doc, filename) - ?: throw NoStackTraceException("创建文档失败") + ?: throw NoStackTraceException("创建文档失败,请尝试重新设置导出文件夹") val stringBuilder = StringBuilder() context.contentResolver.openOutputStream(bookDoc.uri, "wa")?.use { bookOs -> getAllContents(scope, book) { text, srcList -> diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt index 36b99b963..4d40184bb 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookActivity.kt @@ -48,10 +48,10 @@ class ImportBookActivity : VMBaseActivity if (uri.isContentScheme()) { AppConfig.importBookPath = uri.toString() - initRootDoc() + initRootDoc(true) } else { AppConfig.importBookPath = uri.path - initRootDoc() + initRootDoc(true) } } } @@ -146,10 +146,10 @@ class ImportBookActivity : VMBaseActivity upPath() + viewModel.rootDoc != null && !changedFolder -> upPath() lastPath.isNullOrEmpty() -> { binding.tvEmptyMsg.visible() selectFolder.launch() diff --git a/app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt index 1c84412d0..c4f760850 100644 --- a/app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/local/ImportBookViewModel.kt @@ -4,6 +4,7 @@ import android.app.Application import android.net.Uri import androidx.documentfile.provider.DocumentFile import io.legado.app.base.BaseViewModel +import io.legado.app.constant.AppLog import io.legado.app.constant.AppPattern.bookFileRegex import io.legado.app.constant.PreferKey import io.legado.app.model.localBook.LocalBook @@ -76,6 +77,9 @@ class ImportBookViewModel(application: Application) : BaseViewModel(application) uriList.forEach { LocalBook.importFile(Uri.parse(it)) } + }.onError { + context.toastOnUi("添加书架失败,请尝试重新选择文件夹") + AppLog.put("添加书架失败\n${it.localizedMessage}", it) }.onFinally { finally.invoke() }