pull/32/head
kunfei 5 years ago
parent d224a54e25
commit 1f00a3dac9
  1. 4
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceDialog.kt
  2. 10
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt
  3. 8
      app/src/main/res/layout/dialog_change_source.xml

@ -141,6 +141,10 @@ class ChangeSourceDialog : DialogFragment(),
return changeSourceAdapter return changeSourceAdapter
} }
override fun upSearchState(isSearch: Boolean) {
refresh_progress_bar.isAutoLoading = isSearch
}
interface CallBack { interface CallBack {
fun curOrigin(): String? fun curOrigin(): String?
fun oldBook(): Book? fun oldBook(): Book?

@ -7,6 +7,7 @@ import io.legado.app.R
import io.legado.app.base.BaseViewModel import io.legado.app.base.BaseViewModel
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.SearchBook import io.legado.app.data.entities.SearchBook
import io.legado.app.help.coroutine.Coroutine
import io.legado.app.model.WebBook import io.legado.app.model.WebBook
import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main import kotlinx.coroutines.Dispatchers.Main
@ -18,6 +19,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
var callBack: CallBack? = null var callBack: CallBack? = null
var name: String = "" var name: String = ""
var author: String = "" var author: String = ""
private var task: Coroutine<*>? = null
private var screenKey: String = "" private var screenKey: String = ""
private val searchBooks = linkedSetOf<SearchBook>() private val searchBooks = linkedSetOf<SearchBook>()
@ -47,7 +49,8 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
} }
fun search() { fun search() {
execute { task = execute {
callBack?.upSearchState(true)
val bookSourceList = App.db.bookSourceDao().allEnabled val bookSourceList = App.db.bookSourceDao().allEnabled
for (item in bookSourceList) { for (item in bookSourceList) {
//task取消时自动取消 by (scope = this@execute) //task取消时自动取消 by (scope = this@execute)
@ -68,6 +71,10 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
delay(100) delay(100)
} }
} }
task?.invokeOnCompletion {
callBack?.upSearchState(false)
}
} }
private fun loadBookInfo(book: Book) { private fun loadBookInfo(book: Book) {
@ -118,5 +125,6 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
interface CallBack { interface CallBack {
fun adapter(): ChangeSourceAdapter fun adapter(): ChangeSourceAdapter
fun upSearchState(isSearch: Boolean)
} }
} }

@ -15,11 +15,17 @@
app:fitStatusBar="false" app:fitStatusBar="false"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<io.legado.app.ui.widget.anima.RefreshProgressBar
android:id="@+id/refresh_progress_bar"
android:layout_width="match_parent"
android:layout_height="2dp"
app:layout_constraintTop_toBottomOf="@+id/tool_bar" />
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view" android:id="@+id/recycler_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="0dp" android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/tool_bar" app:layout_constraintTop_toBottomOf="@+id/refresh_progress_bar"
app:layout_constraintBottom_toBottomOf="parent" /> app:layout_constraintBottom_toBottomOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save