From 92b5f75ac97088659077579bd24f299e7325c217 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Wed, 15 Jan 2025 20:43:03 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[REFACTOR]#220=20:=20=EC=AA=BD=EC=A7=80=20?= =?UTF-8?q?=EC=8B=A0=EA=B3=A0=20=ED=8E=98=EC=9D=B4=EC=A7=80=EB=A1=9C=20?= =?UTF-8?q?=EC=A0=84=ED=99=98=ED=95=98=EB=8A=94=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/kotlin/com/bff/wespot/AppNavGraphs.kt | 2 -- .../kotlin/com/bff/wespot/CommonNavGraphNavigator.kt | 11 +---------- .../com/bff/wespot/message/screen/MessageScreen.kt | 4 ---- 3 files changed, 1 insertion(+), 16 deletions(-) diff --git a/app/src/main/kotlin/com/bff/wespot/AppNavGraphs.kt b/app/src/main/kotlin/com/bff/wespot/AppNavGraphs.kt index 975fc9e1..4e7b6c54 100644 --- a/app/src/main/kotlin/com/bff/wespot/AppNavGraphs.kt +++ b/app/src/main/kotlin/com/bff/wespot/AppNavGraphs.kt @@ -24,7 +24,6 @@ import com.bff.wespot.entire.screen.destinations.RevokeConfirmScreenDestination import com.bff.wespot.entire.screen.destinations.RevokeScreenDestination import com.bff.wespot.entire.screen.destinations.SettingScreenDestination import com.bff.wespot.message.screen.destinations.MessageEditScreenDestination -import com.bff.wespot.message.screen.destinations.MessageReportScreenDestination import com.bff.wespot.message.screen.destinations.MessageScreenDestination import com.bff.wespot.message.screen.destinations.MessageWriteScreenDestination import com.bff.wespot.message.screen.destinations.ReceiverSelectionScreenDestination @@ -76,7 +75,6 @@ object AppNavGraphs { MessageEditScreenDestination, ReceiverSelectionScreenDestination, ReservedMessageScreenDestination, - MessageReportScreenDestination, ).routedIn(this) .associateBy { it.route } } diff --git a/app/src/main/kotlin/com/bff/wespot/CommonNavGraphNavigator.kt b/app/src/main/kotlin/com/bff/wespot/CommonNavGraphNavigator.kt index f75ccb79..d25529e1 100644 --- a/app/src/main/kotlin/com/bff/wespot/CommonNavGraphNavigator.kt +++ b/app/src/main/kotlin/com/bff/wespot/CommonNavGraphNavigator.kt @@ -19,12 +19,8 @@ import com.bff.wespot.entire.screen.setting.RevokeConfirmNavigator import com.bff.wespot.entire.screen.setting.RevokeNavigator import com.bff.wespot.entire.screen.setting.SettingNavigator import com.bff.wespot.message.screen.MessageNavigator -import com.bff.wespot.message.screen.MessageReportNavigator -import com.bff.wespot.message.screen.MessageReportScreenArgs -import com.bff.wespot.message.screen.MessageScreenArgs import com.bff.wespot.message.screen.ReservedMessageNavigator import com.bff.wespot.message.screen.destinations.MessageEditScreenDestination -import com.bff.wespot.message.screen.destinations.MessageReportScreenDestination import com.bff.wespot.message.screen.destinations.MessageScreenDestination import com.bff.wespot.message.screen.destinations.MessageWriteScreenDestination import com.bff.wespot.message.screen.destinations.ReceiverSelectionScreenDestination @@ -70,8 +66,7 @@ class CommonNavGraphNavigator( VoteStorageNavigator, ReservedMessageNavigator, IndividualVoteNavigator, - ProfileEditNavigator, - MessageReportNavigator { + ProfileEditNavigator { override fun navigateUp() { navController.navigateUp() } @@ -157,8 +152,4 @@ class CommonNavGraphNavigator( override fun navigateToEntireScreen() { navController.navigate(EntireScreenDestination within navGraph) } - - override fun navigateMessageReportScreen(args: MessageReportScreenArgs) { - navController.navigate(MessageReportScreenDestination(args) within navGraph) - } } diff --git a/feature/message/src/main/kotlin/com/bff/wespot/message/screen/MessageScreen.kt b/feature/message/src/main/kotlin/com/bff/wespot/message/screen/MessageScreen.kt index 826e39f1..c3464877 100644 --- a/feature/message/src/main/kotlin/com/bff/wespot/message/screen/MessageScreen.kt +++ b/feature/message/src/main/kotlin/com/bff/wespot/message/screen/MessageScreen.kt @@ -29,7 +29,6 @@ import kotlinx.collections.immutable.persistentListOf interface MessageNavigator { fun navigateUp() - fun navigateMessageReportScreen(args: MessageReportScreenArgs) fun navigateReceiverSelectionScreen(args: ReceiverSelectionScreenArgs) fun navigateToReservedMessageScreen() } @@ -95,9 +94,6 @@ internal fun MessageScreen( navigateToReservedMessageScreen = { messageNavigator.navigateToReservedMessageScreen() }, - navigateToMessageReportScreen = { args -> - messageNavigator.navigateMessageReportScreen(args) - }, showToast = showToast, ) } From 277d18940daf3db9140a75e57ff88605bd44fad7 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Wed, 15 Jan 2025 20:44:19 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[REFACTOR]#220=20:=20=EC=8B=A0=EA=B3=A0=20?= =?UTF-8?q?=EB=B2=84=ED=8A=BC=20=ED=81=B4=EB=A6=AD=EC=8B=9C,=20MessageRepo?= =?UTF-8?q?rtScreen=20=EC=83=81=ED=83=9C=20=EB=B3=80=EA=B2=BD=20=EB=B0=8F?= =?UTF-8?q?=20=EB=85=B8=EC=B6=9C=ED=95=98=EB=8F=84=EB=A1=9D=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../screen/storage/MessageStorageScreen.kt | 36 +++++++++++++------ .../message/state/storage/StorageAction.kt | 1 + .../state/storage/StorageSideEffect.kt | 1 + .../message/viewmodel/StorageViewModel.kt | 17 ++++----- 4 files changed, 36 insertions(+), 19 deletions(-) diff --git a/feature/message/src/main/kotlin/com/bff/wespot/message/screen/storage/MessageStorageScreen.kt b/feature/message/src/main/kotlin/com/bff/wespot/message/screen/storage/MessageStorageScreen.kt index f5cbf5f0..e6bde625 100644 --- a/feature/message/src/main/kotlin/com/bff/wespot/message/screen/storage/MessageStorageScreen.kt +++ b/feature/message/src/main/kotlin/com/bff/wespot/message/screen/storage/MessageStorageScreen.kt @@ -37,6 +37,7 @@ import androidx.compose.ui.res.stringResource import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.unit.dp import androidx.compose.ui.window.Dialog +import androidx.compose.ui.window.DialogProperties import androidx.compose.ui.zIndex import androidx.hilt.navigation.compose.hiltViewModel import androidx.lifecycle.compose.LifecycleStartEffect @@ -58,7 +59,7 @@ import com.bff.wespot.message.common.SENT_MESSAGE_INDEX import com.bff.wespot.message.common.toStringWithDotSeparator import com.bff.wespot.message.component.ReservedMessageBanner import com.bff.wespot.message.model.MessageOptionType -import com.bff.wespot.message.screen.MessageReportScreenArgs +import com.bff.wespot.message.screen.MessageReportScreen import com.bff.wespot.message.state.storage.StorageAction import com.bff.wespot.message.state.storage.StorageSideEffect import com.bff.wespot.message.viewmodel.StorageViewModel @@ -84,7 +85,6 @@ fun MessageStorageScreen( type: NotificationType, messageId: Int? = null, navigateToReservedMessageScreen: () -> Unit, - navigateToMessageReportScreen: (MessageReportScreenArgs) -> Unit, showToast: (ToastState) -> Unit, viewModel: StorageViewModel = hiltViewModel(), ) { @@ -96,6 +96,7 @@ fun MessageStorageScreen( var showBottomSheet by remember { mutableStateOf(false) } var showMessageDialog by remember { mutableStateOf(false) } var showMessageOptionDialog by remember { mutableStateOf(false) } + var showMessageReportScreen by remember { mutableStateOf(false) } val networkState by viewModel.networkState.collectAsStateWithLifecycle() val context = LocalContext.current @@ -114,6 +115,10 @@ fun MessageStorageScreen( is StorageSideEffect.ShowMessageDialog -> { showMessageDialog = true } + + is StorageSideEffect.ShowReportMessageScreen -> { + showMessageReportScreen = true + } } } @@ -236,18 +241,14 @@ fun MessageStorageScreen( okButtonClick = { when (state.messageOptionType) { MessageOptionType.DELETE -> { - action( - StorageAction.OnMessageDeleteButtonClicked, - ) + action(StorageAction.OnMessageDeleteButtonClicked) } MessageOptionType.BLOCK -> { - action( - StorageAction.OnMessageBlockButtonClicked, - ) + action(StorageAction.OnMessageBlockButtonClicked) + } + MessageOptionType.REPORT -> { + action(StorageAction.OnMessageReportButtonClicked) } - MessageOptionType.REPORT -> navigateToMessageReportScreen( - MessageReportScreenArgs(state.optionButtonClickedMessageId), - ) } showMessageOptionDialog = false showBottomSheet = false @@ -257,6 +258,19 @@ fun MessageStorageScreen( ) } + if (showMessageReportScreen) { + Dialog( + onDismissRequest = { }, + properties = DialogProperties(usePlatformDefaultWidth = false), + ) { + MessageReportScreen( + messageId = state.optionButtonClickedMessageId, + showToast = showToast, + onDismiss = { showMessageReportScreen = false }, + ) + } + } + if (state.isLoading) { LoadingAnimation() } diff --git a/feature/message/src/main/kotlin/com/bff/wespot/message/state/storage/StorageAction.kt b/feature/message/src/main/kotlin/com/bff/wespot/message/state/storage/StorageAction.kt index 5c363311..16aa5058 100644 --- a/feature/message/src/main/kotlin/com/bff/wespot/message/state/storage/StorageAction.kt +++ b/feature/message/src/main/kotlin/com/bff/wespot/message/state/storage/StorageAction.kt @@ -10,6 +10,7 @@ sealed class StorageAction { data object CancelTimeTracking : StorageAction() data object OnMessageBlockButtonClicked : StorageAction() data object OnMessageDeleteButtonClicked : StorageAction() + data object OnMessageReportButtonClicked : StorageAction() data class OnStorageChipSelected(val messageType: MessageType) : StorageAction() data class OnReceivedMessageClicked(val message: ReceivedMessage) : StorageAction() data class OnSentMessageClicked(val message: Message) : StorageAction() diff --git a/feature/message/src/main/kotlin/com/bff/wespot/message/state/storage/StorageSideEffect.kt b/feature/message/src/main/kotlin/com/bff/wespot/message/state/storage/StorageSideEffect.kt index de7d1241..2a420065 100644 --- a/feature/message/src/main/kotlin/com/bff/wespot/message/state/storage/StorageSideEffect.kt +++ b/feature/message/src/main/kotlin/com/bff/wespot/message/state/storage/StorageSideEffect.kt @@ -5,4 +5,5 @@ import com.bff.wespot.ui.model.ToastState sealed class StorageSideEffect { data class ShowToast(val toastState: ToastState) : StorageSideEffect() data object ShowMessageDialog : StorageSideEffect() + data object ShowReportMessageScreen : StorageSideEffect() } diff --git a/feature/message/src/main/kotlin/com/bff/wespot/message/viewmodel/StorageViewModel.kt b/feature/message/src/main/kotlin/com/bff/wespot/message/viewmodel/StorageViewModel.kt index bd5effc8..e6ef1a5d 100644 --- a/feature/message/src/main/kotlin/com/bff/wespot/message/viewmodel/StorageViewModel.kt +++ b/feature/message/src/main/kotlin/com/bff/wespot/message/viewmodel/StorageViewModel.kt @@ -71,12 +71,9 @@ class StorageViewModel @Inject constructor( when (action) { StorageAction.StartTimeTracking -> startTimePeriodChecker() StorageAction.CancelTimeTracking -> cancelTimePeriodChecker() - StorageAction.OnMessageDeleteButtonClicked -> { - handleDeleteMessageButtonClicked() - } - StorageAction.OnMessageBlockButtonClicked -> { - handleBlockMessageButtonClicked() - } + StorageAction.OnMessageDeleteButtonClicked -> handleMessageDeleteButtonClicked() + StorageAction.OnMessageBlockButtonClicked -> handleMessageBlockButtonClicked() + StorageAction.OnMessageReportButtonClicked -> handleMessageReportButtonClicked() is StorageAction.OnStorageChipSelected -> { when (action.messageType) { MessageType.SENT -> { @@ -216,7 +213,7 @@ class StorageViewModel @Inject constructor( } } - private fun handleDeleteMessageButtonClicked() = intent { + private fun handleMessageDeleteButtonClicked() = intent { viewModelScope.launch { messageStorageRepository.deleteMessage(state.optionButtonClickedMessageId) .onSuccess { @@ -241,7 +238,7 @@ class StorageViewModel @Inject constructor( } } - private fun handleBlockMessageButtonClicked() = intent { + private fun handleMessageBlockButtonClicked() = intent { viewModelScope.launch { messageStorageRepository.blockMessage(state.optionButtonClickedMessageId) .onSuccess { @@ -261,4 +258,8 @@ class StorageViewModel @Inject constructor( } } } + + private fun handleMessageReportButtonClicked() = intent { + postSideEffect(StorageSideEffect.ShowReportMessageScreen) + } } From 27730e75c0d1923312ad37b9bc3860771df78f93 Mon Sep 17 00:00:00 2001 From: jeongjaino Date: Wed, 15 Jan 2025 20:45:01 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[REFACTOR]#220=20:=20MessageReportScreen=20?= =?UTF-8?q?->=20Dialog=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../message/screen/MessageReportScreen.kt | 29 ++++++++----------- .../message/state/report/ReportAction.kt | 1 + .../message/state/report/ReportUiState.kt | 2 +- .../message/viewmodel/ReportViewModel.kt | 18 +++++++----- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/feature/message/src/main/kotlin/com/bff/wespot/message/screen/MessageReportScreen.kt b/feature/message/src/main/kotlin/com/bff/wespot/message/screen/MessageReportScreen.kt index 41d02717..2eb2d7e3 100644 --- a/feature/message/src/main/kotlin/com/bff/wespot/message/screen/MessageReportScreen.kt +++ b/feature/message/src/main/kotlin/com/bff/wespot/message/screen/MessageReportScreen.kt @@ -16,6 +16,7 @@ import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Scaffold import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -38,27 +39,17 @@ import com.bff.wespot.ui.component.ListBottomGradient import com.bff.wespot.ui.component.WSSelectionItem import com.bff.wespot.ui.model.ToastState import com.bff.wespot.ui.util.handleSideEffect -import com.ramcosta.composedestinations.annotation.Destination import kotlinx.collections.immutable.persistentListOf import org.orbitmvi.orbit.compose.collectAsState import org.orbitmvi.orbit.compose.collectSideEffect -interface MessageReportNavigator { - fun navigateUp() - fun popUpToMessageScreen() -} - -data class MessageReportScreenArgs( - val messageId: Int, -) - @OptIn(ExperimentalMaterial3Api::class) -@Destination(navArgsDelegate = MessageReportScreenArgs::class) @Composable fun MessageReportScreen( viewModel: ReportViewModel = hiltViewModel(), + messageId: Int, showToast: (ToastState) -> Unit, - navigator: MessageReportNavigator, + onDismiss: () -> Unit, ) { val scrollState = rememberScrollState() @@ -69,9 +60,7 @@ fun MessageReportScreen( viewModel.collectSideEffect { when (it) { - ReportSideEffect.NavigateToMessage -> { - navigator.popUpToMessageScreen() - } + ReportSideEffect.NavigateToMessage -> onDismiss() is ReportSideEffect.ShowToast -> { showToast( @@ -90,7 +79,7 @@ fun MessageReportScreen( WSTopBar( title = stringResource(id = R.string.report_title), canNavigateBack = true, - navigateUp = navigator::navigateUp, + navigateUp = onDismiss, ) }, ) { innerPadding -> @@ -170,7 +159,9 @@ fun MessageReportScreen( } Box( - modifier = Modifier.fillMaxSize().zIndex(1f), + modifier = Modifier + .fillMaxSize() + .zIndex(1f), contentAlignment = Alignment.BottomCenter, ) { ListBottomGradient(height = 120) @@ -186,4 +177,8 @@ fun MessageReportScreen( ) } } + + LaunchedEffect(Unit) { + viewModel.onAction(ReportAction.OnMessageReportScreenEntered(messageId)) + } } diff --git a/feature/message/src/main/kotlin/com/bff/wespot/message/state/report/ReportAction.kt b/feature/message/src/main/kotlin/com/bff/wespot/message/state/report/ReportAction.kt index 21f1b4cc..2e2696b9 100644 --- a/feature/message/src/main/kotlin/com/bff/wespot/message/state/report/ReportAction.kt +++ b/feature/message/src/main/kotlin/com/bff/wespot/message/state/report/ReportAction.kt @@ -4,6 +4,7 @@ import com.bff.wespot.message.model.ReportReason sealed class ReportAction { data object OnMessageReportButtonClicked : ReportAction() + data class OnMessageReportScreenEntered(val messageId: Int) : ReportAction() data class OnReportReasonSelected(val reportReason: ReportReason) : ReportAction() data class OnReportReasonChanged(val reason: String) : ReportAction() } diff --git a/feature/message/src/main/kotlin/com/bff/wespot/message/state/report/ReportUiState.kt b/feature/message/src/main/kotlin/com/bff/wespot/message/state/report/ReportUiState.kt index 890d2649..96307a45 100644 --- a/feature/message/src/main/kotlin/com/bff/wespot/message/state/report/ReportUiState.kt +++ b/feature/message/src/main/kotlin/com/bff/wespot/message/state/report/ReportUiState.kt @@ -3,7 +3,7 @@ package com.bff.wespot.message.state.report import com.bff.wespot.message.model.ReportReason data class ReportUiState( - val messageId: Int, + val messageId: Int = -1, val reportReason: ReportReason = ReportReason(), val inputReportReason: String = "", ) diff --git a/feature/message/src/main/kotlin/com/bff/wespot/message/viewmodel/ReportViewModel.kt b/feature/message/src/main/kotlin/com/bff/wespot/message/viewmodel/ReportViewModel.kt index 1e8f2e23..39cdaa20 100644 --- a/feature/message/src/main/kotlin/com/bff/wespot/message/viewmodel/ReportViewModel.kt +++ b/feature/message/src/main/kotlin/com/bff/wespot/message/viewmodel/ReportViewModel.kt @@ -1,6 +1,5 @@ package com.bff.wespot.message.viewmodel -import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.viewModelScope import com.bff.wespot.common.extension.onNetworkFailure import com.bff.wespot.domain.repository.CommonRepository @@ -24,22 +23,27 @@ import javax.inject.Inject @HiltViewModel class ReportViewModel @Inject constructor( private val commonRepository: CommonRepository, - savedStateHandle: SavedStateHandle, ) : BaseViewModel(), ContainerHost { - override val container = container( - ReportUiState( - messageId = savedStateHandle["messageId"] ?: -1, - ), - ) + override val container = container(ReportUiState()) fun onAction(action: ReportAction) { when (action) { + is ReportAction.OnMessageReportScreenEntered -> { + handleMessageReportScreenEntered(action.messageId) + } is ReportAction.OnReportReasonSelected -> handleReportReasonSelected(action.reportReason) is ReportAction.OnReportReasonChanged -> handleReportReasonChanged(action.reason) ReportAction.OnMessageReportButtonClicked -> reportMessage() } } + private fun handleMessageReportScreenEntered(messageId: Int) = intent { + /** MessageReportScreen이 Dialog로, 보이지 않아도 상태가 유지되므로 진입시에 상태를 초기화 한다.*/ + reduce { + ReportUiState(messageId = messageId) + } + } + private fun handleReportReasonSelected(reportReason: ReportReason) = intent { reduce { /** 이미 선택된 신고 사유를 클릭한 경우 선택 해제됨. */