Skip to content

Commit

Permalink
rename/#9 : ProfileViewHolder 이름 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
youjin09222 committed Jun 6, 2024
1 parent 794ae60 commit bc4e974
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 46 deletions.
28 changes: 0 additions & 28 deletions app/src/main/java/com/sopt/now/test/friend/FriendViewHolder.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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
}
}
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -7,41 +7,39 @@ 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<Profile>) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
class UserProfileAdapter(private val profiles: List<Profile>) :
RecyclerView.Adapter<RecyclerView.ViewHolder>() {

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)
}
}

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
}

0 comments on commit bc4e974

Please sign in to comment.