This commit is contained in:
Horis 2024-03-17 17:08:34 +08:00
parent 15258abc09
commit 8cd9610992
3 changed files with 14 additions and 2 deletions

View File

@ -80,7 +80,7 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
val searchGroup = AppConfig.searchGroup
if (searchGroup.isNotEmpty()) {
lifecycleScope.launch {
alert("搜索结果为空") {
context?.alert("搜索结果为空") {
setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组")
cancelButton()
okButton {
@ -112,6 +112,11 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
viewModel.searchFinishCallback = searchFinishCallback
}
override fun onDestroy() {
super.onDestroy()
viewModel.searchFinishCallback = null
}
private fun showTitle() {
binding.toolBar.title = viewModel.name
binding.toolBar.subtitle = viewModel.author

View File

@ -31,6 +31,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.ensureActive
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.collect
@ -214,6 +215,7 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
}
}.onCompletion {
searchStateData.postValue(false)
ensureActive()
searchFinishCallback?.invoke(searchBooks.isEmpty())
}.catch {
AppLog.put("换源搜索出错\n${it.localizedMessage}", it)

View File

@ -89,7 +89,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
val searchGroup = AppConfig.searchGroup
if (searchGroup.isNotEmpty()) {
lifecycleScope.launch {
alert("搜索结果为空") {
context?.alert("搜索结果为空") {
setMessage("${searchGroup}分组搜索结果为空,是否切换到全部分组")
noButton()
yesButton {
@ -128,6 +128,11 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
}
}
override fun onDestroy() {
super.onDestroy()
viewModel.searchFinishCallback = null
}
private fun showTitle() {
binding.toolBar.title = viewModel.chapterTitle
}