Skip to content

Commit

Permalink
[FEAT] 미션 제안 중단 dialog 처리 (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
915dbfl committed Feb 13, 2024
1 parent 27429f6 commit 8713bbb
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
2 changes: 2 additions & 0 deletions common-ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@
<string name="suggestion_next">다음</string>
<string name="title_required">제목은 필수 입력 항목 입니다.</string>
<string name="content_required">본문은 필수 입력 항목 입니다.</string>
<string name="want_to_stop_creating_suggestion">작성을 중단할까요?</string>
<string name="content_will_not_be_saved">작성한 내용은 저장되지 않아요.</string>

<!-- dialog -->
<string name="want_to_logout">로그아웃 하시겠어요?</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ActivityCreateSuggestionBinding>(R.layout.activity_create_suggestion) {
class CreateSuggestionActivity: BaseActivity<ActivityCreateSuggestionBinding>(com.lgtm.android.mission_suggestion.R.layout.activity_create_suggestion) {
private val createSuggestionViewModel by viewModels<CreateSuggestionViewModel>()
override fun initializeViewModel() {
viewModel = createSuggestionViewModel
Expand All @@ -23,15 +24,25 @@ class CreateSuggestionActivity: BaseActivity<ActivityCreateSuggestionBinding>(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()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class CreateSuggestionViewModel @Inject constructor(
InfoType.NONE
}
setIsSuggestionValid()
setIsSuggestionEmpty()
}

/** content **/
Expand All @@ -64,6 +65,7 @@ class CreateSuggestionViewModel @Inject constructor(
InfoType.NONE
}
setIsSuggestionValid()
setIsSuggestionEmpty()
}

/** check suggestion valid **/
Expand All @@ -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<Boolean> = _isSuggestionEmpty

private fun setIsSuggestionEmpty() {
_isSuggestionEmpty.value =
(_suggestionTitleTextData.value.text.value.isNullOrBlank() && _suggestionContentTextData.value.text.value.isNullOrBlank())
}

/** create suggestion **/
private val _createSuggestionState: MutableStateFlow<UiState<CreateSuggestionResponseVO>> = MutableStateFlow(UiState.Init)
val createSuggestionState: StateFlow<UiState<CreateSuggestionResponseVO>>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 */ }
Expand All @@ -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
Expand Down

0 comments on commit 8713bbb

Please sign in to comment.