pull/32/head
kunfei 5 years ago
parent 4e0efb4e45
commit dacc76e2eb
  1. 11
      app/src/main/java/io/legado/app/ui/changesource/ChangeSourceViewModel.kt
  2. 27
      app/src/main/java/io/legado/app/ui/changesource/DiffCallBack.kt

@ -16,17 +16,22 @@ class ChangeSourceViewModel(application: Application) : BaseViewModel(applicatio
var name: String = ""
var author: String = ""
val searchBookData = MutableLiveData<List<SearchBook>>()
private val searchBooks = arrayListOf<SearchBook>()
private val searchBooks = linkedSetOf<SearchBook>()
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 {
}

@ -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<SearchBook>, private val newItems: List<SearchBook>) :
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
}
}
Loading…
Cancel
Save