@@ -3,23 +3,33 @@ package com.seok.gfd.adapter
33import android.view.LayoutInflater
44import android.view.View
55import android.view.ViewGroup
6+ import androidx.fragment.app.FragmentActivity
7+ import androidx.lifecycle.ViewModelProviders
68import androidx.recyclerview.widget.RecyclerView
79import com.seok.gfd.R
810import com.seok.gfd.room.entity.SearchGithubId
11+ import com.seok.gfd.viewmodel.GithubIdViewModel
912import kotlinx.android.synthetic.main.item_search_github_id.view.*
1013
1114class SearchGithubIdAdapter (list : ArrayList <SearchGithubId >) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
1215 private val githubIds: ArrayList <SearchGithubId > = list
16+ private lateinit var githubIdsViewModel: GithubIdViewModel
1317
14- class SearchGithubIdViewHolder (itemView : View ) : RecyclerView.ViewHolder(itemView){
15-
18+ inner class SearchGithubIdViewHolder (itemView : View ) : RecyclerView.ViewHolder(itemView){
1619 fun bind (searchGithubId : SearchGithubId ){
1720 itemView.item_search_txt_github_id.text = searchGithubId.gidName
21+ itemView.item_search_img_close.setOnClickListener {
22+ githubIdsViewModel.deleteGithubId(searchGithubId)
23+ githubIds.removeAt(this .adapterPosition)
24+ notifyItemRemoved(this .adapterPosition)
25+ notifyDataSetChanged()
26+ }
1827 }
1928 }
2029
2130 override fun onCreateViewHolder (parent : ViewGroup , viewType : Int ): RecyclerView .ViewHolder {
2231 val view = LayoutInflater .from(parent.context).inflate(R .layout.item_search_github_id, parent, false )
32+ githubIdsViewModel = ViewModelProviders .of(parent.context as FragmentActivity ).get(GithubIdViewModel ::class .java)
2333 return SearchGithubIdViewHolder (view)
2434 }
2535
0 commit comments