Skip to content

Commit

Permalink
优化
Browse files Browse the repository at this point in the history
  • Loading branch information
821938089 committed Mar 17, 2024
1 parent 15258ab commit 8cd9610
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 8cd9610

Please sign in to comment.