|
@@ -28,6 +28,7 @@ class SearchModel(private val scope: CoroutineScope, private val callBack: CallB
|
|
|
private var tasks = CompositeCoroutine()
|
|
private var tasks = CompositeCoroutine()
|
|
|
private var bookSourceList = arrayListOf<BookSource>()
|
|
private var bookSourceList = arrayListOf<BookSource>()
|
|
|
private var searchBooks = arrayListOf<SearchBook>()
|
|
private var searchBooks = arrayListOf<SearchBook>()
|
|
|
|
|
+ private val emptyBookSource = BookSource()
|
|
|
|
|
|
|
|
@Volatile
|
|
@Volatile
|
|
|
private var searchIndex = -1
|
|
private var searchIndex = -1
|
|
@@ -76,6 +77,7 @@ class SearchModel(private val scope: CoroutineScope, private val callBack: CallB
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
searchIndex++
|
|
searchIndex++
|
|
|
|
|
+ val searchIndex = searchIndex
|
|
|
val source = bookSourceList[searchIndex]
|
|
val source = bookSourceList[searchIndex]
|
|
|
val searchPool = searchPool ?: return
|
|
val searchPool = searchPool ?: return
|
|
|
val task = WebBook.searchBook(
|
|
val task = WebBook.searchBook(
|
|
@@ -91,7 +93,7 @@ class SearchModel(private val scope: CoroutineScope, private val callBack: CallB
|
|
|
onSuccess(searchId, it)
|
|
onSuccess(searchId, it)
|
|
|
}
|
|
}
|
|
|
.onFinally {
|
|
.onFinally {
|
|
|
- onFinally(searchId)
|
|
|
|
|
|
|
+ onFinally(searchId, searchIndex)
|
|
|
}
|
|
}
|
|
|
tasks.add(task)
|
|
tasks.add(task)
|
|
|
}
|
|
}
|
|
@@ -107,12 +109,15 @@ class SearchModel(private val scope: CoroutineScope, private val callBack: CallB
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Synchronized
|
|
@Synchronized
|
|
|
- private fun onFinally(searchId: Long) {
|
|
|
|
|
|
|
+ private fun onFinally(searchId: Long, index: Int) {
|
|
|
if (searchIndex < bookSourceList.lastIndex) {
|
|
if (searchIndex < bookSourceList.lastIndex) {
|
|
|
search(searchId)
|
|
search(searchId)
|
|
|
} else {
|
|
} else {
|
|
|
searchIndex++
|
|
searchIndex++
|
|
|
}
|
|
}
|
|
|
|
|
+ if (index <= bookSourceList.lastIndex) {
|
|
|
|
|
+ bookSourceList[index] = emptyBookSource
|
|
|
|
|
+ }
|
|
|
if (searchIndex >= bookSourceList.lastIndex
|
|
if (searchIndex >= bookSourceList.lastIndex
|
|
|
+ min(bookSourceList.size, threadCount)
|
|
+ min(bookSourceList.size, threadCount)
|
|
|
) {
|
|
) {
|