修复自动换源的bug

pull/370/head
gedoor 4 years ago
parent 1c855d4f4a
commit ab2512e7e8
  1. 17
      app/src/main/java/io/legado/app/data/entities/Book.kt
  2. 15
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt
  3. 4
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt

@ -151,11 +151,26 @@ data class Book(
delete()
App.db.bookDao().insert(newBook)
}
fun delete() {
if (ReadBook.book?.bookUrl == bookUrl) {
ReadBook.book = null
}
App.db.bookDao().delete(this)
}
fun upInfoFromOld(oldBook: Book?) {
oldBook?.let {
group = oldBook.group
durChapterIndex = oldBook.durChapterIndex
durChapterPos = oldBook.durChapterPos
durChapterTitle = oldBook.durChapterTitle
customCoverUrl = oldBook.customCoverUrl
customIntro = oldBook.customIntro
order = oldBook.order
if (coverUrl.isNullOrEmpty()) {
coverUrl = oldBook.getDisplayCover()
}
}
}
}

@ -166,19 +166,8 @@ class ChangeSourceDialog : BaseDialogFragment(),
override fun changeTo(searchBook: SearchBook) {
val book = searchBook.toBook()
callBack?.oldBook?.let { oldBook ->
book.group = oldBook.group
book.durChapterIndex = oldBook.durChapterIndex
book.durChapterPos = oldBook.durChapterPos
book.durChapterTitle = oldBook.durChapterTitle
book.customCoverUrl = oldBook.customCoverUrl
book.customIntro = oldBook.customIntro
book.order = oldBook.order
if (book.coverUrl.isNullOrEmpty()) {
book.coverUrl = oldBook.getDisplayCover()
}
callBack?.changeTo(book)
}
book.upInfoFromOld(callBack?.oldBook)
callBack?.changeTo(book)
dismiss()
}

@ -188,7 +188,9 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
.searchBookSuspend(this, name, variableBook = variableBook)
.getOrNull(0)?.let {
if (it.name == name && (it.author == author || author == "")) {
changeTo(it.toBook())
val book = it.toBook()
book.upInfoFromOld(ReadBook.book)
changeTo(book)
return@execute
}
}

Loading…
Cancel
Save