1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| class MyAdapter(context: Context, list: ArrayList<DataBean>, val itemClick: (DataBean) -> Unit) : RecyclerView.Adapter<MyAdapter.MyViewHolder>() { var context: Context? = null; var list: ArrayList<DataBean>? = null var inflater: LayoutInflater? = null
init { this.context = context this.list = list this.inflater = LayoutInflater.from(context) }
override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): MyViewHolder { return MyViewHolder(inflater?.inflate(R.layout.item_rank, parent, false), context!!,itemClick) }
override fun getItemCount(): Int { return list?.size ?: 0 }
override fun onBindViewHolder(holder: MyViewHolder?, position: Int) { var photoUrl : String? = list?.get(position)?.cover?.feed photoUrl?.let { ImageLoadUtils.display(context!!,holder?.iv_photo, it) } var title : String? = list?.get(position)?.title holder?.tv_title?.text = title var category = list?.get(position)?.category var duration = list?.get(position)?.duration var minute =duration?.div(60) var second = duration?.minus((minute?.times(60)) as Long ) var realMinute : String var realSecond : String if(minute!!<10){ realMinute = "0"+minute }else{ realMinute = minute.toString() } if(second!!<10){ realSecond = "0"+second }else{ realSecond = second.toString() } holder?.tv_time?.text = "$category / $realMinute'$realSecond''" holder?.itemView?.setOnClickListener { var intent : Intent = Intent(context, VideoDetailActivity::class.java) var desc = list?.get(position)?.description var playUrl = list?.get(position)?.playUrl var blurred = list?.get(position)?.cover?.blurred var collect = list?.get(position)?.consumption?.collectionCount var share = list?.get(position)?.consumption?.shareCount var reply = list?.get(position)?.consumption?.replyCount var time = System.currentTimeMillis() var videoBean = VideoBean(photoUrl,title,desc,duration,playUrl,category,blurred,collect ,share ,reply,time) var url = SPUtils.getInstance(context!!,"beans").getString(playUrl!!) if(url.equals("")){ var count = SPUtils.getInstance(context!!,"beans").getInt("count") if(count!=-1){ count = count.inc() }else{ count = 1 } SPUtils.getInstance(context!!,"beans").put("count",count) SPUtils.getInstance(context!!,"beans").put(playUrl!!,playUrl) ObjectSaveUtils.saveObject(context!!,"bean$count",videoBean) } intent.putExtra("data",videoBean as Parcelable) context?.let { context -> context.startActivity(intent) } } }
inner class MyViewHolder(itemView: View?, context: Context, val itemClick: (DataBean) -> Unit) : RecyclerView.ViewHolder(itemView) { var iv_photo: ImageView = itemView?.findViewById(R.id.iv_photo) as ImageView var tv_title: TextView = itemView?.findViewById(R.id.tv_title) as TextView var tv_time: TextView = itemView?.findViewById(R.id.tv_time) as TextView init { tv_title?.typeface = Typeface.createFromAsset(context?.assets, "fonts/FZLanTingHeiS-L-GB-Regular.TTF") bind() } fun bind() { itemView.setOnClickListener { itemClick(list?.get(layoutPosition) as DataBean) } } } }
|