Skip to content

Commit

Permalink
mod/#5: 뷰홀더 분리 데이터 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeeum committed Apr 14, 2024
1 parent b379d72 commit 69ccff0
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 35 deletions.
8 changes: 0 additions & 8 deletions app/src/main/java/com/sopt/now/FriendViewHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,8 @@ 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 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)
}
28 changes: 1 addition & 27 deletions app/src/main/java/com/sopt/now/HomeFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,32 +11,6 @@ import com.sopt.now.databinding.FragmentHomeBinding
class HomeFragment : Fragment() {
private lateinit var binding: FragmentHomeBinding

private val mockFriendList = listOf<Friend>(
Friend(
profileImage = R.drawable.main,
name = "송혜음",
selfDescription = "멀티 뷰 리싸이클러뷰!",
0
),
Friend(
profileImage = R.drawable.main,
name = "이의경",
selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^",
1
),
Friend(
profileImage = R.drawable.main,
name = "우상욱",
selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐",
1
),
Friend(
profileImage = R.drawable.main,
name = "배지현",
selfDescription = "표정 풀자 ^^",
1
),
)
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
Expand All @@ -51,7 +25,7 @@ class HomeFragment : Fragment() {
adapter = friendAdapter
layoutManager = LinearLayoutManager(requireContext())
}
friendAdapter.setFriendList(mockFriendList)
friendAdapter.setFriendList(MockFriendList.mockFriendList)
}

}
66 changes: 66 additions & 0 deletions app/src/main/java/com/sopt/now/MockFriendList.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.sopt.now

object MockFriendList {
val mockFriendList = listOf(
Friend(
profileImage = R.drawable.main,
name = "송혜음",
selfDescription = "멀티 뷰 리싸이클러뷰!",
0
),
Friend(
profileImage = R.drawable.main,
name = "이의경",
selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^",
1
),
Friend(
profileImage = R.drawable.main,
name = "우상욱",
selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐",
1
),
Friend(
profileImage = R.drawable.main,
name = "배지현",
selfDescription = "표정 풀자 ^^",
1
),
Friend(
profileImage = R.drawable.main,
name = "이의경",
selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^",
1
),
Friend(
profileImage = R.drawable.main,
name = "우상욱",
selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐",
1
),
Friend(
profileImage = R.drawable.main,
name = "배지현",
selfDescription = "표정 풀자 ^^",
1
),
Friend(
profileImage = R.drawable.main,
name = "이의경",
selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^",
1
),
Friend(
profileImage = R.drawable.main,
name = "우상욱",
selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐",
1
),
Friend(
profileImage = R.drawable.main,
name = "배지현",
selfDescription = "표정 풀자 ^^",
1
)
)
}
12 changes: 12 additions & 0 deletions app/src/main/java/com/sopt/now/UserViewHolder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.sopt.now

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

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

0 comments on commit 69ccff0

Please sign in to comment.