From 2c7d14f69beb445faf511d095076867e102254a6 Mon Sep 17 00:00:00 2001 From: GunHyung Ham Date: Fri, 23 Feb 2024 15:08:02 +0900 Subject: [PATCH 1/5] =?UTF-8?q?[refactor]=20:=20=EC=A7=80=ED=95=98?= =?UTF-8?q?=EC=B2=A0=20=EC=82=AC=EC=9A=A9=EC=9E=90=EA=B0=80=20=EC=9E=85?= =?UTF-8?q?=EB=A0=A5=ED=95=9C=20=ED=85=8D=EC=8A=A4=ED=8A=B8=EB=A7=8C=20?= =?UTF-8?q?=ED=9D=B0=EC=83=89=EC=9C=BC=EB=A1=9C=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/moya/funch/CreateProflieScreen.kt | 48 +++++++++++++++---- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/feature/profile/src/main/java/com/moya/funch/CreateProflieScreen.kt b/feature/profile/src/main/java/com/moya/funch/CreateProflieScreen.kt index 95f51174..67406cfd 100644 --- a/feature/profile/src/main/java/com/moya/funch/CreateProflieScreen.kt +++ b/feature/profile/src/main/java/com/moya/funch/CreateProflieScreen.kt @@ -45,7 +45,10 @@ import androidx.compose.ui.layout.boundsInWindow import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.platform.LocalFocusManager import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.SpanStyle +import androidx.compose.ui.text.buildAnnotatedString import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.withStyle import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.hilt.navigation.compose.hiltViewModel @@ -540,7 +543,8 @@ private fun SubwayRow( is SubwayTextFieldState.Success -> { HorizontalSubwayStations( subwayStations = subwayStations, - onSubwayStationChange = onSubwayStationChange + onSubwayStationChange = onSubwayStationChange, + text = subwayStation ) } @@ -558,7 +562,8 @@ private fun SubwayRow( is SubwayTextFieldState.Typing -> { HorizontalSubwayStations( subwayStations = subwayStations, - onSubwayStationChange = onSubwayStationChange + onSubwayStationChange = onSubwayStationChange, + text = subwayStation ) } } @@ -567,7 +572,11 @@ private fun SubwayRow( } @Composable -private fun HorizontalSubwayStations(subwayStations: List, onSubwayStationChange: (String) -> Unit) { +private fun HorizontalSubwayStations( + subwayStations: List, + onSubwayStationChange: (String) -> Unit, + text: String +) { val focusManager = LocalFocusManager.current Spacer(modifier = Modifier.height(4.dp)) @@ -578,6 +587,30 @@ private fun HorizontalSubwayStations(subwayStations: List, onSubw horizontalArrangement = Arrangement.spacedBy(4.dp) ) { subwayStations.forEach { station -> + val annotatedText = buildAnnotatedString { + val startIndex = station.name.indexOf(text) + if (startIndex >= 0) { + val endIndex = startIndex + text.length + if (startIndex > 0) { + withStyle(style = SpanStyle(color = Gray500)) { + append(station.name.substring(0, startIndex)) + } + } + withStyle(style = SpanStyle(color = White)) { + append(station.name.substring(startIndex, endIndex)) + } + if (endIndex < station.name.length) { + withStyle(style = SpanStyle(color = Gray500)) { + append(station.name.substring(endIndex)) + } + } + } else { + withStyle(style = SpanStyle(color = Gray500)) { + append(station.name) + } + } + } + Box( modifier = Modifier .background( @@ -596,8 +629,7 @@ private fun HorizontalSubwayStations(subwayStations: List, onSubw .padding(8.dp) ) { Text( - text = station.name, - color = White, + text = annotatedText, style = FunchTheme.typography.b ) } @@ -663,7 +695,7 @@ private fun Preview1() { @Composable private fun Preview2() { FunchTheme { - var text by remember { mutableStateOf("삼") } + var text by remember { mutableStateOf("삼성") } Surface( modifier = Modifier @@ -676,8 +708,8 @@ private fun Preview2() { isKeyboardVisible = {}, textFieldState = SubwayTextFieldState.Typing, subwayStations = listOf( - SubwayStation("삼성역"), - SubwayStation("삼성중앙역") + SubwayStation("삼성"), + SubwayStation("삼성중앙") ), scrollState = rememberScrollState() ) From c30ad8cb7dfa34f8c4df2d0b8740cde3c7e16bcc Mon Sep 17 00:00:00 2001 From: GunHyung Ham Date: Fri, 23 Feb 2024 17:50:27 +0900 Subject: [PATCH 2/5] =?UTF-8?q?[feat]=20:=20FunchDialog=20UI=20=EC=A0=9C?= =?UTF-8?q?=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/moya/funch/ui/FunchDialog.kt | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 core/designsystem/src/main/java/com/moya/funch/ui/FunchDialog.kt diff --git a/core/designsystem/src/main/java/com/moya/funch/ui/FunchDialog.kt b/core/designsystem/src/main/java/com/moya/funch/ui/FunchDialog.kt new file mode 100644 index 00000000..1877afa1 --- /dev/null +++ b/core/designsystem/src/main/java/com/moya/funch/ui/FunchDialog.kt @@ -0,0 +1,79 @@ +package com.moya.funch.ui + +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import com.moya.funch.theme.FunchTheme +import com.moya.funch.theme.LocalBackgroundTheme + +@Composable +fun FunchDialog( + title: String, + text: String, + dismissText: String, + confirmText: String, + onDismiss: () -> Unit, + onConfirm: () -> Unit +) { + AlertDialog( + title = { + Text(text = title) + }, + titleContentColor = Color(0xFFE6E0E9), + text = { + Text(text = text) + }, + textContentColor = Color(0xFFCAC4D0), + containerColor = Color(0xFF2B2930), + confirmButton = { + Box( + modifier = Modifier + .clickable(onClick = onConfirm) + .padding(vertical = 10.dp, horizontal = 12.dp) + ) { + Text( + text = confirmText, + color = Color(0xFFD0BCFF) + ) + } + }, + onDismissRequest = { onDismiss() }, + dismissButton = { + Box( + modifier = Modifier + .clickable(onClick = onDismiss) + .padding(vertical = 10.dp, horizontal = 12.dp) + ) { + Text( + text = dismissText, + color = Color(0xFFD0BCFF) + ) + } + } + ) +} + +@Preview +@Composable +private fun Preview1() { + FunchTheme { + Surface(color = LocalBackgroundTheme.current.color) { + FunchDialog( + title = "프로필 삭제하기", + text = "기존 프로필이 삭제되고 복구가 불가능해요.\n정말 삭제하실 건가요?", + dismissText = "취소하기", + confirmText = "삭제하기", + onDismiss = {}, + onConfirm = {} + ) + } + } +} From 3949cf40b824360f74fd6b93bf58853de2e5bfd0 Mon Sep 17 00:00:00 2001 From: GunHyung Ham Date: Fri, 23 Feb 2024 17:51:06 +0900 Subject: [PATCH 3/5] =?UTF-8?q?[feat]=20:=20=EB=8B=A4=EC=9D=B4=EC=96=BC?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=20string=20res=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- feature/profile/src/main/res/values/strings.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/feature/profile/src/main/res/values/strings.xml b/feature/profile/src/main/res/values/strings.xml index de631896..9767d2fa 100644 --- a/feature/profile/src/main/res/values/strings.xml +++ b/feature/profile/src/main/res/values/strings.xml @@ -1,5 +1,6 @@ + 프로필 만들기 프로필을 만들어 공통점을 찾을 수 있어요 최대 %d글자 @@ -7,4 +8,9 @@ 가까운 지하철역 검색 존재하지 않는 지하철역이에요 이제 매칭할래요! + + 프로필 삭제하기 + 기존 프로필이 삭제되고 복구가 불가능해요.\n정말 삭제하실 건가요? + 취소하기 + 삭제하기 From 96096e46a3713b92f1eec8583408d7651f844ea1 Mon Sep 17 00:00:00 2001 From: GunHyung Ham Date: Fri, 23 Feb 2024 17:52:14 +0900 Subject: [PATCH 4/5] =?UTF-8?q?[feat]=20:=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20service,=20data,=20do?= =?UTF-8?q?main=20=EC=98=81=EC=97=AD=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/moya/funch/di/MemberModule.kt | 6 ++++++ .../datasource/remote/RemoteUserDataSource.kt | 2 ++ .../remote/RemoteUserDataSourceImpl.kt | 8 ++++++++ .../funch/repository/MemberRepositoryImpl.kt | 4 ++++ .../moya/funch/repository/MemberRepository.kt | 2 ++ .../funch/usecase/DeleteUserProfileUseCase.kt | 16 ++++++++++++++++ .../moya/funch/network/service/MemberService.kt | 4 ++++ 7 files changed, 42 insertions(+) create mode 100644 core/domain/src/main/java/com/moya/funch/usecase/DeleteUserProfileUseCase.kt diff --git a/app/src/main/java/com/moya/funch/di/MemberModule.kt b/app/src/main/java/com/moya/funch/di/MemberModule.kt index 5e17b5f2..3365579a 100644 --- a/app/src/main/java/com/moya/funch/di/MemberModule.kt +++ b/app/src/main/java/com/moya/funch/di/MemberModule.kt @@ -4,6 +4,8 @@ import com.moya.funch.repository.MemberRepository import com.moya.funch.repository.MemberRepositoryImpl import com.moya.funch.usecase.CreateUserProfileUseCase import com.moya.funch.usecase.CreateUserProfileUseCaseImpl +import com.moya.funch.usecase.DeleteUserProfileUseCase +import com.moya.funch.usecase.DeleteUserProfileUseCaseImpl import com.moya.funch.usecase.LoadUserProfileUseCase import com.moya.funch.usecase.LoadUserProfileUseCaseImpl import com.moya.funch.usecase.LoadViewCountUseCase @@ -32,6 +34,10 @@ object MemberModule { @Binds @Singleton fun bindCreateUserProfileUseCase(useCase: CreateUserProfileUseCaseImpl): CreateUserProfileUseCase + + @Binds + @Singleton + fun bindDeleteUserProfileUseCase(useCase: DeleteUserProfileUseCaseImpl): DeleteUserProfileUseCase } @Module diff --git a/core/data/src/main/java/com/moya/funch/datasource/remote/RemoteUserDataSource.kt b/core/data/src/main/java/com/moya/funch/datasource/remote/RemoteUserDataSource.kt index d231c548..c377729c 100644 --- a/core/data/src/main/java/com/moya/funch/datasource/remote/RemoteUserDataSource.kt +++ b/core/data/src/main/java/com/moya/funch/datasource/remote/RemoteUserDataSource.kt @@ -5,4 +5,6 @@ import com.moya.funch.model.ProfileModel interface RemoteUserDataSource : UserDataSource { suspend fun createUserProfile(userModel: ProfileModel): Result + + suspend fun deleteUserProfile(): Result } diff --git a/core/data/src/main/java/com/moya/funch/datasource/remote/RemoteUserDataSourceImpl.kt b/core/data/src/main/java/com/moya/funch/datasource/remote/RemoteUserDataSourceImpl.kt index 04d5fa9e..cf09c48d 100644 --- a/core/data/src/main/java/com/moya/funch/datasource/remote/RemoteUserDataSourceImpl.kt +++ b/core/data/src/main/java/com/moya/funch/datasource/remote/RemoteUserDataSourceImpl.kt @@ -33,4 +33,12 @@ class RemoteUserDataSourceImpl @Inject constructor( memberService.createMember(request).data }.mapCatching { it.toModel() } } + + override suspend fun deleteUserProfile(): Result { + return runCatching { + memberService.deleteMember(userDataStore.userId).message + }.onSuccess { + userDataStore.clear() + } + } } diff --git a/core/data/src/main/java/com/moya/funch/repository/MemberRepositoryImpl.kt b/core/data/src/main/java/com/moya/funch/repository/MemberRepositoryImpl.kt index d41cf2ae..a755db7e 100644 --- a/core/data/src/main/java/com/moya/funch/repository/MemberRepositoryImpl.kt +++ b/core/data/src/main/java/com/moya/funch/repository/MemberRepositoryImpl.kt @@ -41,4 +41,8 @@ class MemberRepositoryImpl @Inject constructor( it.toDomain() } } + + override suspend fun deleteUserProfile(): Result { + return remoteUserDataSource.deleteUserProfile() + } } diff --git a/core/domain/src/main/java/com/moya/funch/repository/MemberRepository.kt b/core/domain/src/main/java/com/moya/funch/repository/MemberRepository.kt index edeb5043..f5f24fc0 100644 --- a/core/domain/src/main/java/com/moya/funch/repository/MemberRepository.kt +++ b/core/domain/src/main/java/com/moya/funch/repository/MemberRepository.kt @@ -10,4 +10,6 @@ interface MemberRepository { suspend fun fetchUserViewCount(): Result suspend fun fetchMemberProfile(id: String): Result + + suspend fun deleteUserProfile(): Result } diff --git a/core/domain/src/main/java/com/moya/funch/usecase/DeleteUserProfileUseCase.kt b/core/domain/src/main/java/com/moya/funch/usecase/DeleteUserProfileUseCase.kt new file mode 100644 index 00000000..8df65780 --- /dev/null +++ b/core/domain/src/main/java/com/moya/funch/usecase/DeleteUserProfileUseCase.kt @@ -0,0 +1,16 @@ +package com.moya.funch.usecase + +import com.moya.funch.repository.MemberRepository +import javax.inject.Inject + +class DeleteUserProfileUseCaseImpl @Inject constructor( + private val memberRepository: MemberRepository +) : DeleteUserProfileUseCase { + override suspend operator fun invoke(): Result { + return memberRepository.deleteUserProfile() + } +} + +fun interface DeleteUserProfileUseCase { + suspend operator fun invoke(): Result +} diff --git a/core/network/src/main/java/com/moya/funch/network/service/MemberService.kt b/core/network/src/main/java/com/moya/funch/network/service/MemberService.kt index bc97005e..7ebb15fa 100644 --- a/core/network/src/main/java/com/moya/funch/network/service/MemberService.kt +++ b/core/network/src/main/java/com/moya/funch/network/service/MemberService.kt @@ -4,6 +4,7 @@ import com.moya.funch.network.dto.request.MemberRequest import com.moya.funch.network.dto.response.BaseResponse import com.moya.funch.network.dto.response.member.MemberResponse import retrofit2.http.Body +import retrofit2.http.DELETE import retrofit2.http.GET import retrofit2.http.POST import retrofit2.http.Path @@ -19,4 +20,7 @@ interface MemberService { @GET("api/v1/members") suspend fun findMemberByDeviceNumber(@Query("deviceNumber") deviceNumber: String): BaseResponse + + @DELETE("api/v1/members/{id}") + suspend fun deleteMember(@Path("id") id: String): BaseResponse } From 87347ff6cae3cc95213393889bf0c4dca239eb11 Mon Sep 17 00:00:00 2001 From: GunHyung Ham Date: Fri, 23 Feb 2024 17:52:46 +0900 Subject: [PATCH 5/5] =?UTF-8?q?[feat]=20:=20=ED=94=84=EB=A1=9C=ED=95=84=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=20=EA=B8=B0=EB=8A=A5=20=EC=A0=9C=EC=9E=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/moya/funch/navigation/FunchNavHost.kt | 3 +- .../java/com/moya/funch/MyProfileScreen.kt | 89 ++++++++++++++++--- .../java/com/moya/funch/MyProfileViewModel.kt | 24 ++++- .../funch/navigation/MyProfileNavigatoin.kt | 11 ++- 4 files changed, 109 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/moya/funch/navigation/FunchNavHost.kt b/app/src/main/java/com/moya/funch/navigation/FunchNavHost.kt index 0e0355ba..5dbc3c7f 100644 --- a/app/src/main/java/com/moya/funch/navigation/FunchNavHost.kt +++ b/app/src/main/java/com/moya/funch/navigation/FunchNavHost.kt @@ -20,7 +20,8 @@ fun FunchNavHost(hasProfile: Boolean, navController: NavHostController = remembe with(navController) { profileGraph( onNavigateToHome = ::onNavigateToHome, - onCloseMyProfile = ::onCloseMyProfile + onCloseMyProfile = ::onCloseMyProfile, + onNavigateCreateProfile = ::navigateToCreateProfileFromMyProfile ) homeScreen( onNavigateToMatching = ::onNavigateToMatching, diff --git a/feature/profile/src/main/java/com/moya/funch/MyProfileScreen.kt b/feature/profile/src/main/java/com/moya/funch/MyProfileScreen.kt index 08a8180b..2ac76fc0 100644 --- a/feature/profile/src/main/java/com/moya/funch/MyProfileScreen.kt +++ b/feature/profile/src/main/java/com/moya/funch/MyProfileScreen.kt @@ -2,6 +2,7 @@ package com.moya.funch import androidx.compose.foundation.Image import androidx.compose.foundation.background +import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column @@ -12,17 +13,26 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.verticalScroll import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable +import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color +import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Devices import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp @@ -40,27 +50,44 @@ import com.moya.funch.entity.SubwayLine import com.moya.funch.entity.SubwayStation import com.moya.funch.entity.profile.Profile import com.moya.funch.icon.FunchIconAsset +import com.moya.funch.profile.R import com.moya.funch.theme.FunchTheme import com.moya.funch.theme.Gray400 import com.moya.funch.theme.Gray800 import com.moya.funch.theme.Gray900 import com.moya.funch.theme.LocalBackgroundTheme import com.moya.funch.theme.White +import com.moya.funch.ui.FunchDialog import com.moya.funch.ui.FunchTopBar import com.moya.funch.uimodel.ProfileLabel @Composable -internal fun MyProfileRoute(viewModel: MyProfileViewModel = hiltViewModel(), onCloseMyProfile: () -> Unit) { +internal fun MyProfileRoute( + viewModel: MyProfileViewModel = hiltViewModel(), + onCloseMyProfile: () -> Unit, + onNavigateCreateProfile: () -> Unit +) { val uiState = viewModel.uiState.collectAsState().value + LaunchedEffect(Unit) { + viewModel.event.collect { event -> + if (event is MyProfileEvent.DeleteProfile) { + onNavigateCreateProfile() + } + } + } + MyProfileScreen( uiState = uiState, - onCloseMyProfile = onCloseMyProfile + onCloseMyProfile = onCloseMyProfile, + onDeleteProfile = viewModel::deleteUserProfile ) } @Composable -internal fun MyProfileScreen(uiState: MyProfileUiState, onCloseMyProfile: () -> Unit) { +internal fun MyProfileScreen(uiState: MyProfileUiState, onCloseMyProfile: () -> Unit, onDeleteProfile: () -> Unit) { + var showDialog by remember { mutableStateOf(false) } + Column( modifier = Modifier .fillMaxSize() @@ -80,18 +107,17 @@ internal fun MyProfileScreen(uiState: MyProfileUiState, onCloseMyProfile: () -> ), onClickLeadingIcon = onCloseMyProfile ) - Box( + Spacer(modifier = Modifier.height(8.dp)) + Column( modifier = Modifier - .padding( - top = 8.dp, - bottom = 14.dp, - start = 20.dp, - end = 20.dp - ) + .fillMaxSize() + .verticalScroll(state = rememberScrollState()), + horizontalAlignment = Alignment.CenterHorizontally ) { Column( modifier = Modifier - .fillMaxSize() + .width(320.dp) + .heightIn(min = 477.dp) .clip(FunchTheme.shapes.large) .background( color = Gray800, @@ -116,8 +142,40 @@ internal fun MyProfileScreen(uiState: MyProfileUiState, onCloseMyProfile: () -> } } } + Spacer(modifier = Modifier.height(20.dp)) + Box( + modifier = Modifier + .background( + color = Gray800, + shape = FunchTheme.shapes.small + ) + .clip(FunchTheme.shapes.small) + .clickable( + onClick = { showDialog = true } + ) + .padding( + vertical = 7.5f.dp, + horizontal = 12.dp + ) + ) { + Text( + text = stringResource(id = R.string.profile_delete_body), + style = FunchTheme.typography.b, + color = White + ) + } } } + if (showDialog) { + FunchDialog( + title = stringResource(id = R.string.profile_delete_body), + text = stringResource(id = R.string.dialog_text), + dismissText = stringResource(id = R.string.dialog_dismiss), + confirmText = stringResource(id = R.string.dialog_confirm), + onDismiss = { showDialog = false }, + onConfirm = onDeleteProfile + ) + } } @Composable @@ -309,7 +367,8 @@ private fun Preview1() { ) ) ), - onCloseMyProfile = {} + onCloseMyProfile = {}, + onDeleteProfile = {} ) } } @@ -332,7 +391,8 @@ private fun Preview2() { ) { MyProfileScreen( uiState = MyProfileUiState.Loading, - onCloseMyProfile = {} + onCloseMyProfile = {}, + onDeleteProfile = {} ) } } @@ -355,7 +415,8 @@ private fun Preview3() { ) { MyProfileScreen( uiState = MyProfileUiState.Error, - onCloseMyProfile = {} + onCloseMyProfile = {}, + onDeleteProfile = {} ) } } diff --git a/feature/profile/src/main/java/com/moya/funch/MyProfileViewModel.kt b/feature/profile/src/main/java/com/moya/funch/MyProfileViewModel.kt index 77148885..bc9c26e6 100644 --- a/feature/profile/src/main/java/com/moya/funch/MyProfileViewModel.kt +++ b/feature/profile/src/main/java/com/moya/funch/MyProfileViewModel.kt @@ -3,10 +3,13 @@ package com.moya.funch import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.moya.funch.entity.profile.Profile +import com.moya.funch.usecase.DeleteUserProfileUseCase import com.moya.funch.usecase.LoadUserProfileUseCase import dagger.hilt.android.lifecycle.HiltViewModel import javax.inject.Inject +import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.asSharedFlow import kotlinx.coroutines.flow.asStateFlow import kotlinx.coroutines.launch import timber.log.Timber @@ -17,14 +20,22 @@ sealed class MyProfileUiState { data object Error : MyProfileUiState() } +sealed class MyProfileEvent { + data object DeleteProfile : MyProfileEvent() +} + @HiltViewModel internal class MyProfileViewModel @Inject constructor( - private val loadUserProfileUseCase: LoadUserProfileUseCase + private val loadUserProfileUseCase: LoadUserProfileUseCase, + private val deleteUserProfileUseCase: DeleteUserProfileUseCase ) : ViewModel() { private val _uiState = MutableStateFlow(MyProfileUiState.Loading) val uiState = _uiState.asStateFlow() + private val _event = MutableSharedFlow() + val event = _event.asSharedFlow() + init { loadUserProfile() } @@ -40,4 +51,15 @@ internal class MyProfileViewModel @Inject constructor( } } } + + fun deleteUserProfile() { + viewModelScope.launch { + deleteUserProfileUseCase().onSuccess { + Timber.d(it) + _event.emit(MyProfileEvent.DeleteProfile) + }.onFailure { exception -> + Timber.e(exception) + } + } + } } diff --git a/feature/profile/src/main/java/com/moya/funch/navigation/MyProfileNavigatoin.kt b/feature/profile/src/main/java/com/moya/funch/navigation/MyProfileNavigatoin.kt index 5671809d..68d40bb3 100644 --- a/feature/profile/src/main/java/com/moya/funch/navigation/MyProfileNavigatoin.kt +++ b/feature/profile/src/main/java/com/moya/funch/navigation/MyProfileNavigatoin.kt @@ -18,7 +18,13 @@ fun NavController.navigateToCreateProfile(navOptions: NavOptions? = null) = fun NavController.onCloseMyProfile() = popBackStack() -fun NavGraphBuilder.profileGraph(onNavigateToHome: () -> Unit, onCloseMyProfile: () -> Unit) { +fun NavController.navigateToCreateProfileFromMyProfile() = popBackStack(route = PROFILE_GRAPH_ROUTE, inclusive = true) + +fun NavGraphBuilder.profileGraph( + onNavigateToHome: () -> Unit, + onCloseMyProfile: () -> Unit, + onNavigateCreateProfile: () -> Unit +) { navigation( route = PROFILE_GRAPH_ROUTE, startDestination = ProfileScreens.Create.route @@ -30,7 +36,8 @@ fun NavGraphBuilder.profileGraph(onNavigateToHome: () -> Unit, onCloseMyProfile: } composable(route = ProfileScreens.MyProfile.route) { MyProfileRoute( - onCloseMyProfile = onCloseMyProfile + onCloseMyProfile = onCloseMyProfile, + onNavigateCreateProfile = onNavigateCreateProfile ) } }