feat: 优化代码

pull/141/head
kunfei 5 years ago
parent 8ee3932dca
commit b03675c53b
  1. 9
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt

@ -283,15 +283,10 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
*/ */
@Synchronized @Synchronized
private fun upSearchItems(items: List<SearchBook>, isMandatoryUpdate: Boolean) { private fun upSearchItems(items: List<SearchBook>, isMandatoryUpdate: Boolean) {
if (!isMandatoryUpdate && System.currentTimeMillis() - refreshTime < 500) { if (isMandatoryUpdate || System.currentTimeMillis() - refreshTime > 500) {
return refreshTime = System.currentTimeMillis()
}
refreshTime = System.currentTimeMillis()
try {
val diffResult = DiffUtil.calculateDiff(DiffCallBack(adapter.getItems(), items)) val diffResult = DiffUtil.calculateDiff(DiffCallBack(adapter.getItems(), items))
adapter.setItems(items, diffResult) adapter.setItems(items, diffResult)
} catch (e: Exception) {
e.printStackTrace()
} }
} }

Loading…
Cancel
Save