diff --git a/app/src/main/kotlin/com/bff/wespot/AppNavGraphs.kt b/app/src/main/kotlin/com/bff/wespot/AppNavGraphs.kt index 975fc9e1c..4e7b6c545 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 40e122da5..27dfdae27 100644 --- a/app/src/main/kotlin/com/bff/wespot/CommonNavGraphNavigator.kt +++ b/app/src/main/kotlin/com/bff/wespot/CommonNavGraphNavigator.kt @@ -18,11 +18,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.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 @@ -68,8 +65,7 @@ class CommonNavGraphNavigator( VoteStorageNavigator, ReservedMessageNavigator, IndividualVoteNavigator, - ProfileEditNavigator, - MessageReportNavigator { + ProfileEditNavigator { override fun navigateUp() { navController.navigateUp() } @@ -155,8 +151,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/MessageReportScreen.kt b/feature/message/src/main/kotlin/com/bff/wespot/message/screen/MessageReportScreen.kt index 41d027171..2eb2d7e38 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/screen/MessageScreen.kt b/feature/message/src/main/kotlin/com/bff/wespot/message/screen/MessageScreen.kt index 826e39f15..c3464877c 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, ) } 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 f5cbf5f00..e6bde625a 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/report/ReportAction.kt b/feature/message/src/main/kotlin/com/bff/wespot/message/state/report/ReportAction.kt index 21f1b4cc4..2e2696b99 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 890d2649a..96307a459 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/state/storage/StorageAction.kt b/feature/message/src/main/kotlin/com/bff/wespot/message/state/storage/StorageAction.kt index 5c3633116..16aa5058a 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 de7d12417..2a420065d 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/ReportViewModel.kt b/feature/message/src/main/kotlin/com/bff/wespot/message/viewmodel/ReportViewModel.kt index 1e8f2e238..39cdaa20a 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 { /** 이미 선택된 신고 사유를 클릭한 경우 선택 해제됨. */ 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 bd5effc8f..e6ef1a5de 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) + } }