feat: 优化代码

pull/133/head
kunfei 5 years ago
parent d578e0e958
commit eecd276b4a
  1. 17
      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,15 +30,16 @@ object LocalBook {
} }
fun deleteBook(book: Book, deleteOriginal: Boolean) { fun deleteBook(book: Book, deleteOriginal: Boolean) {
if (book.isTxt()) { kotlin.runCatching {
val bookFile = if (book.isTxt()) {
FileUtils.getFile(AnalyzeTxtFile.cacheFolder, book.originName, subDirs = *arrayOf()) val bookFile = FileUtils.getFile(AnalyzeTxtFile.cacheFolder, book.originName)
bookFile.delete() bookFile.delete()
} }
if (deleteOriginal) { if (deleteOriginal) {
val uri = Uri.parse(book.bookUrl) val uri = Uri.parse(book.bookUrl)
DocumentFile.fromSingleUri(App.INSTANCE, uri)?.delete() DocumentFile.fromSingleUri(App.INSTANCE, uri)?.delete()
}
} }
} }
} }

@ -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