Skip to content

Conversation

@hoyaboi
Copy link
Collaborator

@hoyaboi hoyaboi commented Feb 16, 2025

Summary

  • 즐겨찾기 화면(FavoritesFragment)의기능 분리, MVVM 적용

Describe your changes

  • DegreeViewModel : FavoritesFragment에서 학과 정보를 옵저빙하기 위해, 해당 뷰모델에서 학교 정보와 학과 정보 관리
  • FavoritesFragment : 학과 정보 수정 기능, 즐겨찾기 추가된 가게 표시 기능, 필터 기능 분리

To reviewers

  • 발생한 문제 : 다른 프래그먼트 혹은 액티비티에서 즐겨찾기 상태 수정 후, 현재 프래그먼트의 즐겨찾기 ui가 바로 반영되지 않는 문제 발생(HomeFragment와 FavoritesFragment 해결 필요)

@hoyaboi hoyaboi changed the title Refactor/hoya/favorites refactor: 즐겨찾기 가게 표시 화면 기능 분리 Feb 16, 2025
@hoyaboi hoyaboi changed the title refactor: 즐겨찾기 가게 표시 화면 기능 분리 refactor: 즐겨찾기 화면 기능 분리 Feb 16, 2025
Comment on lines 327 to 330
storeAdapter = StoreAdapter(
storeItems = storeViewModel.storeItems.value ?: mutableListOf(),
favoriteItems = favoriteViewModel.favoriteState.value ?: emptyList(),
onFavoriteClicked = { storeId ->

Choose a reason for hiding this comment

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

맨 처음에는 로딩이 다 되지 않았으니까 아이템들이 항상 빈 리스트로 들어가게 되지 않을까요?

degreeViewModel = ViewModelProvider(this)[DegreeViewModel::class.java]
storeViewModel = ViewModelProvider(this)[StoreViewModel::class.java]
favoriteViewModel = ViewModelProvider(this)[FavoriteViewModel::class.java]
filterViewModel = ViewModelProvider(this)[FilterViewModel::class.java]

Choose a reason for hiding this comment

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

FilterViewModel의 역할이 무엇인가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

4가지 필터(단체, 데이트, 가성비, 제휴)의 체크 상태를(true, false) 관리하는 뷰모델입니다

import com.example.ssul.model.StoreModel

class StoreAdapter(
private var storeItems: MutableList<StoreModel>,

Choose a reason for hiding this comment

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

storeItems를 MutableList로 하신 이유가 있을까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

처음 개발할 때 즐겨찾기 화면에서 즐겨찾기 제거 시 해당 아이템을 직접 제거 하려고 MutableList로 했던 것 같은데, 지금 다시 보니 새로운 가게 리스트를 넘겨 받아 대체하는 식으로 되어있어서 크게 의미가 없네요!

Comment on lines 104 to 110
storeItems = if (isFavoriteMode) { // FavoriteFragment
newItems.filter { store ->
favoriteItems.any { favorite -> favorite.storeId == store.id && favorite.isFavorite }
}.toMutableList()
} else { // HomeFragment
newItems.toMutableList()
}

Choose a reason for hiding this comment

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

이렇게 매번 연산하지 말고 그냥 StoreModel 내에 isFavorite 같은 플래그를 두는 건 어떨까요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

좋은 것 같아요!

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.

3 participants