feat: 优化代码

pull/103/head
kunfei 5 years ago
parent 2bd0c7024d
commit 32a0b2fbc2
  1. 5
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt

@ -50,6 +50,7 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
private var menu: Menu? = null
private var precisionSearchMenuItem: MenuItem? = null
private var groups = hashSetOf<String>()
private var refreshTime = System.currentTimeMillis()
override fun onActivityCreated(savedInstanceState: Bundle?) {
initRecyclerView()
@ -263,6 +264,10 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
@Synchronized
private fun setSearchItems(items: List<SearchBook>) {
if (System.currentTimeMillis() - refreshTime < 1000) {
return
}
refreshTime = System.currentTimeMillis()
val diffResult = DiffUtil.calculateDiff(DiffCallBack(ArrayList(adapter.getItems()), items))
adapter.setItems(items, false)
diffResult.dispatchUpdatesTo(adapter)

Loading…
Cancel
Save