From 88182d93f02311d5d87c1ca2f1c7489fd24afb4c Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 19 Aug 2019 11:36:47 +0800 Subject: [PATCH] up --- .../legado/app/base/adapter/CommonRecyclerAdapter.kt | 11 +++++++++++ .../app/ui/changesource/ChangeSourceViewModel.kt | 7 ++++++- 2 files changed, 17 insertions(+), 1 deletion(-) 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) + } } }