From dacc76e2eb2324295e7bee4a0acd6e33bfad67a2 Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 19 Aug 2019 10:56:54 +0800 Subject: [PATCH] up --- .../ui/changesource/ChangeSourceViewModel.kt | 11 +++++--- .../app/ui/changesource/DiffCallBack.kt | 27 +++++++++++++++++++ 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 app/src/main/java/io/legado/app/ui/changesource/DiffCallBack.kt 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