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

알림 페이지 리팩토링 #379

Closed

Conversation

plgafhd
Copy link
Collaborator

@plgafhd plgafhd commented Nov 18, 2024

뭐가 정답인지 잘 모르지만, 오답지라도 만들면서 고쳐나가기 위한 PR

바뀐 점

  • Normal / Refactor 상태를 구분하는 provideSNUTTAppState 생성
  • 그 외에는 전에 리팩토링 얘기하면서 얘기한 점 반영 (Route/Page 분리, UiState 관리, 네트워크/도메인 모델 분리)

특이점

  • 원래 UiState를 ViewModel에서 관리해야 하나 Paging의 경우 컴포저블 함수에서 collectAsLazyPagingItems()를 했을 때 state가 생성되므로 예외적으로 Route에서 UiState 관리
  • 아직 Navigation까지는 그냥 기존 방식 채택
  • develop과 섞이는 것을 방지하기 위해 refactor-base-branch 생성
  • 그 외 사소한 점들은 코멘트로 작성

@plgafhd plgafhd requested a review from a team as a code owner November 18, 2024 15:17
Comment on lines +112 to +113
fun getNotificationTime(context: Context, info: Notification): String {
try {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

이거 알림 시간 받아서, 현재 시간이랑 비교한 다음에 어떻게 텍스트로 띄울지 변환하는 부분인데

  • 일단 context를 제거하고 싶은 마음이 굴뚝 같았으나 어쩔 수 없었음...
  • SimpleDateFormat 쓰지 말고 다르게 하라는데 이것보다는 다른 부분이 중요하다고 생각해서 일단 보류

고치려면 고칠 수 있는 부분이라고 생각되지만 일단 PR 올리고 얘기해본 뒤에 고치기로 생각해서 그대로인 상태

@@ -258,7 +258,7 @@ class RootActivity : AppCompatActivity() {

composable2(NavigationDestination.ImportantNotice) { ImportantNoticePage() }

composable2(NavigationDestination.Notification) { NotificationPage() }
composable2(NavigationDestination.Notification) { NotificationRoute() }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

설명에 써놓은 대로, Navigation은 그대로 뒀기에 Page()가 아니라 Route()를 호출하는 언뜻 보면 이상한 상황 발생

Comment on lines +64 to +66

if (viewModel.isRefactoring()) {
NotificationPage(
Copy link
Collaborator Author

@plgafhd plgafhd Nov 18, 2024

Choose a reason for hiding this comment

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

동엽이형 말로부터 영감을 받아 refactor 상태를 알 수 있게 따로 함수로 둠
보니까 컴포저블에 의존성 주입은 안되는듯... 애초에 클래스가 아니라 함수기도 하고 (내가 방법을 못찾은 거일지도)

Comment on lines +251 to +259
@Composable
fun NotificationPage(
modifier: Modifier = Modifier,
uiState: NotificationUiState,
onBackClick: () -> Unit,
) {
Column(
modifier = Modifier
.background(SNUTTColors.White900)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

이제 여기에는 context나 navController 이런거 필요 없음

Comment on lines +283 to +288

@Composable
fun NotificationItem(notification: Notification, onClick: () -> Unit) {
val context = LocalContext.current
Column(
modifier = Modifier
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NotificationItem과, NotificationIcon은 딱히 달라진거 없고 그냥 어떤 타입을 받느냐 (네트워크/도메인 모델 분리해서) 그것만 달라지고, 함수 분리만 조금 한 정도

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

그래서 같은 이름을 갖는 함수가 2개씩 있음
NotificationPage, NotificationItem 등등..

Comment on lines +33 to +48
when (snuttAppState) {
SNUTTAppState.NORMAL -> {
notificationRepository.getNotificationResultStream()
.cachedIn(viewModelScope)
.collect {
_notificationResult.emit(it)
}
}
SNUTTAppState.REFACTOR -> {
notificationRepository.getNotificationListStream()
.cachedIn(viewModelScope)
.collect {
_notificationList.emit(it)
}
}
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

여기도 마찬가지, 경우에 따라 다른 타입의 PagingData를 받아야 하므로 거의 비슷한 부분이 중복으로 2개

@JuTaK97
Copy link
Collaborator

JuTaK97 commented Nov 19, 2024

벌써기대되는군

Comment on lines +40 to +44
@Provides
@Singleton
fun provideSNUTTAppState(): SNUTTAppState {
return SNUTTAppState.REFACTOR
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

이것도 상관없긴 한데 flavor dimension 새로 하나 만들어서 BuildConfig로 관리해도 좋을듯ㅋㅋ

Comment on lines 54 to 71
fun NotificationRoute(
modifier: Modifier = Modifier,
viewModel: NotificationsViewModel = hiltViewModel()
) {
val navController = LocalNavController.current
if (viewModel.isRefactoring()) {
NotificationPage(
onBackClick = {
if (navController.currentDestination?.route == NavigationDestination.Notification) {
navController.popBackStack()
}
},
modifier = modifier,
)
} else {
NotificationPage()
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

새로 생기는 UI 코드들도, flavor 다르게 빌드하고 아예 다른 폴더에 격리시켜버리는 건 어떄

@plgafhd plgafhd closed this Nov 24, 2024
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.

2 participants