diff --git a/app/src/main/java/com/sopt/now/test/data/Friend.kt b/app/src/main/java/com/sopt/now/test/data/Friend.kt deleted file mode 100644 index 95e548b..0000000 --- a/app/src/main/java/com/sopt/now/test/data/Friend.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.sopt.now.test.data - -import androidx.annotation.DrawableRes - -data class Friend( - @DrawableRes val profileImage: Int, - val name: String, - val phone: String, -) { - companion object { - const val TYPE_USER = 0 - const val TYPE_FRIEND = 1 - } -} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/test/data/Profile.kt b/app/src/main/java/com/sopt/now/test/data/Profile.kt new file mode 100644 index 0000000..0fb1f77 --- /dev/null +++ b/app/src/main/java/com/sopt/now/test/data/Profile.kt @@ -0,0 +1,10 @@ +package com.sopt.now.test.data + +import kotlinx.serialization.Serializable + +@Serializable +data class Profile( + val userImage: String, + val userName: String, + val userInfo: String +) \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/test/friend/FriendAdapter.kt b/app/src/main/java/com/sopt/now/test/friend/FriendAdapter.kt index d3fc245..2e5c25e 100644 --- a/app/src/main/java/com/sopt/now/test/friend/FriendAdapter.kt +++ b/app/src/main/java/com/sopt/now/test/friend/FriendAdapter.kt @@ -5,20 +5,20 @@ import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.sopt.now.databinding.ItemFriendBinding import com.sopt.now.databinding.ItemUserBinding -import com.sopt.now.test.data.Friend +import com.sopt.now.test.data.Profile -class FriendAdapter(private val profiles: List) : RecyclerView.Adapter() { +class FriendAdapter(private val profiles: List) : RecyclerView.Adapter() { // 첫 번째 아이템 private val FIRST_ITEM_POSITION = 0 override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder { return when (viewType) { - Friend.TYPE_USER -> { + TYPE_USER -> { val binding = ItemUserBinding.inflate(LayoutInflater.from(parent.context), parent, false) UserViewHolder(binding) } - Friend.TYPE_FRIEND -> { + TYPE_FRIEND -> { val binding = ItemFriendBinding.inflate(LayoutInflater.from(parent.context), parent, false) FriendViewHolder(binding) } @@ -30,10 +30,10 @@ class FriendAdapter(private val profiles: List) : RecyclerView.Adapter { + is UserViewHolder -> { holder.onBind(profile) } - is UserViewHolder -> { + is FriendViewHolder -> { holder.onBind(profile) } } @@ -41,10 +41,14 @@ class FriendAdapter(private val profiles: List) : RecyclerView.Adapter Friend.TYPE_USER - else -> Friend.TYPE_FRIEND + FIRST_ITEM_POSITION -> TYPE_USER + else -> TYPE_FRIEND } } - override fun getItemCount(): Int = profiles.size + + companion object { + const val TYPE_USER = 0 + const val TYPE_FRIEND = 1 + } } \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/test/friend/FriendViewHolder.kt b/app/src/main/java/com/sopt/now/test/friend/FriendViewHolder.kt index c78de7a..b73a649 100644 --- a/app/src/main/java/com/sopt/now/test/friend/FriendViewHolder.kt +++ b/app/src/main/java/com/sopt/now/test/friend/FriendViewHolder.kt @@ -2,28 +2,30 @@ package com.sopt.now.test.friend import androidx.recyclerview.widget.RecyclerView import androidx.viewbinding.ViewBinding +import coil.api.load +import com.sopt.now.R import com.sopt.now.databinding.ItemFriendBinding import com.sopt.now.databinding.ItemUserBinding -import com.sopt.now.test.data.Friend +import com.sopt.now.test.data.Profile sealed class BaseViewHolder(binding: ViewBinding) : RecyclerView.ViewHolder(binding.root) class FriendViewHolder(private val binding: ItemFriendBinding) : BaseViewHolder(binding) { - fun onBind(friendData: Friend) { + fun onBind(friendData: Profile) { binding.run { - ivFriendProfile.setImageResource(friendData.profileImage) - tvFriendName.text = friendData.name - tvFriendPhone.text = friendData.phone + ivFriendProfile.load(friendData.userImage) + tvFriendName.text = friendData.userName + tvFriendPhone.text = friendData.userInfo } } } class UserViewHolder(private val binding: ItemUserBinding) : BaseViewHolder(binding) { - fun onBind(userData: Friend) { + fun onBind(userData: Profile) { binding.run { - ivMyProfile.setImageResource(userData.profileImage) - tvMyName.text = userData.name - tvMyPhone.text = userData.phone + ivMyProfile.load(R.drawable.iv_user_profile) + tvMyName.text = userData.userName + tvMyPhone.text = userData.userInfo } } } \ No newline at end of file