|
|
@ -1,11 +1,10 @@ |
|
|
|
package io.legado.app.ui.book.search |
|
|
|
package io.legado.app.ui.book.search |
|
|
|
|
|
|
|
|
|
|
|
import android.view.LayoutInflater |
|
|
|
import android.content.Context |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import android.view.ViewGroup |
|
|
|
|
|
|
|
import androidx.paging.PagedListAdapter |
|
|
|
|
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
|
|
|
|
import io.legado.app.R |
|
|
|
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.SearchShow |
|
|
|
import io.legado.app.data.entities.SearchShow |
|
|
|
import io.legado.app.help.ImageLoader |
|
|
|
import io.legado.app.help.ImageLoader |
|
|
|
import io.legado.app.utils.gone |
|
|
|
import io.legado.app.utils.gone |
|
|
@ -15,33 +14,19 @@ import kotlinx.android.synthetic.main.item_bookshelf_list.view.tv_name |
|
|
|
import kotlinx.android.synthetic.main.item_search.view.* |
|
|
|
import kotlinx.android.synthetic.main.item_search.view.* |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
|
|
|
|
|
|
|
|
class SearchAdapter(val callBack: CallBack) : |
|
|
|
class SearchAdapter(context: Context, val callBack: CallBack) : |
|
|
|
PagedListAdapter<SearchShow, SearchAdapter.MyViewHolder>(DiffCallBack()) { |
|
|
|
SimpleRecyclerAdapter<SearchShow>(context, R.layout.item_search) { |
|
|
|
|
|
|
|
|
|
|
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { |
|
|
|
override fun convert(holder: ItemViewHolder, item: SearchShow, payloads: MutableList<Any>) { |
|
|
|
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()) { |
|
|
|
if (payloads.isEmpty()) { |
|
|
|
super.onBindViewHolder(holder, position, payloads) |
|
|
|
bind(holder.itemView, item) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
getItem(position)?.let { |
|
|
|
bindChange(holder.itemView, item, payloads) |
|
|
|
holder.bindChange(it, payloads) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { |
|
|
|
private fun bind(itemView: View, searchBook: SearchShow) { |
|
|
|
getItem(position)?.let { |
|
|
|
with(itemView) { |
|
|
|
holder.bind(it, callBack) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun bind(searchBook: SearchShow, callBack: CallBack?) = with(itemView) { |
|
|
|
|
|
|
|
tv_name.text = searchBook.name |
|
|
|
tv_name.text = searchBook.name |
|
|
|
tv_author.text = context.getString(R.string.author_show, searchBook.author) |
|
|
|
tv_author.text = context.getString(R.string.author_show, searchBook.author) |
|
|
|
bv_originCount.setBadgeCount(searchBook.originCount) |
|
|
|
bv_originCount.setBadgeCount(searchBook.originCount) |
|
|
@ -90,68 +75,69 @@ class SearchAdapter(val callBack: CallBack) : |
|
|
|
.setAsDrawable(iv_cover) |
|
|
|
.setAsDrawable(iv_cover) |
|
|
|
} |
|
|
|
} |
|
|
|
onClick { |
|
|
|
onClick { |
|
|
|
callBack?.showBookInfo(searchBook.name, searchBook.author) |
|
|
|
callBack.showBookInfo(searchBook.name, searchBook.author) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fun bindChange(searchBook: SearchShow, payloads: MutableList<Any>) = |
|
|
|
private fun bindChange(itemView: View, searchBook: SearchShow, payloads: MutableList<Any>) { |
|
|
|
with(itemView) { |
|
|
|
with(itemView) { |
|
|
|
when (payloads[0]) { |
|
|
|
when (payloads[0]) { |
|
|
|
1 -> bv_originCount.setBadgeCount(searchBook.originCount) |
|
|
|
1 -> bv_originCount.setBadgeCount(searchBook.originCount) |
|
|
|
2 -> searchBook.coverUrl.let { |
|
|
|
2 -> searchBook.coverUrl.let { |
|
|
|
ImageLoader.load(context, it)//Glide自动识别http://和file:// |
|
|
|
ImageLoader.load(context, it)//Glide自动识别http://和file:// |
|
|
|
.placeholder(R.drawable.image_cover_default) |
|
|
|
.placeholder(R.drawable.image_cover_default) |
|
|
|
.error(R.drawable.image_cover_default) |
|
|
|
.error(R.drawable.image_cover_default) |
|
|
|
.centerCrop() |
|
|
|
.centerCrop() |
|
|
|
.setAsDrawable(iv_cover) |
|
|
|
.setAsDrawable(iv_cover) |
|
|
|
} |
|
|
|
} |
|
|
|
3 -> { |
|
|
|
3 -> { |
|
|
|
val kinds = searchBook.getKindList() |
|
|
|
val kinds = searchBook.getKindList() |
|
|
|
if (kinds.isEmpty()) { |
|
|
|
if (kinds.isEmpty()) { |
|
|
|
ll_kind.gone() |
|
|
|
ll_kind.gone() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
ll_kind.visible() |
|
|
|
ll_kind.visible() |
|
|
|
for (index in 0..2) { |
|
|
|
for (index in 0..2) { |
|
|
|
if (kinds.size > index) { |
|
|
|
if (kinds.size > index) { |
|
|
|
when (index) { |
|
|
|
when (index) { |
|
|
|
0 -> { |
|
|
|
0 -> { |
|
|
|
tv_kind.text = kinds[index] |
|
|
|
tv_kind.text = kinds[index] |
|
|
|
tv_kind.visible() |
|
|
|
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 { |
|
|
|
1 -> { |
|
|
|
when (index) { |
|
|
|
tv_kind_1.text = kinds[index] |
|
|
|
0 -> tv_kind.gone() |
|
|
|
tv_kind_1.visible() |
|
|
|
1 -> tv_kind_1.gone() |
|
|
|
|
|
|
|
2 -> tv_kind_2.gone() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
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()) { |
|
|
|
4 -> { |
|
|
|
tv_lasted.gone() |
|
|
|
if (searchBook.latestChapterTitle.isNullOrEmpty()) { |
|
|
|
} else { |
|
|
|
tv_lasted.gone() |
|
|
|
tv_lasted.text = context.getString( |
|
|
|
} else { |
|
|
|
R.string.lasted_show, |
|
|
|
tv_lasted.text = context.getString( |
|
|
|
searchBook.latestChapterTitle |
|
|
|
R.string.lasted_show, |
|
|
|
) |
|
|
|
searchBook.latestChapterTitle |
|
|
|
tv_lasted.visible() |
|
|
|
) |
|
|
|
} |
|
|
|
tv_lasted.visible() |
|
|
|
} |
|
|
|
} |
|
|
|
5 -> tv_introduce.text = |
|
|
|
|
|
|
|
context.getString(R.string.intro_show, searchBook.intro) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
5 -> tv_introduce.text = |
|
|
|
|
|
|
|
context.getString(R.string.intro_show, searchBook.intro) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
interface CallBack { |
|
|
|
interface CallBack { |
|
|
|