pull/32/head
kunfei 5 years ago
parent aee0503868
commit 88182d93f0
  1. 11
      app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt
  2. 7
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt

@ -122,6 +122,17 @@ abstract class CommonRecyclerAdapter<ITEM>(protected val context: Context) : Rec
}
}
fun setItemsNoNotify(items: List<ITEM>?) {
synchronized(lock) {
if (this.items.isNotEmpty()) {
this.items.clear()
}
if (items != null) {
this.items.addAll(items)
}
}
}
fun setItems(items: List<ITEM>?) {
synchronized(lock) {
if (this.items.isNotEmpty()) {

@ -9,6 +9,7 @@ import io.legado.app.data.entities.Book
import io.legado.app.data.entities.SearchBook
import io.legado.app.model.WebBook
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.jetbrains.anko.debug
class ChangeSourceViewModel(application: Application) : BaseViewModel(application) {
@ -30,8 +31,12 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
private fun upAdapter() {
callBack?.adapter()?.let {
val books = searchBooks.toList()
val diffResult = DiffUtil.calculateDiff(DiffCallBack(it.getItems(), searchBooks.toList()))
diffResult.dispatchUpdatesTo(it)
launch {
it.setItemsNoNotify(books)
diffResult.dispatchUpdatesTo(it)
}
}
}

Loading…
Cancel
Save