generated from NOW-SOPT-ANDROID/now-sopt-android-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feat/#5 week2 xml 필수과제 구현
- Loading branch information
Showing
25 changed files
with
668 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# Now Sopt Android | ||
feat/#5-week2_xml | ||
|
||
- **[FEAT]** : 새로운 기능 구현 | ||
- **[MOD]** : 코드 수정 및 내부 파일 수정 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.sopt.now | ||
|
||
import android.os.Bundle | ||
import androidx.fragment.app.Fragment | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.viewModels | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import com.sopt.now.databinding.FragmentHomeBinding | ||
|
||
class HomeFragment : Fragment() { | ||
private val binding:FragmentHomeBinding | ||
get()= requireNotNull(_binding){"_binding이 null이 아닌 경우만 _binding 반환"} | ||
private var _binding: FragmentHomeBinding ?= null | ||
private val viewModel by viewModels<HomeViewModel>() | ||
|
||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle? | ||
): View { | ||
_binding = FragmentHomeBinding.inflate(inflater,container,false) | ||
return binding.root | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
val homeListAdapter = HomeListAdapter() | ||
binding.rvFriends.run { | ||
adapter = homeListAdapter | ||
layoutManager = LinearLayoutManager(requireContext()) | ||
} | ||
homeListAdapter.setHomeList(viewModel.homeListData) | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.sopt.now | ||
|
||
import androidx.annotation.DrawableRes | ||
|
||
data class HomeList( | ||
@DrawableRes val profileImage: Int, | ||
val name: String, | ||
val selfDescription: String, | ||
val viewType: Int | ||
) { | ||
companion object { | ||
const val VIEW_TYPE_USER = 0 | ||
const val VIEW_TYPE_FRIEND = 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.sopt.now | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.sopt.now.databinding.ItemFriendBinding | ||
import com.sopt.now.databinding.ItemUserBinding | ||
|
||
class HomeListAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() { | ||
private var homeListList: List<HomeList> = emptyList() | ||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { | ||
val inflater = LayoutInflater.from(parent.context) | ||
val bindingUser = ItemUserBinding.inflate(inflater, parent, false) | ||
val bindingFriend = ItemFriendBinding.inflate(inflater, parent, false) | ||
return when(viewType){ | ||
HomeList.VIEW_TYPE_USER -> { | ||
UserViewHolder(bindingUser) | ||
} | ||
else -> { | ||
FriendViewHolder(bindingFriend) | ||
} | ||
} | ||
} | ||
|
||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { | ||
when(homeListList.getOrNull(position)?.viewType){ | ||
HomeList.VIEW_TYPE_USER -> { | ||
(holder as UserViewHolder).onBind(homeListList[position]) | ||
} | ||
else -> { | ||
(holder as FriendViewHolder).onBind(homeListList[position]) | ||
} | ||
} | ||
} | ||
|
||
override fun getItemCount() = homeListList.size | ||
override fun getItemViewType(position: Int): Int { | ||
return homeListList[position].viewType | ||
} | ||
fun setHomeList(homeListList: List<HomeList>) { | ||
this.homeListList = homeListList.toList() | ||
notifyDataSetChanged() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.sopt.now | ||
|
||
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: HomeList) { | ||
binding.run { | ||
ivProfile.setImageResource(friendData.profileImage) | ||
tvName.text = friendData.name | ||
tvSelfDescription.text = friendData.selfDescription | ||
} | ||
} | ||
} | ||
|
||
class UserViewHolder(private val binding:ItemUserBinding) : RecyclerView.ViewHolder(binding.root) { | ||
fun onBind(friendData: HomeList) { | ||
binding.run { | ||
ivProfile.setImageResource(friendData.profileImage) | ||
tvName.text = friendData.name | ||
tvSelfDescription.text = friendData.selfDescription | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package com.sopt.now | ||
|
||
import androidx.lifecycle.ViewModel | ||
|
||
class HomeViewModel : ViewModel() { | ||
val homeListData = listOf( | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "송혜음", | ||
selfDescription = "멀티 뷰 리싸이클러뷰!", | ||
HomeList.VIEW_TYPE_USER | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "박동민", | ||
selfDescription = "곽의진...얼굴 재치 실력 모든걸 다 가진 남자... 하지만 밀양박씨 36대손인 나 박동민은 가지지 못했지", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "이석준", | ||
selfDescription = "죄송합니다 저 도핑했습니다... 안드-로이더 \uD83D\uDC89", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "박유진", | ||
selfDescription = "(ง˙∇˙)ว 에라 모르겠다", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "이의경", | ||
selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "우상욱", | ||
selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "배지현", | ||
selfDescription = "표정 풀자 ^^", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "이의경", | ||
selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "우상욱", | ||
selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "배지현", | ||
selfDescription = "표정 풀자 ^^", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "이의경", | ||
selfDescription = "다들 빨리 끝내고 뒤풀이 가고 싶지? ㅎㅎ 아직 반도 안왔어 ^&^", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "우상욱", | ||
selfDescription = "나보다 안드 잘하는 사람 있으면 나와봐", | ||
HomeList.VIEW_TYPE_FRIEND | ||
), | ||
HomeList( | ||
profileImage = R.drawable.main, | ||
name = "배지현", | ||
selfDescription = "표정 풀자 ^^", | ||
HomeList.VIEW_TYPE_FRIEND | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.