5주차 미션_종이#17
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
kimdoyeon1234
left a comment
There was a problem hiding this comment.
수고하셨습니다! 이번 PR에서 정말 인상적인 부분이 많았어요! 지금도 좋지만 개선해야할 부분들을 조금 남겨두었으니 참고해주세요!
- repeatOnLifecycle 패턴을 HomeFragment와 MainActivity에도 동일하게 적용해보세요
- ProductAdapter도 FollowingAdapter처럼 ListAdapter + DiffUtil로 바꾸면 일관성이 생겨요
- 파일 구조를 역할별 패키지로 나눠두면 프로젝트가 커져도 관리하기 편합니다
수고하셨습니다!
| private const val API_KEY = "reqres_701d6373134941c7ba1e30b84be78104" | ||
|
|
||
| private val logging = HttpLoggingInterceptor().apply { | ||
| level = HttpLoggingInterceptor.Level.BODY | ||
| } |
There was a problem hiding this comment.
API 키가 하드코딩 되어있습니다! local.properties + BuildConfig로 분리해서 관리하는 것은 개발할때 중요한 요소이니 나중에 프로젝트 하실때 참고하세요!
로깅 레벨이 BODY로 무조건 켜져 있어요. 개발 중엔 편리하지만 실제 배포 빌드에서도 모든 네트워크 요청/응답 내용이 로그에 찍히면 개인정보나 민감한 데이터가 노출될 수 있어요. 아래처럼 디버그 빌드에서만 켜는 게 좋습니다!
private val logging = HttpLoggingInterceptor().apply {
level = if (BuildConfig.DEBUG) {
HttpLoggingInterceptor.Level.BODY
} else {
HttpLoggingInterceptor.Level.NONE
}
}
| viewLifecycleOwner.lifecycleScope.launch { | ||
| sharedViewModel.homeProducts.collect { products -> | ||
| productAdapter.updateData(products) | ||
| } | ||
| } |
There was a problem hiding this comment.
WishlistFragment에서는 repeatOnLifecycle을 쓰셨는데 HomeFragment에서는 빠져 있어요. Fragment가 백그라운드에 있어도 계속 수집하게 되니 WishlistFragment와 동일한 패턴으로 맞춰주세요!
| lifecycleScope.launch { | ||
| sharedViewModel.navigateToDetail.collect { | ||
| supportFragmentManager.beginTransaction() | ||
| .replace(R.id.main_container, DetailFragment()) | ||
| .addToBackStack(null) | ||
| .commit() | ||
| } | ||
| } | ||
|
|
||
| lifecycleScope.launch { | ||
| sharedViewModel.navigateToBuyTab.collect { | ||
| binding.mainBottomNav.selectedItemId = R.id.nav_buy | ||
| } | ||
| } |
There was a problem hiding this comment.
lifecycleScope에서 바로 collect하면 Activity가 백그라운드로 가도 계속 수집해요! 화면이 안 보이는 상태에서 화면 전환이 트리거되면 예상치 못한 동작이 생길 수 있어요. repeatOnLifecycle(Lifecycle.State.STARTED)로 감싸주는 게 안전합니다!
참고로 WishlistFragment에서는 이미 repeatOnLifecycle을 올바르게 사용하고 계시니 그 패턴을 MainActivity에도 동일하게 적용하면 됩니다!
There was a problem hiding this comment.
모든 파일이 com.example.week5 패키지 하나에 몰려 있습니다..파일이 많아질수록 역할별로 패키지를 나눠두면 찾기도 쉽고 구조가 한눈에 보여요. 아래처럼 나눠보는 걸 추천드립니다!
com.example.week5
├── data
│ ├── model
│ │ ├── Product.kt
│ │ └── UserDto.kt
│ ├── remote
│ │ ├── ApiClient.kt
│ │ └── ReqResService.kt
│ └── repository
│ └── ProfileRepository.kt
├── ui
│ ├── home
│ │ └── HomeFragment.kt
│ ├── buy
│ │ └── BuyFragment.kt
│ ├── profile
│ │ ├── ProfileFragment.kt
│ │ ├── ProfileViewModel.kt
│ │ ├── ProfileEditActivity.kt
│ │ └── FollowingAdapter.kt
│ ├── wishlist
│ │ └── WishlistFragment.kt
│ ├── bag
│ │ └── BagFragment.kt
│ └── detail
│ └── DetailFragment.kt
├── shared
│ └── SharedViewModel.kt
├── adapter
│ └── ProductAdapter.kt
└── MainActivity.kt
|
감사합니다! |
📝 작업 내용
📸 스크린샷
🙏 리뷰 요구사항 (선택)