Commit 0f079764 authored by mengcuiguang's avatar mengcuiguang

代码优化

parent a5edb06c
package com.mints.wisdomclean.ui.adapter
import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.xinfu.helivideo.R
import com.xinfu.helivideo.mvp.model.VedioBean
import com.xinfu.library.utils.GlideUtils
class HotStyleAdapter(val context: Context, val dataList: ArrayList<VedioBean>?) :
RecyclerView.Adapter<HotStyleAdapter.ViewHolder>() {
lateinit var mOnItemClickListener: OnItemClickListener
inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
val ivVedioItem: ImageView = view.findViewById(R.id.ivVedioItem)
val tvVedioItemCount: TextView = view.findViewById(R.id.tvVedioItemCount)
val tvVedioItemTitle: TextView = view.findViewById(R.id.tvVedioItemTitle)
val tvVedioItemText: TextView = view.findViewById(R.id.tvVedioItemText)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(context).inflate(R.layout.item_hot_style, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val topBean = dataList?.get(position)
if (topBean != null) {
holder.tvVedioItemCount.text =
"${if (topBean.completeStatus == 0) "已完结" else "更新至${topBean.vedioTotal}"}"
holder.tvVedioItemTitle.text = "${topBean.title}"
holder.tvVedioItemText.text = "${topBean.vedioDesc}"
GlideUtils.loadImageViewGifForFitCenter(
context,
topBean.coverImage,
holder.ivVedioItem
)
}
holder.itemView.setOnClickListener {
mOnItemClickListener.onItemClick(position)
}
holder.itemView.setTag(position)
}
override fun getItemCount(): Int = dataList?.size ?: 0
interface OnItemClickListener {
fun onItemClick(position: Int)
}
fun setOnItemClickListener(listener: OnItemClickListener) {
mOnItemClickListener = listener
}
}
\ No newline at end of file
......@@ -8,29 +8,26 @@ import com.xinfu.helivideo.mvp.model.VedioBean
class NewHotStyleAdapter : BaseQuickAdapter<VedioBean, BaseViewHolder>(R.layout.item_hot_style) {
override fun convert(holder: BaseViewHolder, item: VedioBean) {
holder.setText(
R.id.tvVedioItemCount,
"${if (item.completeStatus == 0) "已完结" else "更新至${item.vedioTotal}"}"
)
if (item.title != null) {
item?.let {
holder.setText(
R.id.tvVedioItemCount,
"${if (it.completeStatus == 0) "已完结" else "更新至${it.vedioTotal}"}"
)
holder.setText(
R.id.tvVedioItemTitle,
"${item.title}"
"${it.title}"
)
}
if (item.vedioDesc != null) {
holder.setText(
R.id.tvVedioItemText,
"${item.vedioDesc}"
"${it.vedioDesc}"
)
}
if (item.coverImage != null) {
GlideUtils.loadImageViewGifForFitCenter(
context,
item.coverImage,
it.coverImage,
holder.getView(R.id.ivVedioItem)
)
}
}
}
\ No newline at end of file
......@@ -2,8 +2,10 @@ package com.xinfu.helivideo.ui.fragment
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import com.mints.wisdomclean.ui.adapter.HotStyleAdapter
import com.xinfu.helivideo.R
import com.xinfu.helivideo.common.Constant
import com.xinfu.helivideo.manager.LocalVedioManager
......@@ -42,6 +44,7 @@ class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener
private var hotPage = 1 // 分页
private val hotList: ArrayList<VedioBean> = arrayListOf()
private lateinit var hotStyleAdapter: NewHotStyleAdapter
// private lateinit var hotStyleAdapter: HotStyleAdapter
override fun getContentViewLayoutID() = R.layout.fragment_movie
......@@ -121,6 +124,21 @@ class MovieFragment : LazyLoadBaseFragment(), PicContentView, OnLoadMoreListener
)
}
}
// val gridLayoutManager = GridLayoutManager(context, 3)
// rv_pic_list.layoutManager = gridLayoutManager
// hotStyleAdapter = HotStyleAdapter(requireContext(), hotList)
// rv_pic_list.adapter = hotStyleAdapter
// hotStyleAdapter.setOnItemClickListener(object : HotStyleAdapter.OnItemClickListener {
// override fun onItemClick(position: Int) {
// if (hotList!=null&&hotList!!.size > 0) {
// LocalVedioManager.startVedioDetailActivityForType(
// requireActivity(),
// hotList!!.get(position)
// )
// }
// }
// })
}
private fun initListener() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment