-
Notifications
You must be signed in to change notification settings - Fork 0
[QA#67] Recording Screen 수정 #68
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,40 @@ | ||
| package com.alarmy.near.presentation.feature.home.navigation | ||
|
|
||
| import android.os.Parcelable | ||
| import android.util.Log | ||
| import androidx.compose.runtime.LaunchedEffect | ||
| import androidx.hilt.navigation.compose.hiltViewModel | ||
| import androidx.lifecycle.compose.collectAsStateWithLifecycle | ||
| import androidx.navigation.NavController | ||
| import androidx.navigation.NavGraphBuilder | ||
| import androidx.navigation.NavOptions | ||
| import androidx.navigation.compose.composable | ||
| import com.alarmy.near.presentation.feature.home.HomeRoute | ||
| import com.alarmy.near.presentation.feature.home.HomeViewModel | ||
| import kotlinx.parcelize.Parcelize | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| const val HOME_FRIEND_DELETE_COMPLETE_KEY = "HOME_FRIEND_DELETE_COMPLETE_KEY" | ||
| const val HOME_RESULT_EVENT = "HOME_RESULT_EVENT" | ||
|
|
||
| @Serializable | ||
| object RouteHome | ||
|
|
||
| sealed interface HomeNavigationEvent : Parcelable { | ||
| @Parcelize | ||
| @Serializable | ||
| data class FriendDeleted( | ||
| val friendId: String, | ||
| ) : HomeNavigationEvent | ||
|
|
||
| @Parcelize | ||
| @Serializable | ||
| data class FriendReminderUpdated( | ||
| val friendId: String, | ||
| val friendReminderUpdatedAt: String?, | ||
| ) : HomeNavigationEvent | ||
| } | ||
|
|
||
| /* | ||
| * 추후 홈으로 화면 이동이 필요할 때 이 함수를 사용합니다. | ||
| * */ | ||
|
|
@@ -31,10 +52,20 @@ fun NavGraphBuilder.homeNavGraph( | |
| ) { | ||
| composable<RouteHome> { backStackEntry -> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 제미나이가 remove()로 이벤트를 소비하라는 리뷰를 주었네요! 네비게이션에서는 라우팅만 담당하는 것을 선호하여 ViewModel 사용을 자제하고 있었는데
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 연락 일시 데이터를 이전 화면에서 가지고 와서 viewModel 상태에 반영하기 위함이었습니다!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 앗 아닙니다! Navigation 쪽에서 ViewModel을 생성하는 것이 낯설어서 여쭤봤어요 :)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 답변이 늦었네요😅 lifecycleOwner는 액티비티 생명주기 변경에 대한 중복 이벤트가 막아지는 것으로 알고있습니다! 저도 안 viewModel에서 못받는 것에 대해서 테스트를 조금 해봤는데, backStackEntry.savedStateHandle 는 이벤트가 넘어 오는데, viewModel saveStateHandle는 이벤트가 안넘어오네요! 리컴포지션 문제에 대해서는 LaunchedEffect로 해결하겠습니다!
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 링크 감사합니다! 저도 더 자세히 알게 되었네요 :D |
||
| val viewModel: HomeViewModel = hiltViewModel() | ||
| val friendId: String? = backStackEntry.savedStateHandle.get<String>(HOME_FRIEND_DELETE_COMPLETE_KEY) | ||
| friendId?.let { | ||
| viewModel.deleteFriend(it) | ||
| val homeEvent = backStackEntry.savedStateHandle.get<HomeNavigationEvent>(HOME_RESULT_EVENT) | ||
| LaunchedEffect(homeEvent) { | ||
| when (homeEvent) { | ||
| is HomeNavigationEvent.FriendDeleted -> { | ||
| viewModel.deleteFriend(homeEvent.friendId) | ||
| } | ||
|
|
||
| is HomeNavigationEvent.FriendReminderUpdated -> { | ||
| viewModel.updateFriendReminder(homeEvent.friendId, homeEvent.friendReminderUpdatedAt) | ||
| } | ||
| null -> Unit | ||
| } | ||
| } | ||
|
|
||
| HomeRoute( | ||
| onShowErrorSnackBar = onShowErrorSnackBar, | ||
| onContactClick = onContactClick, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,6 +22,7 @@ import kotlinx.coroutines.flow.receiveAsFlow | |
| import kotlinx.coroutines.flow.update | ||
| import kotlinx.coroutines.launch | ||
| import java.time.LocalDate | ||
| import java.time.format.DateTimeFormatter | ||
| import javax.inject.Inject | ||
|
|
||
| @HiltViewModel | ||
|
|
@@ -92,6 +93,7 @@ class MonthlyReminderAllViewModel | |
| } | ||
| } | ||
|
|
||
| // 챙김시에 기념일이 나와야 함 | ||
| fun onRecordFriendShip(friendId: String) { | ||
| friendRepository | ||
| .recordContact(friendId) | ||
|
|
@@ -103,7 +105,14 @@ class MonthlyReminderAllViewModel | |
| if (recordedFriend != null) { | ||
| monthlyReminders.value = | ||
| monthlyReminders.value.filter { it.friendId != friendId } | ||
| completedReminders.value = listOf(recordedFriend) + completedReminders.value | ||
| completedReminders.value = listOf( | ||
| recordedFriend.copy( | ||
| nextContactAt = | ||
| LocalDate | ||
| .now() | ||
| .format(DateTimeFormatter.ofPattern("yy.MM.dd")), | ||
| ), | ||
| ) + completedReminders.value | ||
|
Comment on lines
+108
to
+115
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 챙김(record)이 완료된 친구를 |
||
| combineRemindersToUIState() | ||
| } | ||
| }.handleError(viewModelScope, _uiEvent) { exception -> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FriendProfileScreen의onClickBackButton파라미터 타입이(Friend) -> Unit으로 선언되어 있습니다. 하지만FriendProfileRoute에서는(Friend?) -> Unit타입의 콜백을 전달하고 있어 타입 불일치로 인해 컴파일 오류가 발생할 수 있습니다.BackHandler에서도 nullable한Friend객체를 전달할 수 있으므로,FriendProfileScreen의onClickBackButton타입을(Friend?) -> Unit으로 변경하여 일관성을 맞추고 잠재적인 오류를 해결하는 것이 좋습니다.