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) {
kotlin.runCatching {
if (book.isTxt()) {
val bookFile =
FileUtils.getFile(AnalyzeTxtFile.cacheFolder, book.originName, subDirs = *arrayOf())
val bookFile = FileUtils.getFile(AnalyzeTxtFile.cacheFolder, book.originName)
bookFile.delete()
}
@ -41,4 +41,5 @@ object LocalBook {
DocumentFile.fromSingleUri(App.INSTANCE, uri)?.delete()
}
}
}
}

@ -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()
}

Loading…
Cancel
Save