edit ChangeCoverViewModel.kt

pull/849/head
gedoor 4 years ago
parent 74f0c61067
commit fa727896de
  1. 24
      app/src/main/java/io/legado/app/ui/book/changecover/ChangeCoverViewModel.kt

@ -90,13 +90,17 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application
}
}
@Synchronized
private fun search() {
synchronized(this) {
if (searchIndex >= bookSourceList.lastIndex) {
return
}
searchIndex++
val source = bookSourceList[searchIndex]
if (source.getSearchRule().coverUrl.isNullOrBlank()) {
searchNext()
return
}
val task = WebBook(source)
.searchBook(this, name, context = searchPool!!)
.timeout(60000L)
@ -115,22 +119,26 @@ class ChangeCoverViewModel(application: Application) : BaseViewModel(application
}
}
.onFinally {
synchronized(this) {
searchNext()
}
tasks.add(task)
}
@Synchronized
private fun searchNext() {
if (searchIndex < bookSourceList.lastIndex) {
search()
} else {
searchIndex++
}
if (searchIndex >= bookSourceList.lastIndex + min(bookSourceList.size,
threadCount)
if (searchIndex >= bookSourceList.lastIndex + min(
bookSourceList.size,
threadCount
)
) {
searchStateData.postValue(false)
}
}
}
tasks.add(task)
}
}
fun stopSearch() {
if (tasks.isEmpty) {

Loading…
Cancel
Save