feat: 优化代码

pull/133/head
kunfei 5 years ago
parent d578e0e958
commit eecd276b4a
  1. 5
      app/src/main/java/io/legado/app/model/localBook/LocalBook.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt

@ -30,9 +30,9 @@ object LocalBook {
} }
fun deleteBook(book: Book, deleteOriginal: Boolean) { fun deleteBook(book: Book, deleteOriginal: Boolean) {
kotlin.runCatching {
if (book.isTxt()) { if (book.isTxt()) {
val bookFile = val bookFile = FileUtils.getFile(AnalyzeTxtFile.cacheFolder, book.originName)
FileUtils.getFile(AnalyzeTxtFile.cacheFolder, book.originName, subDirs = *arrayOf())
bookFile.delete() bookFile.delete()
} }
@ -42,3 +42,4 @@ object LocalBook {
} }
} }
} }
}

@ -202,12 +202,12 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
fun delBook(deleteOriginal: Boolean = false, success: (() -> Unit)? = null) { fun delBook(deleteOriginal: Boolean = false, success: (() -> Unit)? = null) {
execute { execute {
bookData.value?.let { bookData.value?.let {
App.db.bookDao().delete(it)
inBookshelf = false
if (it.isLocalBook()) { if (it.isLocalBook()) {
LocalBook.deleteBook(it, deleteOriginal) LocalBook.deleteBook(it, deleteOriginal)
} }
App.db.bookDao().delete(it)
} }
inBookshelf = false
}.onSuccess { }.onSuccess {
success?.invoke() success?.invoke()
} }

Loading…
Cancel
Save