From bc4e974ed6c3127b8301835ecae926a1778b3935 Mon Sep 17 00:00:00 2001 From: youjin09222 Date: Fri, 7 Jun 2024 08:19:45 +0900 Subject: [PATCH] =?UTF-8?q?rename/#9=20:=20ProfileViewHolder=20=EC=9D=B4?= =?UTF-8?q?=EB=A6=84=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sopt/now/test/friend/FriendViewHolder.kt | 28 --------------- .../home/FriendProfileViewHolder.kt | 17 ++++++++++ .../home/UserProfileAdapter.kt} | 34 +++++++++---------- .../home/UserProfileViewHolder.kt | 18 ++++++++++ 4 files changed, 51 insertions(+), 46 deletions(-) delete mode 100644 app/src/main/java/com/sopt/now/test/friend/FriendViewHolder.kt create mode 100644 app/src/main/java/com/sopt/now/test/presentation/home/FriendProfileViewHolder.kt rename app/src/main/java/com/sopt/now/test/{friend/FriendAdapter.kt => presentation/home/UserProfileAdapter.kt} (52%) create mode 100644 app/src/main/java/com/sopt/now/test/presentation/home/UserProfileViewHolder.kt 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 deleted file mode 100644 index 4e6c4eb..0000000 --- a/app/src/main/java/com/sopt/now/test/friend/FriendViewHolder.kt +++ /dev/null @@ -1,28 +0,0 @@ -package com.sopt.now.test.friend - -import androidx.recyclerview.widget.RecyclerView -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.Profile - -class FriendViewHolder(private val binding: ItemFriendBinding) : RecyclerView.ViewHolder(binding.root) { - fun onBind(friendData: Profile) { - binding.run { - ivFriendProfile.load(friendData.userImage) - tvFriendName.text = friendData.userName - tvFriendPhone.text = friendData.userInfo - } - } -} - -class UserViewHolder(private val binding: ItemUserBinding) : RecyclerView.ViewHolder(binding.root) { - fun onBind(userData: Profile) { - binding.run { - ivMyProfile.load(R.drawable.iv_user_profile) - tvMyName.text = userData.userName - tvMyPhone.text = userData.userInfo - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/test/presentation/home/FriendProfileViewHolder.kt b/app/src/main/java/com/sopt/now/test/presentation/home/FriendProfileViewHolder.kt new file mode 100644 index 0000000..9e8f29f --- /dev/null +++ b/app/src/main/java/com/sopt/now/test/presentation/home/FriendProfileViewHolder.kt @@ -0,0 +1,17 @@ +package com.sopt.now.test.presentation.home + +import androidx.recyclerview.widget.RecyclerView +import coil.api.load +import com.sopt.now.databinding.ItemFriendBinding +import com.sopt.now.test.data.Profile + +class FriendProfileViewHolder(private val binding: ItemFriendBinding) : + RecyclerView.ViewHolder(binding.root) { + fun onBind(friendData: Profile) { + binding.run { + ivFriendProfile.load(friendData.userImage) + tvFriendName.text = friendData.userName + tvFriendPhone.text = friendData.userInfo + } + } +} \ 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/presentation/home/UserProfileAdapter.kt similarity index 52% rename from app/src/main/java/com/sopt/now/test/friend/FriendAdapter.kt rename to app/src/main/java/com/sopt/now/test/presentation/home/UserProfileAdapter.kt index 5b62eef..a18c2ad 100644 --- a/app/src/main/java/com/sopt/now/test/friend/FriendAdapter.kt +++ b/app/src/main/java/com/sopt/now/test/presentation/home/UserProfileAdapter.kt @@ -1,4 +1,4 @@ -package com.sopt.now.test.friend +package com.sopt.now.test.presentation.home import android.view.LayoutInflater import android.view.ViewGroup @@ -7,19 +7,18 @@ import com.sopt.now.databinding.ItemFriendBinding import com.sopt.now.databinding.ItemUserBinding import com.sopt.now.test.data.Profile -class FriendAdapter(private val profiles: List) : RecyclerView.Adapter() { +class UserProfileAdapter(private val profiles: List) : + RecyclerView.Adapter() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { - return when (viewType) { - TYPE_USER -> { - val binding = ItemUserBinding.inflate(LayoutInflater.from(parent.context), parent, false) - UserViewHolder(binding) - } - TYPE_FRIEND -> { - val binding = ItemFriendBinding.inflate(LayoutInflater.from(parent.context), parent, false) - FriendViewHolder(binding) - } - else -> throw IllegalArgumentException("Invalid view type") + return if (viewType == TYPE_USER) { + val binding = + ItemUserBinding.inflate(LayoutInflater.from(parent.context), parent, false) + UserProfileViewHolder(binding) + } else { + val binding = + ItemFriendBinding.inflate(LayoutInflater.from(parent.context), parent, false) + FriendProfileViewHolder(binding) } } @@ -27,21 +26,20 @@ class FriendAdapter(private val profiles: List) : RecyclerView.Adapter< val profile = profiles[position] when (holder) { - is UserViewHolder -> { + is UserProfileViewHolder -> { holder.onBind(profile) } - is FriendViewHolder -> { + + is FriendProfileViewHolder -> { holder.onBind(profile) } } } override fun getItemViewType(position: Int): Int { - return when (position) { - FIRST_ITEM_POSITION -> TYPE_USER - else -> TYPE_FRIEND - } + return if (position == FIRST_ITEM_POSITION) TYPE_USER else TYPE_FRIEND } + override fun getItemCount(): Int = profiles.size companion object { diff --git a/app/src/main/java/com/sopt/now/test/presentation/home/UserProfileViewHolder.kt b/app/src/main/java/com/sopt/now/test/presentation/home/UserProfileViewHolder.kt new file mode 100644 index 0000000..e302ce2 --- /dev/null +++ b/app/src/main/java/com/sopt/now/test/presentation/home/UserProfileViewHolder.kt @@ -0,0 +1,18 @@ +package com.sopt.now.test.presentation.home + +import androidx.recyclerview.widget.RecyclerView +import coil.api.load +import com.sopt.now.R +import com.sopt.now.databinding.ItemUserBinding +import com.sopt.now.test.data.Profile + +class UserProfileViewHolder(private val binding: ItemUserBinding) : + RecyclerView.ViewHolder(binding.root) { + fun onBind(userData: Profile) { + binding.run { + ivMyProfile.load(R.drawable.iv_user_profile) + tvMyName.text = userData.userName + tvMyPhone.text = userData.userInfo + } + } +} \ No newline at end of file