From 8713bbb0e153221feef83f333262d1355141f03b Mon Sep 17 00:00:00 2001 From: 915dbfl Date: Tue, 13 Feb 2024 19:48:13 +0900 Subject: [PATCH] =?UTF-8?q?[FEAT]=20=EB=AF=B8=EC=85=98=20=EC=A0=9C?= =?UTF-8?q?=EC=95=88=20=EC=A4=91=EB=8B=A8=20dialog=20=EC=B2=98=EB=A6=AC=20?= =?UTF-8?q?(#204)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common-ui/src/main/res/values/strings.xml | 2 ++ .../CreateSuggestionActivity.kt | 23 +++++++++++---- .../CreateSuggestionViewModel.kt | 10 +++++++ .../presentation/CreateSuggestionScreen.kt | 29 ++++++++++++++++--- 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/common-ui/src/main/res/values/strings.xml b/common-ui/src/main/res/values/strings.xml index 9a9c4230..51be28b8 100644 --- a/common-ui/src/main/res/values/strings.xml +++ b/common-ui/src/main/res/values/strings.xml @@ -163,6 +163,8 @@ 다음 제목은 필수 입력 항목 입니다. 본문은 필수 입력 항목 입니다. + 작성을 중단할까요? + 작성한 내용은 저장되지 않아요. 로그아웃 하시겠어요? diff --git a/feature/mission_suggestion/src/main/java/com/lgtm/android/mission_suggestion/ui/create_suggestion/CreateSuggestionActivity.kt b/feature/mission_suggestion/src/main/java/com/lgtm/android/mission_suggestion/ui/create_suggestion/CreateSuggestionActivity.kt index 3bef4aee..d5527de1 100644 --- a/feature/mission_suggestion/src/main/java/com/lgtm/android/mission_suggestion/ui/create_suggestion/CreateSuggestionActivity.kt +++ b/feature/mission_suggestion/src/main/java/com/lgtm/android/mission_suggestion/ui/create_suggestion/CreateSuggestionActivity.kt @@ -2,14 +2,15 @@ package com.lgtm.android.mission_suggestion.ui.create_suggestion import androidx.activity.viewModels import androidx.compose.material.MaterialTheme +import com.lgtm.android.common_ui.R import com.lgtm.android.common_ui.base.BaseActivity -import com.lgtm.android.mission_suggestion.R +import com.lgtm.android.common_ui.ui.LgtmConfirmationDialog import com.lgtm.android.mission_suggestion.databinding.ActivityCreateSuggestionBinding import com.lgtm.android.mission_suggestion.ui.create_suggestion.presentation.CreateSuggestionScreen import dagger.hilt.android.AndroidEntryPoint @AndroidEntryPoint -class CreateSuggestionActivity: BaseActivity(R.layout.activity_create_suggestion) { +class CreateSuggestionActivity: BaseActivity(com.lgtm.android.mission_suggestion.R.layout.activity_create_suggestion) { private val createSuggestionViewModel by viewModels() override fun initializeViewModel() { viewModel = createSuggestionViewModel @@ -23,15 +24,25 @@ class CreateSuggestionActivity: BaseActivity(R. private fun setComposableContent() { binding.composeView.setContent { MaterialTheme { - CreateSuggestionScreen { - setBackButtonClick() - } + CreateSuggestionScreen( + onBackButtonClick = ::setBackButtonClick, + showStopCreationDialog = ::showStopCreationDialog + ) } } } + private fun showStopCreationDialog() { + val dialog = LgtmConfirmationDialog( + title = getString(R.string.want_to_stop_creating_suggestion), + description = getString(R.string.content_will_not_be_saved), + doAfterConfirm = ::setBackButtonClick, + confirmBtnBackground = LgtmConfirmationDialog.ConfirmButtonBackground.GRAY + ) + dialog.show(supportFragmentManager, "stop_creation_dialog") + } + private fun setBackButtonClick() { finish() } - } \ No newline at end of file diff --git a/feature/mission_suggestion/src/main/java/com/lgtm/android/mission_suggestion/ui/create_suggestion/CreateSuggestionViewModel.kt b/feature/mission_suggestion/src/main/java/com/lgtm/android/mission_suggestion/ui/create_suggestion/CreateSuggestionViewModel.kt index 035259cf..bc927ded 100644 --- a/feature/mission_suggestion/src/main/java/com/lgtm/android/mission_suggestion/ui/create_suggestion/CreateSuggestionViewModel.kt +++ b/feature/mission_suggestion/src/main/java/com/lgtm/android/mission_suggestion/ui/create_suggestion/CreateSuggestionViewModel.kt @@ -44,6 +44,7 @@ class CreateSuggestionViewModel @Inject constructor( InfoType.NONE } setIsSuggestionValid() + setIsSuggestionEmpty() } /** content **/ @@ -64,6 +65,7 @@ class CreateSuggestionViewModel @Inject constructor( InfoType.NONE } setIsSuggestionValid() + setIsSuggestionEmpty() } /** check suggestion valid **/ @@ -75,6 +77,14 @@ class CreateSuggestionViewModel @Inject constructor( (_suggestionTitleTextData.value.infoStatus.value == InfoType.NONE) && (_suggestionContentTextData.value.infoStatus.value == InfoType.NONE) } + private val _isSuggestionEmpty = MutableStateFlow(true) + val isSuggestionEmpty: StateFlow = _isSuggestionEmpty + + private fun setIsSuggestionEmpty() { + _isSuggestionEmpty.value = + (_suggestionTitleTextData.value.text.value.isNullOrBlank() && _suggestionContentTextData.value.text.value.isNullOrBlank()) + } + /** create suggestion **/ private val _createSuggestionState: MutableStateFlow> = MutableStateFlow(UiState.Init) val createSuggestionState: StateFlow> diff --git a/feature/mission_suggestion/src/main/java/com/lgtm/android/mission_suggestion/ui/create_suggestion/presentation/CreateSuggestionScreen.kt b/feature/mission_suggestion/src/main/java/com/lgtm/android/mission_suggestion/ui/create_suggestion/presentation/CreateSuggestionScreen.kt index d50643b1..a63ece9c 100644 --- a/feature/mission_suggestion/src/main/java/com/lgtm/android/mission_suggestion/ui/create_suggestion/presentation/CreateSuggestionScreen.kt +++ b/feature/mission_suggestion/src/main/java/com/lgtm/android/mission_suggestion/ui/create_suggestion/presentation/CreateSuggestionScreen.kt @@ -1,5 +1,6 @@ package com.lgtm.android.mission_suggestion.ui.create_suggestion.presentation +import androidx.activity.compose.BackHandler import androidx.compose.foundation.background import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box @@ -43,7 +44,8 @@ import com.lgtm.android.mission_suggestion.ui.create_suggestion.CreateSuggestion @Composable fun CreateSuggestionScreen( viewModel: CreateSuggestionViewModel = hiltViewModel(), - onBackButtonClick: () -> Unit + onBackButtonClick: () -> Unit, + showStopCreationDialog: () -> Unit ) { ConstraintLayout( modifier = Modifier @@ -54,6 +56,7 @@ fun CreateSuggestionScreen( when(viewModel.createSuggestionState.collectAsStateWithLifecycle().value) { is UiState.Init -> { val (backButton, suggestionSection, nextButton) = createRefs() + val isSuggestionEmpty = viewModel.isSuggestionEmpty.collectAsStateWithLifecycle().value SuggestionSection( modifier = Modifier @@ -86,8 +89,18 @@ fun CreateSuggestionScreen( top.linkTo(parent.top, margin = 30.dp) start.linkTo(parent.start, margin = 20.dp) }, - onBackButtonClick = onBackButtonClick + isSuggestionEmpty = isSuggestionEmpty, + onBackButtonClick = onBackButtonClick, + showStopCreationDialog = showStopCreationDialog ) + + BackHandler { + if (!isSuggestionEmpty) { + showStopCreationDialog() + } else { + onBackButtonClick() + } + } } is UiState.Success -> { onBackButtonClick() } is UiState.Failure -> { /* no-op */ } @@ -98,9 +111,17 @@ fun CreateSuggestionScreen( @Composable fun CreateSuggestionBackButton( modifier: Modifier = Modifier, - onBackButtonClick: () -> Unit + isSuggestionEmpty: Boolean, + onBackButtonClick: () -> Unit, + showStopCreationDialog: () -> Unit ) { - BackButton(modifier) { onBackButtonClick() } + BackButton(modifier) { + if (!isSuggestionEmpty) { + showStopCreationDialog() + } else { + onBackButtonClick() + } + } } @Composable