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 b4e889b96..58d687f3f 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 @@ -16,17 +16,22 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio var name: String = "" var author: String = "" val searchBookData = MutableLiveData>() - private val searchBooks = arrayListOf() + private val searchBooks = linkedSetOf() fun initData() { execute { App.db.searchBookDao().getByNameAuthorEnable(name, author).let { searchBooks.addAll(it) - searchBookData.postValue(searchBooks) + searchBookData.postValue(it) + search() } } } + fun upAdapter() { + + } + fun search() { execute { val bookSourceList = App.db.bookSourceDao().allEnabled @@ -80,7 +85,7 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio fun screen(key: String?) { if (key.isNullOrEmpty()) { - searchBookData.postValue(searchBooks) + searchBookData.postValue(searchBooks.toList()) } else { } diff --git a/app/src/main/java/io/legado/app/ui/changesource/DiffCallBack.kt b/app/src/main/java/io/legado/app/ui/changesource/DiffCallBack.kt new file mode 100644 index 000000000..2183c51e5 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/changesource/DiffCallBack.kt @@ -0,0 +1,27 @@ +package io.legado.app.ui.changesource + +import androidx.recyclerview.widget.DiffUtil +import io.legado.app.data.entities.SearchBook + +class DiffCallBack(private val oldItems: List, private val newItems: List) : + DiffUtil.Callback() { + + + override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + return oldItems[oldItemPosition].bookUrl == newItems[newItemPosition].bookUrl + } + + override fun getOldListSize(): Int { + return oldItems.size + } + + override fun getNewListSize(): Int { + return newItems.size + } + + override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { + return oldItems[oldItemPosition].originName == newItems[newItemPosition].originName + && oldItems[oldItemPosition].latestChapterTitle == newItems[newItemPosition].originName + } + +} \ No newline at end of file