Skip to content

Commit

Permalink
mod/#9: Friend Data 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
youjin09222 committed May 8, 2024
1 parent 4391afa commit a3964d5
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
14 changes: 0 additions & 14 deletions app/src/main/java/com/sopt/now/test/data/Friend.kt

This file was deleted.

10 changes: 10 additions & 0 deletions app/src/main/java/com/sopt/now/test/data/Profile.kt
Original file line number Diff line number Diff line change
@@ -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
)
22 changes: 13 additions & 9 deletions app/src/main/java/com/sopt/now/test/friend/FriendAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<Friend>) : RecyclerView.Adapter<BaseViewHolder>() {
class FriendAdapter(private val profiles: List<Profile>) : RecyclerView.Adapter<BaseViewHolder>() {

// 첫 번째 아이템
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)
}
Expand All @@ -30,21 +30,25 @@ class FriendAdapter(private val profiles: List<Friend>) : RecyclerView.Adapter<B
val profile = profiles[position]

when (holder) {
is FriendViewHolder -> {
is UserViewHolder -> {
holder.onBind(profile)
}
is UserViewHolder -> {
is FriendViewHolder -> {
holder.onBind(profile)
}
}
}

override fun getItemViewType(position: Int): Int {
return when (position) {
FIRST_ITEM_POSITION -> 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
}
}
20 changes: 11 additions & 9 deletions app/src/main/java/com/sopt/now/test/friend/FriendViewHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit a3964d5

Please sign in to comment.