Skip to content

Commit

Permalink
refactor/#9: init 사용
Browse files Browse the repository at this point in the history
  • Loading branch information
youjin09222 committed May 10, 2024
1 parent d50abcc commit f92c796
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ class HomeFragment: Fragment() {

// 사용자 프로필 설정
private fun setUserProfile() {
userViewModel.userInfo()

userViewModel.userInfoLiveData.observe(requireActivity()) { userInfo ->
userInfo?.let {
val userProfile = Profile(
Expand All @@ -50,15 +48,12 @@ class HomeFragment: Fragment() {
userInfo = userInfo.data.phone,
)
userList.add(0, userProfile)
setRecyclerView()
}
}
}

// 친구 프로필 설정
private fun setFriendProfile() {
friendViewModel.getFriendInfo(0)

friendViewModel.friendInfoLiveData.observe(requireActivity()) { friendInfo ->
friendInfo?.let {
friendInfo.data.forEach { friendData ->
Expand All @@ -67,7 +62,7 @@ class HomeFragment: Fragment() {
userName = friendData.firstName,
userInfo = friendData.email
)
userList.add(friend)
userList.add(1, friend)
}
setRecyclerView()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ class HomeViewModel() : ViewModel() {
val liveData = MutableLiveData<BaseState>()
val friendInfoLiveData = MutableLiveData<ResponseFriendDto?>()

fun getFriendInfo(page: Int) {
friendService.getFriendInfo(page).enqueue(object : Callback<ResponseFriendDto> {
init{
friendInfo()
}

private fun friendInfo() {
friendService.getFriendInfo(0).enqueue(object : Callback<ResponseFriendDto> {
override fun onResponse(
call: Call<ResponseFriendDto>,
response: Response<ResponseFriendDto>,
Expand All @@ -30,9 +34,7 @@ class HomeViewModel() : ViewModel() {
isSuccess = true,
message = response.message()
)
Log.d("HomeViewModel", "Response: $data")
} else {
Log.e("HomeViewModel", "Failed to get friend info: ${response.code()}")
val error = response.errorBody()?.string()
val gson = Gson()
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.sopt.now.test.presentation

import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.google.gson.Gson
Expand All @@ -21,7 +20,7 @@ class UserInfoViewModel : ViewModel() {
userInfo()
}

fun userInfo() {
private fun userInfo() {
userService.getUserInfo().enqueue(object : Callback<ResponseUserInfoDto> {
override fun onResponse(
call: Call<ResponseUserInfoDto>,
Expand Down

0 comments on commit f92c796

Please sign in to comment.