diff --git a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt index c58410cd7..9a893b8a3 100644 --- a/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt +++ b/app/src/main/java/io/legado/app/model/localBook/LocalBook.kt @@ -30,15 +30,16 @@ object LocalBook { } fun deleteBook(book: Book, deleteOriginal: Boolean) { - if (book.isTxt()) { - val bookFile = - FileUtils.getFile(AnalyzeTxtFile.cacheFolder, book.originName, subDirs = *arrayOf()) - bookFile.delete() - } + kotlin.runCatching { + if (book.isTxt()) { + val bookFile = FileUtils.getFile(AnalyzeTxtFile.cacheFolder, book.originName) + bookFile.delete() + } - if (deleteOriginal) { - val uri = Uri.parse(book.bookUrl) - DocumentFile.fromSingleUri(App.INSTANCE, uri)?.delete() + if (deleteOriginal) { + val uri = Uri.parse(book.bookUrl) + DocumentFile.fromSingleUri(App.INSTANCE, uri)?.delete() + } } } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index 0364696a6..485d704ce 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -202,12 +202,12 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { fun delBook(deleteOriginal: Boolean = false, success: (() -> Unit)? = null) { execute { bookData.value?.let { + App.db.bookDao().delete(it) + inBookshelf = false if (it.isLocalBook()) { LocalBook.deleteBook(it, deleteOriginal) } - App.db.bookDao().delete(it) } - inBookshelf = false }.onSuccess { success?.invoke() }