|
|
|
@ -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) { |
|
|
|
|