From 1f00a3dac94b0dee0dba34b54112ccfe2a21dca6 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 10 Sep 2019 14:24:06 +0800 Subject: [PATCH] up --- .../legado/app/ui/changesource/ChangeSourceDialog.kt | 4 ++++ .../app/ui/changesource/ChangeSourceViewModel.kt | 10 +++++++++- app/src/main/res/layout/dialog_change_source.xml | 8 +++++++- 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt index dcb1398cd..f5a1a6699 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt @@ -141,6 +141,10 @@ class ChangeSourceDialog : DialogFragment(), return changeSourceAdapter } + override fun upSearchState(isSearch: Boolean) { + refresh_progress_bar.isAutoLoading = isSearch + } + interface CallBack { fun curOrigin(): String? fun oldBook(): Book? diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index 5d7410b5b..3839bebef 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -7,6 +7,7 @@ import io.legado.app.R import io.legado.app.base.BaseViewModel import io.legado.app.data.entities.Book import io.legado.app.data.entities.SearchBook +import io.legado.app.help.coroutine.Coroutine import io.legado.app.model.WebBook import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main @@ -18,6 +19,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio var callBack: CallBack? = null var name: String = "" var author: String = "" + private var task: Coroutine<*>? = null private var screenKey: String = "" private val searchBooks = linkedSetOf() @@ -47,7 +49,8 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio } fun search() { - execute { + task = execute { + callBack?.upSearchState(true) val bookSourceList = App.db.bookSourceDao().allEnabled for (item in bookSourceList) { //task取消时自动取消 by (scope = this@execute) @@ -68,6 +71,10 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio delay(100) } } + + task?.invokeOnCompletion { + callBack?.upSearchState(false) + } } private fun loadBookInfo(book: Book) { @@ -118,5 +125,6 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio interface CallBack { fun adapter(): ChangeSourceAdapter + fun upSearchState(isSearch: Boolean) } } \ No newline at end of file diff --git a/app/src/main/res/layout/dialog_change_source.xml b/app/src/main/res/layout/dialog_change_source.xml index 5d96cbdf8..21683d69d 100644 --- a/app/src/main/res/layout/dialog_change_source.xml +++ b/app/src/main/res/layout/dialog_change_source.xml @@ -15,11 +15,17 @@ app:fitStatusBar="false" app:layout_constraintTop_toTopOf="parent" /> + + \ No newline at end of file