From 40c4f30dd157b137d93c3475ee7c764625f1e4d8 Mon Sep 17 00:00:00 2001 From: hyeumm <20221159@sungshin.ac.kr> Date: Sun, 14 Apr 2024 01:53:41 +0900 Subject: [PATCH] =?UTF-8?q?feat/#5:=20=EB=A9=80=ED=8B=B0=EB=B7=B0=20?= =?UTF-8?q?=EB=A6=AC=EC=8B=B8=EC=9D=B4=ED=81=B4=EB=9F=AC=EB=B7=B0=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/sopt/now/Friend.kt | 8 +++- .../main/java/com/sopt/now/FriendAdapter.kt | 48 +++++++++++++++---- .../java/com/sopt/now/FriendViewHolder.kt | 21 ++++---- .../main/java/com/sopt/now/HomeFragment.kt | 15 ++++-- .../main/java/com/sopt/now/LoginActivity.kt | 4 +- app/src/main/res/layout/item_friend.xml | 2 +- app/src/main/res/layout/item_user.xml | 48 +++++++++++++++++++ 7 files changed, 121 insertions(+), 25 deletions(-) create mode 100644 app/src/main/res/layout/item_user.xml diff --git a/app/src/main/java/com/sopt/now/Friend.kt b/app/src/main/java/com/sopt/now/Friend.kt index f6d3ea0..031fead 100644 --- a/app/src/main/java/com/sopt/now/Friend.kt +++ b/app/src/main/java/com/sopt/now/Friend.kt @@ -6,4 +6,10 @@ data class Friend( @DrawableRes val profileImage: Int, val name: String, val selfDescription: String, -) \ No newline at end of file + val viewType : Int +) { + companion object { + const val VIEW_TYPE_USER = 0 + const val VIEW_TYPE_FRIEND = 1 + } +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/FriendAdapter.kt b/app/src/main/java/com/sopt/now/FriendAdapter.kt index 57c710c..014d53c 100644 --- a/app/src/main/java/com/sopt/now/FriendAdapter.kt +++ b/app/src/main/java/com/sopt/now/FriendAdapter.kt @@ -1,26 +1,54 @@ package com.sopt.now import android.view.LayoutInflater +import android.view.View import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView -import com.sopt.now.databinding.ItemFriendBinding +import java.lang.RuntimeException -class FriendAdapter() : RecyclerView.Adapter() { +class FriendAdapter() : RecyclerView.Adapter() { // 임시의 빈 리스트 private var friendList: List = emptyList() - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): FriendViewHolder { - val inflater = LayoutInflater.from(parent.context) - val binding = ItemFriendBinding.inflate(inflater, parent, false) - return FriendViewHolder(binding) + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { + val adapterLayout : View? + return when(viewType){ + Friend.VIEW_TYPE_USER -> { + adapterLayout = LayoutInflater.from(parent.context) + .inflate(R.layout.item_user,parent,false) + UserViewHolder(adapterLayout) + } + Friend.VIEW_TYPE_FRIEND -> { + adapterLayout = LayoutInflater.from(parent.context) + .inflate(R.layout.item_friend,parent,false) + FriendViewHolder(adapterLayout) + } + else -> throw RuntimeException("알 수 없는 뷰타입입니다.") + } } - override fun onBindViewHolder(holder: FriendViewHolder, position: Int) { - holder.onBind(friendList[position]) + override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { + val item = friendList[position] + when(item.viewType){ + Friend.VIEW_TYPE_USER -> { + (holder as UserViewHolder).ivProfile.setImageResource(item.profileImage) + holder.tvName.text = item.name + holder.tvSelfDescription.text = item.selfDescription + holder.setIsRecyclable(false) + } + Friend.VIEW_TYPE_FRIEND -> { + (holder as FriendViewHolder).ivProfile.setImageResource(item.profileImage) + holder.tvName.text = item.name + holder.tvSelfDescription.text = item.selfDescription + holder.setIsRecyclable(false) + } + else -> throw RuntimeException("알 수 없는 뷰타입입니다.") + } } override fun getItemCount() = friendList.size - + override fun getItemViewType(position: Int): Int { + return friendList[position].viewType + } fun setFriendList(friendList: List) { this.friendList = friendList.toList() notifyDataSetChanged() diff --git a/app/src/main/java/com/sopt/now/FriendViewHolder.kt b/app/src/main/java/com/sopt/now/FriendViewHolder.kt index 85375be..5e255ee 100644 --- a/app/src/main/java/com/sopt/now/FriendViewHolder.kt +++ b/app/src/main/java/com/sopt/now/FriendViewHolder.kt @@ -1,14 +1,19 @@ package com.sopt.now +import android.view.View +import android.widget.ImageView +import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.sopt.now.databinding.ItemFriendBinding +import com.sopt.now.databinding.ItemUserBinding -class FriendViewHolder(private val binding: ItemFriendBinding) : RecyclerView.ViewHolder(binding.root) { - fun onBind(friendData: Friend) { - binding.run { - ivProfile.setImageResource(friendData.profileImage) - tvName.text = friendData.name - tvSelfDescription.text = friendData.selfDescription - } - } +class FriendViewHolder(private val view: View) : RecyclerView.ViewHolder(view) { + val ivProfile : ImageView = view.findViewById(R.id.iv_profile) + val tvName : TextView = view.findViewById(R.id.tv_name) + val tvSelfDescription : TextView = view.findViewById(R.id.tv_self_description) +} +class UserViewHolder(private val view: View) : RecyclerView.ViewHolder(view) { + val ivProfile : ImageView = view.findViewById(R.id.iv_profile) + val tvName : TextView = view.findViewById(R.id.tv_name) + val tvSelfDescription : TextView = view.findViewById(R.id.tv_self_description) } \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/HomeFragment.kt b/app/src/main/java/com/sopt/now/HomeFragment.kt index 2917642..922b00e 100644 --- a/app/src/main/java/com/sopt/now/HomeFragment.kt +++ b/app/src/main/java/com/sopt/now/HomeFragment.kt @@ -13,19 +13,28 @@ class HomeFragment : Fragment() { private val mockFriendList = listOf( Friend( - profileImage = R.drawable.ic_home_white_24, + profileImage = R.drawable.main, + name = "송혜음", + selfDescription = "멀티 뷰 리싸이클러뷰!", + 0 + ), + Friend( + profileImage = R.drawable.main, name = "이의경", selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^", + 1 ), Friend( - profileImage = R.drawable.ic_home_white_24, + profileImage = R.drawable.main, name = "우상욱", selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐", + 1 ), Friend( - profileImage = R.drawable.ic_home_white_24, + profileImage = R.drawable.main, name = "배지현", selfDescription = "표정 풀자 ^^", + 1 ), ) override fun onCreateView( diff --git a/app/src/main/java/com/sopt/now/LoginActivity.kt b/app/src/main/java/com/sopt/now/LoginActivity.kt index 23c1d48..78e1356 100644 --- a/app/src/main/java/com/sopt/now/LoginActivity.kt +++ b/app/src/main/java/com/sopt/now/LoginActivity.kt @@ -68,8 +68,8 @@ class LoginActivity : AppCompatActivity() { } private fun sendData(id:String,pw:String,nick:String){ if (isLoginAvailable(id, pw)) { - var mypagefragment = MyPageFragment() - var bundle = Bundle() + val mypagefragment = MyPageFragment() + val bundle = Bundle() bundle.putString("id",id) bundle.putString("pw",pw) bundle.putString("nick",nick) diff --git a/app/src/main/res/layout/item_friend.xml b/app/src/main/res/layout/item_friend.xml index 93d9c95..bd00c96 100644 --- a/app/src/main/res/layout/item_friend.xml +++ b/app/src/main/res/layout/item_friend.xml @@ -11,7 +11,7 @@ android:layout_marginStart="20dp" android:scaleType="centerCrop" android:layout_marginVertical="10dp" - android:src="@drawable/ic_person_white_24" + android:src="@drawable/main" app:layout_constraintDimensionRatio="1" app:layout_constraintStart_toStartOf="parent" app:layout_constraintBottom_toBottomOf="parent" diff --git a/app/src/main/res/layout/item_user.xml b/app/src/main/res/layout/item_user.xml new file mode 100644 index 0000000..fa7ba00 --- /dev/null +++ b/app/src/main/res/layout/item_user.xml @@ -0,0 +1,48 @@ + + + + + + + + + + \ No newline at end of file