diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt index 06eb167a7..ee7410764 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt @@ -298,7 +298,7 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_ waitDialog.setText(R.string.load_toc) waitDialog.show() val book = searchBook.toBook() - viewModel.getToc(book, { + val coroutine = viewModel.getToc(book, { waitDialog.dismiss() toastOnUi(it) }) { toc, source -> @@ -306,6 +306,9 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_ callBack?.changeTo(source, book, toc) onSuccess?.invoke() } + waitDialog.setOnCancelListener { + coroutine.cancel() + } } /** diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt index 1aa7cca12..73e9fee69 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt @@ -275,8 +275,8 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a book: Book, onError: (msg: String) -> Unit, onSuccess: (toc: List, source: BookSource) -> Unit - ) { - execute { + ): Coroutine, BookSource>> { + return execute { val toc = tocMap[book.bookUrl] if (toc != null) { val source = appDb.bookSourceDao.getBookSource(book.origin)