修复自动换源的bug

pull/370/head
gedoor 4 years ago
parent 1c855d4f4a
commit ab2512e7e8
  1. 15
      app/src/main/java/io/legado/app/data/entities/Book.kt
  2. 13
      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

@ -158,4 +158,19 @@ data class Book(
} }
App.db.bookDao().delete(this) 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) { override fun changeTo(searchBook: SearchBook) {
val book = searchBook.toBook() val book = searchBook.toBook()
callBack?.oldBook?.let { oldBook -> book.upInfoFromOld(callBack?.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) callBack?.changeTo(book)
}
dismiss() dismiss()
} }

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

Loading…
Cancel
Save