11package com.fmt.github.home.adapter
22
3- import android.content.Context
4- import android.content.Intent
3+ import android.app.Activity
54import android.view.LayoutInflater
65import android.view.View
76import android.view.ViewGroup
@@ -10,11 +9,13 @@ import androidx.recyclerview.widget.DiffUtil
109import androidx.recyclerview.widget.RecyclerView
1110import com.fmt.github.databinding.LayoutReceivedEventBinding
1211import com.fmt.github.home.model.ReceivedEventModel
13- import com.fmt.github.repos.activity.ReposDetailActivity
12+ import com.fmt.github.repos.activity.go2ReposDetailActivity
13+ import com.fmt.github.user.activity.go2UserInfoActivity
14+ import com.fmt.github.user.model.UserModel
1415
1516const val BASE_WEB_URL = " https://github.com/"
1617
17- class HomeAdapter (private val mContext : Context ) :
18+ class HomeAdapter (private val mContext : Activity ) :
1819 PagedListAdapter <ReceivedEventModel , HomeAdapter .ViewHolder >(object :
1920 DiffUtil .ItemCallback <ReceivedEventModel >() {
2021 override fun areItemsTheSame (oldItem : ReceivedEventModel , newItem : ReceivedEventModel ) =
@@ -38,27 +39,25 @@ class HomeAdapter(private val mContext: Context) :
3839 getItem(position)?.let { receivedEventModel ->
3940 holder.bindData(receivedEventModel)
4041 holder.itemView.setOnClickListener {
41- go2ReposDetailActivity(receivedEventModel)
42+ val splitArr = receivedEventModel.repo.name.split(" /" )
43+ go2ReposDetailActivity(mContext," ${BASE_WEB_URL }${receivedEventModel.repo.name} " ,
44+ splitArr[1 ],splitArr[0 ])
4245 }
4346 }
4447 }
4548
46- private fun go2ReposDetailActivity (receivedEventModel : ReceivedEventModel ) {
47- val splitArr = receivedEventModel.repo.name.split(" /" )
48- with (Intent (mContext, ReposDetailActivity ::class .java)) {
49- putExtra(ReposDetailActivity .WEB_URL , " ${BASE_WEB_URL }${receivedEventModel.repo.name} " )
50- putExtra(ReposDetailActivity .OWNER , splitArr[0 ])
51- putExtra(ReposDetailActivity .REPO , splitArr[1 ])
52- }.run {
53- mContext.startActivity(this )
54- }
55- }
56-
57- class ViewHolder (itemView : View , val binding : LayoutReceivedEventBinding ) :
49+ inner class ViewHolder (itemView : View , val binding : LayoutReceivedEventBinding ) :
5850 RecyclerView .ViewHolder (itemView) {
5951
6052 fun bindData (receivedEventModel : ReceivedEventModel ) {
6153 binding.item = receivedEventModel
54+ binding.ivHead.setOnClickListener {
55+ go2UserInfoActivity(
56+ mContext,
57+ binding.ivHead,
58+ UserModel (receivedEventModel.actor.login, receivedEventModel.actor.avatar_url)
59+ )
60+ }
6261 }
6362 }
6463}
0 commit comments