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

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