From c487625178d9087c4ebafe81d575c31a50ba7182 Mon Sep 17 00:00:00 2001 From: LEE YOU BIN Date: Mon, 14 Oct 2024 09:06:37 +0900 Subject: [PATCH] [feature/#871] change ui state --- .../feature/mypage/model/MyPageUiState.kt | 2 - .../feature/mypage/mypage/MyPageActivity.kt | 67 ++++++++++++------- .../feature/mypage/mypage/MyPageViewModel.kt | 12 ++-- 3 files changed, 47 insertions(+), 34 deletions(-) diff --git a/feature/mypage/src/main/java/org/sopt/official/feature/mypage/model/MyPageUiState.kt b/feature/mypage/src/main/java/org/sopt/official/feature/mypage/model/MyPageUiState.kt index 2a86a59ff..9c696e728 100644 --- a/feature/mypage/src/main/java/org/sopt/official/feature/mypage/model/MyPageUiState.kt +++ b/feature/mypage/src/main/java/org/sopt/official/feature/mypage/model/MyPageUiState.kt @@ -27,7 +27,6 @@ package org.sopt.official.feature.mypage.model import androidx.compose.runtime.Immutable import androidx.compose.runtime.Stable import org.sopt.official.auth.model.UserActiveState -import org.sopt.official.feature.mypage.mypage.MyPageAction @Stable sealed interface MyPageUiState { @@ -38,7 +37,6 @@ sealed interface MyPageUiState { @Immutable data class Authenticated( val activeState: UserActiveState, - val action: MyPageAction? = null ) : MyPageUiState @Immutable diff --git a/feature/mypage/src/main/java/org/sopt/official/feature/mypage/mypage/MyPageActivity.kt b/feature/mypage/src/main/java/org/sopt/official/feature/mypage/mypage/MyPageActivity.kt index 1dd871afb..88410d2bf 100644 --- a/feature/mypage/src/main/java/org/sopt/official/feature/mypage/mypage/MyPageActivity.kt +++ b/feature/mypage/src/main/java/org/sopt/official/feature/mypage/mypage/MyPageActivity.kt @@ -41,6 +41,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material3.Scaffold +import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.getValue import androidx.compose.runtime.remember @@ -83,6 +84,7 @@ class MyPageActivity : AppCompatActivity() { val lifecycleOwner = LocalLifecycleOwner.current val state by viewModel.state.collectAsStateWithLifecycle() + val myPageAction by viewModel.action.collectAsStateWithLifecycle() val scrollState = rememberScrollState() val serviceSectionItems = remember { @@ -194,31 +196,6 @@ class MyPageActivity : AppCompatActivity() { Spacer(modifier = Modifier.height(16.dp)) when (state) { is MyPageUiState.Authenticated -> { - when ((state as MyPageUiState.Authenticated).action) { - MyPageAction.CLEAR_SOPTAMP -> { - MyPageDialog( - onDismissRequest = viewModel::onDismiss, - title = "미션을 초기화 하실건가요?", - subTitle = "사진, 메모가 삭제되고\n전체 미션이 미완료상태로 초기화됩니다.", - negativeText = "취소", - positiveText = "초기화", - onPositiveButtonClick = viewModel::resetSoptamp - ) - } - - MyPageAction.LOGOUT -> { - MyPageDialog( - onDismissRequest = viewModel::onDismiss, - title = "로그아웃", - subTitle = "정말 로그아웃을 하실 건가요?", - negativeText = "취소", - positiveText = "로그아웃", - onPositiveButtonClick = viewModel::logOut - ) - } - - else -> {} - } MyPageSection(items = notificationSectionItems) Spacer(modifier = Modifier.height(16.dp)) MyPageSection(items = soptampSectionItems) @@ -234,6 +211,14 @@ class MyPageActivity : AppCompatActivity() { } Spacer(modifier = Modifier.height(32.dp)) } + if (myPageAction != null) { + ShowMyPageDialog( + action = myPageAction ?: return@Scaffold, + onDismissRequest = viewModel::onDismiss, + onClearSoptampClick = viewModel::resetSoptamp, + onLogoutClick = viewModel::logOut + ) + } } } } @@ -250,3 +235,35 @@ class MyPageActivity : AppCompatActivity() { } } } + +@Composable +private fun ShowMyPageDialog( + action: MyPageAction, + onDismissRequest: () -> Unit, + onClearSoptampClick: () -> Unit, + onLogoutClick: () -> Unit +) { + when (action) { + MyPageAction.CLEAR_SOPTAMP -> { + MyPageDialog( + onDismissRequest = onDismissRequest, + title = "미션을 초기화 하실건가요?", + subTitle = "사진, 메모가 삭제되고\n전체 미션이 미완료상태로 초기화됩니다.", + negativeText = "취소", + positiveText = "초기화", + onPositiveButtonClick = onClearSoptampClick + ) + } + + MyPageAction.LOGOUT -> { + MyPageDialog( + onDismissRequest = onDismissRequest, + title = "로그아웃", + subTitle = "정말 로그아웃을 하실 건가요?", + negativeText = "취소", + positiveText = "로그아웃", + onPositiveButtonClick = onLogoutClick + ) + } + } +} \ No newline at end of file diff --git a/feature/mypage/src/main/java/org/sopt/official/feature/mypage/mypage/MyPageViewModel.kt b/feature/mypage/src/main/java/org/sopt/official/feature/mypage/mypage/MyPageViewModel.kt index 3f7286e3a..c0f17e14f 100644 --- a/feature/mypage/src/main/java/org/sopt/official/feature/mypage/mypage/MyPageViewModel.kt +++ b/feature/mypage/src/main/java/org/sopt/official/feature/mypage/mypage/MyPageViewModel.kt @@ -33,7 +33,6 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.flow.receiveAsFlow -import kotlinx.coroutines.flow.update import kotlinx.coroutines.launch import kotlinx.coroutines.tasks.await import org.sopt.official.auth.model.UserActiveState @@ -56,6 +55,9 @@ class MyPageViewModel @Inject constructor( private val _state: MutableStateFlow = MutableStateFlow(MyPageUiState.UnInitialized) val state: StateFlow = _state.asStateFlow() + private val _action = MutableStateFlow(null) + val action: StateFlow = _action.asStateFlow() + private val _finish = Channel() val finish = _finish.receiveAsFlow() @@ -89,14 +91,10 @@ class MyPageViewModel @Inject constructor( } fun showDialogState(action: MyPageAction) { - _state.update { currentState -> - (currentState as MyPageUiState.Authenticated).copy(action = action) - } + _action.value = action } fun onDismiss() { - _state.update { currentState -> - (currentState as MyPageUiState.Authenticated).copy(action = null) - } + _action.value = null } }