mirror of
https://github.com/gedoor/legado.git
synced 2025-08-10 00:52:30 +00:00
优化
This commit is contained in:
@@ -28,6 +28,7 @@ class SearchModel(private val scope: CoroutineScope, private val callBack: CallB
|
||||
private var tasks = CompositeCoroutine()
|
||||
private var bookSourceList = arrayListOf<BookSource>()
|
||||
private var searchBooks = arrayListOf<SearchBook>()
|
||||
private val emptyBookSource = BookSource()
|
||||
|
||||
@Volatile
|
||||
private var searchIndex = -1
|
||||
@@ -76,6 +77,7 @@ class SearchModel(private val scope: CoroutineScope, private val callBack: CallB
|
||||
return
|
||||
}
|
||||
searchIndex++
|
||||
val searchIndex = searchIndex
|
||||
val source = bookSourceList[searchIndex]
|
||||
val searchPool = searchPool ?: return
|
||||
val task = WebBook.searchBook(
|
||||
@@ -91,7 +93,7 @@ class SearchModel(private val scope: CoroutineScope, private val callBack: CallB
|
||||
onSuccess(searchId, it)
|
||||
}
|
||||
.onFinally {
|
||||
onFinally(searchId)
|
||||
onFinally(searchId, searchIndex)
|
||||
}
|
||||
tasks.add(task)
|
||||
}
|
||||
@@ -107,12 +109,15 @@ class SearchModel(private val scope: CoroutineScope, private val callBack: CallB
|
||||
}
|
||||
|
||||
@Synchronized
|
||||
private fun onFinally(searchId: Long) {
|
||||
private fun onFinally(searchId: Long, index: Int) {
|
||||
if (searchIndex < bookSourceList.lastIndex) {
|
||||
search(searchId)
|
||||
} else {
|
||||
searchIndex++
|
||||
}
|
||||
if (index <= bookSourceList.lastIndex) {
|
||||
bookSourceList[index] = emptyBookSource
|
||||
}
|
||||
if (searchIndex >= bookSourceList.lastIndex
|
||||
+ min(bookSourceList.size, threadCount)
|
||||
) {
|
||||
|
||||
@@ -212,6 +212,7 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
|
||||
binding.rvHistoryKey.adapter = historyKeyAdapter
|
||||
binding.recyclerView.layoutManager = LinearLayoutManager(this)
|
||||
binding.recyclerView.adapter = adapter
|
||||
binding.recyclerView.itemAnimator = null
|
||||
adapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
|
||||
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
|
||||
super.onItemRangeInserted(positionStart, itemCount)
|
||||
|
||||
Reference in New Issue
Block a user