feat: 优化

pull/241/head
gedoor 5 years ago
parent 59335a00c8
commit e3aa9263e6
  1. 5
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceViewModel.kt
  2. 5
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt

@ -62,13 +62,14 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
@Synchronized
private fun upAdapter() {
if (System.currentTimeMillis() > postTime + 500) {
if (System.currentTimeMillis() >= postTime + 500) {
handler.removeCallbacks(sendRunnable)
postTime = System.currentTimeMillis()
val books = searchBooks.toList()
searchBooksLiveData.postValue(books.sortedBy { it.originOrder })
} else {
handler.postDelayed(sendRunnable, 500)
handler.removeCallbacks(sendRunnable)
handler.postDelayed(sendRunnable, 500 - System.currentTimeMillis() + postTime)
}
}

@ -42,12 +42,13 @@ class SearchViewModel(application: Application) : BaseViewModel(application),
@Synchronized
private fun upAdapter() {
if (System.currentTimeMillis() > postTime + 500) {
if (System.currentTimeMillis() >= postTime + 500) {
handler.removeCallbacks(sendRunnable)
postTime = System.currentTimeMillis()
searchBookLiveData.postValue(searchBooks)
} else {
handler.postDelayed(sendRunnable, 500)
handler.removeCallbacks(sendRunnable)
handler.postDelayed(sendRunnable, 500 - System.currentTimeMillis() + postTime)
}
}

Loading…
Cancel
Save