|
|
|
@ -4,7 +4,6 @@ import android.view.LayoutInflater |
|
|
|
|
import android.view.View |
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
import androidx.paging.PagedListAdapter |
|
|
|
|
import androidx.recyclerview.widget.DiffUtil |
|
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
|
import io.legado.app.R |
|
|
|
|
import io.legado.app.data.entities.SearchShow |
|
|
|
@ -16,21 +15,7 @@ import kotlinx.android.synthetic.main.item_bookshelf_list.view.tv_name |
|
|
|
|
import kotlinx.android.synthetic.main.item_search.view.* |
|
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
|
|
|
|
|
|
class SearchAdapter : PagedListAdapter<SearchShow, SearchAdapter.MyViewHolder>(DIFF_CALLBACK) { |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
@JvmField |
|
|
|
|
val DIFF_CALLBACK = object : DiffUtil.ItemCallback<SearchShow>() { |
|
|
|
|
override fun areItemsTheSame(oldItem: SearchShow, newItem: SearchShow): Boolean = |
|
|
|
|
oldItem.name == newItem.name |
|
|
|
|
&& oldItem.author == newItem.author |
|
|
|
|
|
|
|
|
|
override fun areContentsTheSame(oldItem: SearchShow, newItem: SearchShow): Boolean = |
|
|
|
|
oldItem.name == newItem.name |
|
|
|
|
&& oldItem.author == newItem.author |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
class SearchAdapter : PagedListAdapter<SearchShow, SearchAdapter.MyViewHolder>(DiffCallBack()) { |
|
|
|
|
|
|
|
|
|
var callBack: CallBack? = null |
|
|
|
|
|
|
|
|
@ -38,6 +23,16 @@ class SearchAdapter : PagedListAdapter<SearchShow, SearchAdapter.MyViewHolder>(D |
|
|
|
|
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_search, parent, false)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: MyViewHolder, position: Int, payloads: MutableList<Any>) { |
|
|
|
|
if (payloads.isEmpty()) { |
|
|
|
|
super.onBindViewHolder(holder, position, payloads) |
|
|
|
|
} else { |
|
|
|
|
getItem(position)?.let { |
|
|
|
|
holder.bindChange(it, payloads, callBack) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { |
|
|
|
|
getItem(position)?.let { |
|
|
|
|
holder.bind(it, callBack) |
|
|
|
@ -49,8 +44,8 @@ class SearchAdapter : PagedListAdapter<SearchShow, SearchAdapter.MyViewHolder>(D |
|
|
|
|
|
|
|
|
|
fun bind(searchBook: SearchShow, callBack: CallBack?) = with(itemView) { |
|
|
|
|
tv_name.text = searchBook.name |
|
|
|
|
bv_originCount.setBadgeCount(searchBook.originCount) |
|
|
|
|
tv_author.text = context.getString(R.string.author_show, searchBook.author) |
|
|
|
|
bv_originCount.setBadgeCount(searchBook.originCount) |
|
|
|
|
if (searchBook.latestChapterTitle.isNullOrEmpty()) { |
|
|
|
|
tv_lasted.gone() |
|
|
|
|
} else { |
|
|
|
@ -99,6 +94,65 @@ class SearchAdapter : PagedListAdapter<SearchShow, SearchAdapter.MyViewHolder>(D |
|
|
|
|
callBack?.showBookInfo(searchBook.name, searchBook.author) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fun bindChange(searchBook: SearchShow, payloads: MutableList<Any>, callBack: CallBack?) = |
|
|
|
|
with(itemView) { |
|
|
|
|
when (payloads[0]) { |
|
|
|
|
1 -> bv_originCount.setBadgeCount(searchBook.originCount) |
|
|
|
|
2 -> searchBook.coverUrl.let { |
|
|
|
|
ImageLoader.load(context, it)//Glide自动识别http://和file:// |
|
|
|
|
.placeholder(R.drawable.img_cover_default) |
|
|
|
|
.error(R.drawable.img_cover_default) |
|
|
|
|
.centerCrop() |
|
|
|
|
.setAsDrawable(iv_cover) |
|
|
|
|
} |
|
|
|
|
3 -> { |
|
|
|
|
val kinds = searchBook.getKindList() |
|
|
|
|
if (kinds.isEmpty()) { |
|
|
|
|
ll_kind.gone() |
|
|
|
|
} else { |
|
|
|
|
ll_kind.visible() |
|
|
|
|
for (index in 0..2) { |
|
|
|
|
if (kinds.size > index) { |
|
|
|
|
when (index) { |
|
|
|
|
0 -> { |
|
|
|
|
tv_kind.text = kinds[index] |
|
|
|
|
tv_kind.visible() |
|
|
|
|
} |
|
|
|
|
1 -> { |
|
|
|
|
tv_kind_1.text = kinds[index] |
|
|
|
|
tv_kind_1.visible() |
|
|
|
|
} |
|
|
|
|
2 -> { |
|
|
|
|
tv_kind_2.text = kinds[index] |
|
|
|
|
tv_kind_2.visible() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
when (index) { |
|
|
|
|
0 -> tv_kind.gone() |
|
|
|
|
1 -> tv_kind_1.gone() |
|
|
|
|
2 -> tv_kind_2.gone() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
4 -> { |
|
|
|
|
if (searchBook.latestChapterTitle.isNullOrEmpty()) { |
|
|
|
|
tv_lasted.gone() |
|
|
|
|
} else { |
|
|
|
|
tv_lasted.text = context.getString( |
|
|
|
|
R.string.lasted_show, |
|
|
|
|
searchBook.latestChapterTitle |
|
|
|
|
) |
|
|
|
|
tv_lasted.visible() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
5 -> tv_introduce.text = |
|
|
|
|
context.getString(R.string.intro_show, searchBook.intro) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
interface CallBack { |
|
|
|
|