diff --git a/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt b/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt index d39022f7e..16108e2f9 100644 --- a/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt +++ b/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt @@ -122,6 +122,17 @@ abstract class CommonRecyclerAdapter(protected val context: Context) : Rec } } + fun setItemsNoNotify(items: List?) { + synchronized(lock) { + if (this.items.isNotEmpty()) { + this.items.clear() + } + if (items != null) { + this.items.addAll(items) + } + } + } + fun setItems(items: List?) { synchronized(lock) { if (this.items.isNotEmpty()) { diff --git a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt index e392ffc13..7c77397d3 100644 --- a/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt @@ -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) + } } }