pull/43/head
kunfei 5 years ago
parent baf0378bbc
commit 07e9c4b3e6
  1. 2
      app/src/main/java/io/legado/app/data/entities/BaseBook.kt
  2. 4
      app/src/main/java/io/legado/app/data/entities/SearchBook.kt
  3. 13
      app/src/main/java/io/legado/app/ui/book/search/DiffCallBack.kt
  4. 13
      app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt
  5. 29
      app/src/main/java/io/legado/app/ui/book/search/SearchEntity.kt
  6. 10
      app/src/main/java/io/legado/app/ui/book/search/SearchViewModel.kt

@ -10,7 +10,7 @@ interface BaseBook {
var infoHtml: String?
var tocHtml: String?
fun putVariable(key: String, value: String)
fun putVariable(key: String, value: String) {}
fun getKindList(): List<String> {
val kindList = arrayListOf<String>()

@ -64,6 +64,10 @@ data class SearchBook(
variable = GSON.toJson(variableMap)
}
@Ignore
@IgnoredOnParcel
val origins: LinkedHashSet<String>? = null
fun toBook(): Book {
return Book(
name = name,

@ -1,24 +1,25 @@
package io.legado.app.ui.book.search
import androidx.recyclerview.widget.DiffUtil
import io.legado.app.data.entities.SearchBook
class DiffCallBack : DiffUtil.ItemCallback<SearchEntity>() {
override fun areItemsTheSame(oldItem: SearchEntity, newItem: SearchEntity): Boolean {
class DiffCallBack : DiffUtil.ItemCallback<SearchBook>() {
override fun areItemsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean {
return oldItem.name == newItem.name
&& oldItem.author == newItem.author
}
override fun areContentsTheSame(oldItem: SearchEntity, newItem: SearchEntity): Boolean {
return oldItem.originCount == newItem.originCount
override fun areContentsTheSame(oldItem: SearchBook, newItem: SearchBook): Boolean {
return oldItem.origins?.size == newItem.origins?.size
&& (oldItem.coverUrl == newItem.coverUrl || !oldItem.coverUrl.isNullOrEmpty())
&& (oldItem.kind == newItem.kind || !oldItem.kind.isNullOrEmpty())
&& (oldItem.latestChapterTitle == newItem.latestChapterTitle || !oldItem.kind.isNullOrEmpty())
&& oldItem.intro?.length ?: 0 > newItem.intro?.length ?: 0
}
override fun getChangePayload(oldItem: SearchEntity, newItem: SearchEntity): Any? {
override fun getChangePayload(oldItem: SearchBook, newItem: SearchBook): Any? {
return when {
oldItem.originCount != newItem.originCount -> 1
oldItem.origins?.size != newItem.origins?.size -> 1
oldItem.coverUrl != newItem.coverUrl -> 2
oldItem.kind != newItem.kind -> 3
oldItem.latestChapterTitle != newItem.latestChapterTitle -> 4

@ -5,6 +5,7 @@ import android.view.View
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.SearchBook
import io.legado.app.help.ImageLoader
import io.legado.app.utils.gone
import io.legado.app.utils.visible
@ -14,9 +15,9 @@ import kotlinx.android.synthetic.main.item_search.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class SearchAdapter(context: Context, val callBack: CallBack) :
SimpleRecyclerAdapter<SearchEntity>(context, R.layout.item_search) {
SimpleRecyclerAdapter<SearchBook>(context, R.layout.item_search) {
override fun convert(holder: ItemViewHolder, item: SearchEntity, payloads: MutableList<Any>) {
override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) {
if (payloads.isEmpty()) {
bind(holder.itemView, item)
} else {
@ -24,11 +25,11 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
}
}
private fun bind(itemView: View, searchBook: SearchEntity) {
private fun bind(itemView: View, searchBook: SearchBook) {
with(itemView) {
tv_name.text = searchBook.name
tv_author.text = context.getString(R.string.author_show, searchBook.author)
bv_originCount.setBadgeCount(searchBook.originCount)
bv_originCount.setBadgeCount(searchBook.origins?.size ?: 1)
if (searchBook.latestChapterTitle.isNullOrEmpty()) {
tv_lasted.gone()
} else {
@ -79,10 +80,10 @@ class SearchAdapter(context: Context, val callBack: CallBack) :
}
}
private fun bindChange(itemView: View, searchBook: SearchEntity, payloads: MutableList<Any>) {
private fun bindChange(itemView: View, searchBook: SearchBook, payloads: MutableList<Any>) {
with(itemView) {
when (payloads[0]) {
1 -> bv_originCount.setBadgeCount(searchBook.originCount)
1 -> bv_originCount.setBadgeCount(searchBook.origins?.size ?: 1)
2 -> searchBook.coverUrl.let {
ImageLoader.load(context, it)//Glide自动识别http://和file://
.placeholder(R.drawable.image_cover_default)

@ -1,29 +0,0 @@
package io.legado.app.ui.book.search
import io.legado.app.utils.splitNotBlank
data class SearchEntity(
var name: String = "",
var author: String = "",
var kind: String? = null,
var coverUrl: String? = null,
var intro: String? = null,
var wordCount: String? = null,
var latestChapterTitle: String? = null,
var time: Long = 0L,
var originCount: Int = 0
) {
fun getKindList(): List<String> {
val kindList = arrayListOf<String>()
wordCount?.let {
if (it.isNotBlank()) kindList.add(it)
}
kind?.let {
val kinds = it.splitNotBlank(",", "\n")
kindList.addAll(kinds)
}
return kindList
}
}

@ -22,7 +22,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
var startTime: Long = 0
var searchPage = 0
var isLoading = false
private val booksShow = arrayListOf<SearchEntity>()
private val searchBooks = arrayListOf<SearchBook>()
fun search(
key: String,
@ -34,7 +34,7 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
searchPage++
} else {
searchKey = key
booksShow.clear()
searchBooks.clear()
}
if (searchKey.isEmpty()) return
startTime = System.currentTimeMillis()
@ -81,8 +81,10 @@ class SearchViewModel(application: Application) : BaseViewModel(application) {
}
}
private fun addToAdapter(searchBooks: List<SearchBook>) {
callBack?.adapter.let { adapter ->
@Synchronized
private fun addToAdapter(books: List<SearchBook>) {
if (books.isNotEmpty()) {
val copyDataS = ArrayList(searchBooks)
}
}

Loading…
Cancel
Save