|
|
@ -1,12 +1,12 @@ |
|
|
|
package io.legado.app.ui.book.search |
|
|
|
package io.legado.app.ui.book.search |
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context |
|
|
|
import android.content.Context |
|
|
|
|
|
|
|
import android.os.Bundle |
|
|
|
import android.view.View |
|
|
|
import android.view.View |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.R |
|
|
|
import io.legado.app.base.adapter.ItemViewHolder |
|
|
|
import io.legado.app.base.adapter.ItemViewHolder |
|
|
|
import io.legado.app.base.adapter.SimpleRecyclerAdapter |
|
|
|
import io.legado.app.base.adapter.SimpleRecyclerAdapter |
|
|
|
import io.legado.app.data.entities.SearchBook |
|
|
|
import io.legado.app.data.entities.SearchBook |
|
|
|
import io.legado.app.help.ImageLoader |
|
|
|
|
|
|
|
import io.legado.app.utils.gone |
|
|
|
import io.legado.app.utils.gone |
|
|
|
import io.legado.app.utils.visible |
|
|
|
import io.legado.app.utils.visible |
|
|
|
import kotlinx.android.synthetic.main.item_bookshelf_list.view.iv_cover |
|
|
|
import kotlinx.android.synthetic.main.item_bookshelf_list.view.iv_cover |
|
|
@ -18,10 +18,11 @@ class SearchAdapter(context: Context, val callBack: CallBack) : |
|
|
|
SimpleRecyclerAdapter<SearchBook>(context, R.layout.item_search) { |
|
|
|
SimpleRecyclerAdapter<SearchBook>(context, R.layout.item_search) { |
|
|
|
|
|
|
|
|
|
|
|
override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) { |
|
|
|
override fun convert(holder: ItemViewHolder, item: SearchBook, payloads: MutableList<Any>) { |
|
|
|
if (payloads.isEmpty()) { |
|
|
|
val bundle = payloads.getOrNull(0) as? Bundle |
|
|
|
|
|
|
|
if (bundle == null) { |
|
|
|
bind(holder.itemView, item) |
|
|
|
bind(holder.itemView, item) |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
bindChange(holder.itemView, item, payloads) |
|
|
|
bindChange(holder.itemView, item, bundle) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -30,43 +31,9 @@ class SearchAdapter(context: Context, val callBack: CallBack) : |
|
|
|
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.origins?.size ?: 1) |
|
|
|
bv_originCount.setBadgeCount(searchBook.origins?.size ?: 1) |
|
|
|
if (searchBook.latestChapterTitle.isNullOrEmpty()) { |
|
|
|
upLasted(itemView, searchBook.latestChapterTitle) |
|
|
|
tv_lasted.gone() |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
tv_lasted.text = context.getString(R.string.lasted_show, searchBook.latestChapterTitle) |
|
|
|
|
|
|
|
tv_lasted.visible() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
tv_introduce.text = context.getString(R.string.intro_show, searchBook.intro) |
|
|
|
tv_introduce.text = context.getString(R.string.intro_show, searchBook.intro) |
|
|
|
val kinds = searchBook.getKindList() |
|
|
|
upKind(itemView, 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() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
iv_cover.load(searchBook.coverUrl, searchBook.name, searchBook.author) |
|
|
|
iv_cover.load(searchBook.coverUrl, searchBook.name, searchBook.author) |
|
|
|
onClick { |
|
|
|
onClick { |
|
|
|
callBack.showBookInfo(searchBook.name, searchBook.author) |
|
|
|
callBack.showBookInfo(searchBook.name, searchBook.author) |
|
|
@ -74,64 +41,71 @@ class SearchAdapter(context: Context, val callBack: CallBack) : |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun bindChange(itemView: View, searchBook: SearchBook, payloads: MutableList<Any>) { |
|
|
|
private fun bindChange(itemView: View, searchBook: SearchBook, bundle: Bundle) { |
|
|
|
with(itemView) { |
|
|
|
with(itemView) { |
|
|
|
when (payloads[0]) { |
|
|
|
bundle.keySet().map { |
|
|
|
1 -> bv_originCount.setBadgeCount(searchBook.origins?.size ?: 1) |
|
|
|
when (it) { |
|
|
|
2 -> searchBook.coverUrl.let { |
|
|
|
"name" -> tv_name.text = searchBook.name |
|
|
|
ImageLoader.load(context, it)//Glide自动识别http://和file:// |
|
|
|
"author" -> tv_author.text = |
|
|
|
.placeholder(R.drawable.image_cover_default) |
|
|
|
context.getString(R.string.author_show, searchBook.author) |
|
|
|
.error(R.drawable.image_cover_default) |
|
|
|
"originCount" -> bv_originCount.setBadgeCount(searchBook.origins?.size ?: 1) |
|
|
|
.centerCrop() |
|
|
|
"lasted" -> upLasted(itemView, searchBook.latestChapterTitle) |
|
|
|
.into(iv_cover) |
|
|
|
"introduce" -> tv_introduce.text = |
|
|
|
|
|
|
|
context.getString(R.string.intro_show, searchBook.intro) |
|
|
|
|
|
|
|
"kind" -> upKind(itemView, searchBook.getKindList()) |
|
|
|
|
|
|
|
"cover" -> iv_cover.load( |
|
|
|
|
|
|
|
searchBook.coverUrl, |
|
|
|
|
|
|
|
searchBook.name, |
|
|
|
|
|
|
|
searchBook.author |
|
|
|
|
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
3 -> { |
|
|
|
} |
|
|
|
val kinds = searchBook.getKindList() |
|
|
|
} |
|
|
|
if (kinds.isEmpty()) { |
|
|
|
} |
|
|
|
ll_kind.gone() |
|
|
|
|
|
|
|
} else { |
|
|
|
private fun upLasted(itemView: View, latestChapterTitle: String?) { |
|
|
|
ll_kind.visible() |
|
|
|
with(itemView) { |
|
|
|
for (index in 0..2) { |
|
|
|
if (latestChapterTitle.isNullOrEmpty()) { |
|
|
|
if (kinds.size > index) { |
|
|
|
tv_lasted.gone() |
|
|
|
when (index) { |
|
|
|
} else { |
|
|
|
0 -> { |
|
|
|
tv_lasted.text = |
|
|
|
tv_kind.text = kinds[index] |
|
|
|
context.getString( |
|
|
|
tv_kind.visible() |
|
|
|
R.string.lasted_show, |
|
|
|
} |
|
|
|
latestChapterTitle |
|
|
|
1 -> { |
|
|
|
) |
|
|
|
tv_kind_1.text = kinds[index] |
|
|
|
tv_lasted.visible() |
|
|
|
tv_kind_1.visible() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
2 -> { |
|
|
|
} |
|
|
|
tv_kind_2.text = kinds[index] |
|
|
|
|
|
|
|
tv_kind_2.visible() |
|
|
|
private fun upKind(itemView: View, kinds: List<String>) = with(itemView) { |
|
|
|
} |
|
|
|
if (kinds.isEmpty()) { |
|
|
|
} |
|
|
|
ll_kind.gone() |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
when (index) { |
|
|
|
ll_kind.visible() |
|
|
|
0 -> tv_kind.gone() |
|
|
|
for (index in 0..2) { |
|
|
|
1 -> tv_kind_1.gone() |
|
|
|
if (kinds.size > index) { |
|
|
|
2 -> tv_kind_2.gone() |
|
|
|
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 { |
|
|
|
4 -> { |
|
|
|
when (index) { |
|
|
|
if (searchBook.latestChapterTitle.isNullOrEmpty()) { |
|
|
|
0 -> tv_kind.gone() |
|
|
|
tv_lasted.gone() |
|
|
|
1 -> tv_kind_1.gone() |
|
|
|
} else { |
|
|
|
2 -> tv_kind_2.gone() |
|
|
|
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) |
|
|
|
|
|
|
|
else -> { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|