Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7주차/필수] Repository 분리 - xml #17

Open
wants to merge 13 commits into
base: develop-xml
Choose a base branch
from

Conversation

Hyobeen-Park
Copy link
Collaborator

@Hyobeen-Park Hyobeen-Park commented Jun 7, 2024

Related issue 🛠

Work Video ✏️

KakaoTalk_20240607_234435747.mp4

Copy link

@Marchbreeze Marchbreeze left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반갑습니다 효빈님, 과제 코드리뷰로 참여하게 된 32기, 33기 안드로이드 수료한 김상호입니다 :)

사실 다른 조 코드리뷰 담당이긴한데, 둘러보다가 효빈님 보고 반가워서 들렸어요!
혹시 저를... 기억하시려나요..^_^

코드 너무 깔끔하고, 아키텍처 분리까지 완전 깔끔하시네요 !!
코드리뷰에 담긴 질문들은 꼭 고쳐야한다고 말씀드리는게 아닙니다! 코드를 활용해보는 과정에서 생각을 담은 개발을 하기 위한 하나의 질문을 던져드린다고 생각해주세요 ㅎㅎ (고치세요!가 아니라… 이유가 궁금하거나 알고 썼나 궁금해서 질문드리는…것입니다)

실력은 충분해보이시니, 앞으로 앱잼도 꼭 좋은 팀 만나서 행복앱잼하시기를 응원하겠습니다 :)

Comment on lines +29 to +30
private lateinit var userAdapter: UserAdapter
private lateinit var friendAdapter: FriendAdapter

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fragment의 경우에는 View와 객체의 생명주기가 달라서, Adapter 역시 binding과 같이 백패킹 설정 후 onDestroyView()에서 해제해주는 방식이 안전합니다!

initUserData()
getUserList()

homeViewModel.getUserInfo(activity?.intent?.getStringExtra(USERID) ?: "0")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

activity? 보다는 requireActivity()가 더 안전할 것 같아요!
UserId를 스트링 값으로 저장하는 이유가 있나요?

getUserList()

homeViewModel.getUserInfo(activity?.intent?.getStringExtra(USERID) ?: "0")
homeViewModel.getFriendsInfo(2)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이렇게 onCreateView에서 뷰모델의 함수를 바로 실행시키는 경우는,
뷰모델에서 init으로 처리할 수 있습니다!
// 뷰모델

init {
    getFriendsInfo(2)
}

private fun getFriendsInfo( ... )

처럼요~

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저도 이렇게 사용합니당

showToastMessage(homeUserState.message)
}

else -> Unit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

코틀린 문에서는 when() 에서 else 대신 모든 경우를 표시하는 것으로 권장되어 있습니다! 물론 저도 귀찮아서 가끔 잘 안지키지만...ㅎ

Comment on lines +95 to 97
private fun showToastMessage(message: String?) {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 친구들은 다른 뷰에서도 자주 활용되기 때문에 확장함수로서 따로 파일을 생성해두고, 공동으로 사용한다면 중복 코드를 줄일 수 있어요!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toast, snackbar 등등.. 자주 사용되는 것을 util로 빼서 관리하고 호출할 수 있어요

Comment on lines +36 to +37
viewModelScope.launch {
_homeFriendState.value = UiState.Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사소한 차이고 스타일 차이긴 한데, 저는 viewModelScope 안에는 서버통신에 실제로 필요한 값들만 넣어두긴 합니다!

Suggested change
viewModelScope.launch {
_homeFriendState.value = UiState.Loading
_homeFriendState.value = UiState.Loading
viewModelScope.launch {

loginViewModel.loginState.flowWithLifecycle(lifecycle).onEach { loginState ->
when (loginState) {
is UiState.Success -> {
showToastMessage("${loginState.data} 님 로그인에 성공했습니다")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 토스트 텍스트들도 모두 텍스트 추출해서 보관하는게 더 깔끔해질 것 같아요 ~

Comment on lines +59 to +61
Intent(this@LoginActivity, HomeActivity::class.java).apply {
putExtra(USERID, loginState.data.toString())
startActivity(this)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

스코프 함수 활용 편안하네요 ㅠㅡㅠ

Copy link
Member

@Eonji-sw Eonji-sw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨어요!

authService.getUserInfo(memberId = memberId)

companion object {
const val LOCATION = "location"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굿굿

@Serializable
data class ResponseFriendsDto(
@SerialName("page")
val page: Int,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
val page: Int,
val page: Int = -1,

기본값 설정해주면 더 좋을 것 같아요

import retrofit2.Call
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.POST

interface AuthService {
@POST("member/join")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상수화해주면 좋을 것 같아요

@Body request: RequestLoginDto,
): Call<ResponseSignupDto>
): Response<NullableBaseResponse<Unit>>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Response<NullableBaseResponse... 로 감싼 이유가 있을까요?

@Header("memberId") userId: String,
): Call<ResponseUserInfoDto>
suspend fun getUserInfo(
@Header("memberId") memberId: String,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분도 상수화 가능해요

Comment on lines +95 to 97
private fun showToastMessage(message: String?) {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toast, snackbar 등등.. 자주 사용되는 것을 util로 빼서 관리하고 호출할 수 있어요

with(binding) {
btnLoginSignin.setOnClickListener {
if (etLoginId.text.isEmpty()) {
showToastMessage("아이디를 입력해주세요")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 것도 strings 파일로 빼면 좋을 것 같네요. 또한 해당 로직을 뷰모델로 빼는게 좋아보여요.

}.launchIn(lifecycleScope)
}

private fun showToastMessage(message: String?) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여러 곳에서 반복되어 사용되어지는걸 보니 재사용성을 높일 필요가 중요해보이네요!

class LoginViewModel(
private val authRepository: AuthRepository,
) : ViewModel() {
private val _loginState = MutableStateFlow<UiState<Int?>>(UiState.Empty)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SharedFlow와의 차이점이 뭘까요?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BaseResponse와 분리하여 만든 이유가 있나요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7주차 필수 과제 - XML
3 participants