안드로이드(코틀린) 채팅앱 만들기 - CattingFragment 1
class CatAdapter(val listData: ArrayList<CatProfile>, val logHelper: ChattingLogHelper) : RecyclerView.Adapter<CatAdapter.Holder>(){
inner class Holder(val binding: ItemChattingCatListBinding): RecyclerView.ViewHolder(binding.root){
fun setCatProfile(catProfile: CatProfile){
val decodedString = Base64.decode(catProfile.cPicture, Base64.DEFAULT)
val decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.size)
with(binding){
cName.text = catProfile.cName
chattingInfo.setOnClickListener {
MainActivity.getInstance()?.openChattingActivity(catProfile)
}
cImage.setImageBitmap(decodedByte)
cImage.clipToOutline = true
}
}
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
val binding = ItemChattingCatListBinding.inflate(LayoutInflater.from(parent.context),parent,false)
return Holder(binding)
}
override fun onBindViewHolder(holder: Holder, position: Int) {
Log.d("ChattingFragment", "${listData[position]}")
val catProfile = listData[position]
holder.setCatProfile(catProfile)
}
override fun getItemCount() = listData.size
}
override fun onResume() {
super.onResume()
if(MainActivity.isChattingFragmentNeedRefresh){
catList = mainActivity.userInfo.cats
binding.chattingRecycler.layoutManager = LinearLayoutManager(mainActivity,LinearLayoutManager.VERTICAL,false)
binding.chattingRecycler.adapter = CatAdapter(catList, logHelper)
MainActivity.isChattingFragmentNeedRefresh = false
}
}