feat: 优化代码

pull/120/head
kunfei 5 years ago
parent 8fce75a788
commit b2d0bd5de2
  1. 10
      app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt
  2. 4
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt

@ -16,10 +16,6 @@ class DiffCallBack(private val oldItems: List<SearchBook>, private val newItems:
} }
override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean { override fun areItemsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
return true
}
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
val oldItem = oldItems[oldItemPosition] val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition] val newItem = newItems[newItemPosition]
if (oldItem.name != newItem.name) { if (oldItem.name != newItem.name) {
@ -28,6 +24,12 @@ class DiffCallBack(private val oldItems: List<SearchBook>, private val newItems:
if (oldItem.author != newItem.author) { if (oldItem.author != newItem.author) {
return false return false
} }
return true
}
override fun areContentsTheSame(oldItemPosition: Int, newItemPosition: Int): Boolean {
val oldItem = oldItems[oldItemPosition]
val newItem = newItems[newItemPosition]
if (oldItem.origins?.size != newItem.origins?.size) { if (oldItem.origins?.size != newItem.origins?.size) {
return false return false
} }

@ -130,9 +130,9 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
} }
} }
} else if (searchKey == item.author) { } else if (searchKey == item.author) {
for ((i, searchBook) in copyDataS.withIndex()) { for ((index, searchBook) in copyDataS.withIndex()) {
if (searchKey != searchBook.name && searchKey == searchBook.author) { if (searchKey != searchBook.name && searchKey == searchBook.author) {
copyDataS.add(i, item) copyDataS.add(index, item)
break break
} }
} }

Loading…
Cancel
Save