pull/2143/head
kunfei 2 years ago
parent 5110ff8473
commit ee3777e511
  1. 5
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt

@ -298,7 +298,7 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
waitDialog.setText(R.string.load_toc) waitDialog.setText(R.string.load_toc)
waitDialog.show() waitDialog.show()
val book = searchBook.toBook() val book = searchBook.toBook()
viewModel.getToc(book, { val coroutine = viewModel.getToc(book, {
waitDialog.dismiss() waitDialog.dismiss()
toastOnUi(it) toastOnUi(it)
}) { toc, source -> }) { toc, source ->
@ -306,6 +306,9 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
callBack?.changeTo(source, book, toc) callBack?.changeTo(source, book, toc)
onSuccess?.invoke() onSuccess?.invoke()
} }
waitDialog.setOnCancelListener {
coroutine.cancel()
}
} }
/** /**

@ -275,8 +275,8 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
book: Book, book: Book,
onError: (msg: String) -> Unit, onError: (msg: String) -> Unit,
onSuccess: (toc: List<BookChapter>, source: BookSource) -> Unit onSuccess: (toc: List<BookChapter>, source: BookSource) -> Unit
) { ): Coroutine<Pair<List<BookChapter>, BookSource>> {
execute { return execute {
val toc = tocMap[book.bookUrl] val toc = tocMap[book.bookUrl]
if (toc != null) { if (toc != null) {
val source = appDb.bookSourceDao.getBookSource(book.origin) val source = appDb.bookSourceDao.getBookSource(book.origin)

Loading…
Cancel
Save