|
|
|
@ -4,6 +4,7 @@ import android.graphics.drawable.GradientDrawable |
|
|
|
|
import android.view.LayoutInflater |
|
|
|
|
import android.view.View |
|
|
|
|
import android.view.ViewGroup |
|
|
|
|
import android.widget.TextView |
|
|
|
|
import androidx.paging.PagedListAdapter |
|
|
|
|
import androidx.recyclerview.widget.DiffUtil |
|
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
@ -13,6 +14,7 @@ import io.legado.app.lib.theme.ColorUtils |
|
|
|
|
import io.legado.app.utils.gone |
|
|
|
|
import io.legado.app.utils.invisible |
|
|
|
|
import kotlinx.android.synthetic.main.item_find_book.view.* |
|
|
|
|
import org.jetbrains.anko.sdk27.listeners.onClick |
|
|
|
|
|
|
|
|
|
class FindBookAdapter:PagedListAdapter<BookSource, FindBookAdapter.MyViewHolder>(DIFF_CALLBACK) { |
|
|
|
|
|
|
|
|
@ -33,26 +35,33 @@ class FindBookAdapter:PagedListAdapter<BookSource, FindBookAdapter.MyViewHolder> |
|
|
|
|
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_find_book, parent, false)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: MyViewHolder, position: Int) { |
|
|
|
|
currentList?.get(position)?.let { |
|
|
|
|
holder.bind(it, position == exIndex) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { |
|
|
|
|
|
|
|
|
|
fun bind(bookSource: BookSource, ex: Boolean) = with(itemView) { |
|
|
|
|
val bgShape: GradientDrawable? = tv_name.background as? GradientDrawable |
|
|
|
|
bgShape?.setStroke(2, ColorUtils.getRandomColor()) |
|
|
|
|
tv_name.text = bookSource.bookSourceName |
|
|
|
|
if (ex) { |
|
|
|
|
gl_child.invisible() |
|
|
|
|
bookSource.getExploreRule().exploreUrl?.let { |
|
|
|
|
|
|
|
|
|
override fun onBindViewHolder(holder: MyViewHolder, position: Int): Unit = |
|
|
|
|
with(holder.itemView) { |
|
|
|
|
currentList?.get(position)?.let { bookSource -> |
|
|
|
|
val bgShape: GradientDrawable? = tv_name.background as? GradientDrawable |
|
|
|
|
bgShape?.setStroke(2, ColorUtils.getRandomColor()) |
|
|
|
|
tv_name.text = bookSource.bookSourceName |
|
|
|
|
ll_title.onClick { |
|
|
|
|
val oldEx = exIndex |
|
|
|
|
exIndex = position |
|
|
|
|
notifyItemChanged(oldEx) |
|
|
|
|
notifyItemChanged(position) |
|
|
|
|
} |
|
|
|
|
if (exIndex == position) { |
|
|
|
|
gl_child.invisible() |
|
|
|
|
bookSource.getExploreRule().getExploreKinds(bookSource.bookSourceUrl)?.let { |
|
|
|
|
it.map { kind -> |
|
|
|
|
val tv = TextView(context) |
|
|
|
|
tv.text = kind.title |
|
|
|
|
tv.onClick { } |
|
|
|
|
gl_child.addView(tv) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
gl_child.gone() |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
gl_child.gone() |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) |
|
|
|
|
} |