From 03a21c448bf2ab6defd5569223cb10731eb20e9b Mon Sep 17 00:00:00 2001 From: hyeumm <20221159@sungshin.ac.kr> Date: Thu, 11 Apr 2024 02:52:31 +0900 Subject: [PATCH] =?UTF-8?q?feat/#5:=20=EB=A6=AC=EC=8B=B8=EC=9D=B4=ED=81=B4?= =?UTF-8?q?=EB=9F=AC=EB=B7=B0=20=EC=97=B0=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/com/sopt/now/Friend.kt | 9 ++++ .../main/java/com/sopt/now/FriendAdapter.kt | 28 ++++++++++++ .../java/com/sopt/now/FriendViewHolder.kt | 14 ++++++ .../main/java/com/sopt/now/MyPageFragment.kt | 38 +++++++++++++--- app/src/main/res/layout/fragment_my_page.xml | 10 +++-- app/src/main/res/layout/item_friend.xml | 43 +++++++++++++++++++ 6 files changed, 133 insertions(+), 9 deletions(-) create mode 100644 app/src/main/java/com/sopt/now/Friend.kt create mode 100644 app/src/main/java/com/sopt/now/FriendAdapter.kt create mode 100644 app/src/main/java/com/sopt/now/FriendViewHolder.kt create mode 100644 app/src/main/res/layout/item_friend.xml diff --git a/app/src/main/java/com/sopt/now/Friend.kt b/app/src/main/java/com/sopt/now/Friend.kt new file mode 100644 index 0000000..f6d3ea0 --- /dev/null +++ b/app/src/main/java/com/sopt/now/Friend.kt @@ -0,0 +1,9 @@ +package com.sopt.now + +import androidx.annotation.DrawableRes + +data class Friend( + @DrawableRes val profileImage: Int, + val name: String, + val selfDescription: String, +) \ 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 new file mode 100644 index 0000000..57c710c --- /dev/null +++ b/app/src/main/java/com/sopt/now/FriendAdapter.kt @@ -0,0 +1,28 @@ +package com.sopt.now + +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.RecyclerView +import com.sopt.now.databinding.ItemFriendBinding + +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 onBindViewHolder(holder: FriendViewHolder, position: Int) { + holder.onBind(friendList[position]) + } + + override fun getItemCount() = friendList.size + + fun setFriendList(friendList: List) { + this.friendList = friendList.toList() + notifyDataSetChanged() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/FriendViewHolder.kt b/app/src/main/java/com/sopt/now/FriendViewHolder.kt new file mode 100644 index 0000000..85375be --- /dev/null +++ b/app/src/main/java/com/sopt/now/FriendViewHolder.kt @@ -0,0 +1,14 @@ +package com.sopt.now + +import androidx.recyclerview.widget.RecyclerView +import com.sopt.now.databinding.ItemFriendBinding + +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 + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/sopt/now/MyPageFragment.kt b/app/src/main/java/com/sopt/now/MyPageFragment.kt index 1780051..bb34054 100644 --- a/app/src/main/java/com/sopt/now/MyPageFragment.kt +++ b/app/src/main/java/com/sopt/now/MyPageFragment.kt @@ -5,18 +5,44 @@ import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import androidx.recyclerview.widget.LinearLayoutManager +import com.sopt.now.databinding.FragmentMyPageBinding class MyPageFragment : Fragment() { + private lateinit var binding:FragmentMyPageBinding - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - } - + private val mockFriendList = listOf( + Friend( + profileImage = R.drawable.ic_home_white_24, + name = "이의경", + selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^", + ), + Friend( + profileImage = R.drawable.ic_home_white_24, + name = "우상욱", + selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐", + ), + Friend( + profileImage = R.drawable.ic_home_white_24, + name = "배지현", + selfDescription = "표정 풀자 ^^", + ), + ) override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? ): View? { - // Inflate the layout for this fragment - return inflater.inflate(R.layout.fragment_my_page, container, false) + binding=FragmentMyPageBinding.inflate(inflater) + return binding.root } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + val friendAdapter = FriendAdapter() + binding.rvFriends.run { + adapter = friendAdapter + layoutManager = LinearLayoutManager(requireContext()) + } + friendAdapter.setFriendList(mockFriendList) + } + } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_my_page.xml b/app/src/main/res/layout/fragment_my_page.xml index 3fd4134..30979a5 100644 --- a/app/src/main/res/layout/fragment_my_page.xml +++ b/app/src/main/res/layout/fragment_my_page.xml @@ -3,12 +3,16 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" + xmlns:app="http://schemas.android.com/apk/res-auto" tools:context=".MyPageFragment"> - - + android:orientation="vertical" + app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" + tools:listitem="@layout/item_friend" + android:paddingVertical="5dp"/> \ No newline at end of file diff --git a/app/src/main/res/layout/item_friend.xml b/app/src/main/res/layout/item_friend.xml new file mode 100644 index 0000000..2b3bf0d --- /dev/null +++ b/app/src/main/res/layout/item_friend.xml @@ -0,0 +1,43 @@ + + + + + + + + + + \ No newline at end of file