From 7a3e8d9726021cb9f1f278617521bc759f49a144 Mon Sep 17 00:00:00 2001 From: soopeach Date: Wed, 20 Nov 2024 17:32:09 +0900 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=EC=9E=84=EC=8B=9C=EB=A1=9C=20?= =?UTF-8?q?=EC=B1=8C=EB=A6=B0=EC=A7=80=20=EC=99=84=EB=A3=8C=20=EB=B2=84?= =?UTF-8?q?=ED=8A=BC=20=EB=B0=8F=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/whyranoid/walkie/KoinModules.kt | 2 +- .../challenge/ChallengeDetailScreen.kt | 29 +++++++++++++++---- .../challenge/ChallengeDetailViewModel.kt | 16 +++++++++- 3 files changed, 39 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/whyranoid/walkie/KoinModules.kt b/app/src/main/java/com/whyranoid/walkie/KoinModules.kt index 7111fb43..ac6d9f12 100644 --- a/app/src/main/java/com/whyranoid/walkie/KoinModules.kt +++ b/app/src/main/java/com/whyranoid/walkie/KoinModules.kt @@ -120,7 +120,7 @@ import java.util.concurrent.TimeUnit val viewModelModule = module { viewModel { ChallengeMainViewModel(get(), get(), get(), get(), get()) } - viewModel { ChallengeDetailViewModel(get(), get()) } + viewModel { ChallengeDetailViewModel(get(), get(), get()) } viewModel { ChallengeExitViewModel(get(), get()) } viewModel { UserPageViewModel( diff --git a/presentation/src/main/java/com/whyranoid/presentation/screens/challenge/ChallengeDetailScreen.kt b/presentation/src/main/java/com/whyranoid/presentation/screens/challenge/ChallengeDetailScreen.kt index c81f345e..496993fc 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/screens/challenge/ChallengeDetailScreen.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/screens/challenge/ChallengeDetailScreen.kt @@ -1,6 +1,5 @@ package com.whyranoid.presentation.screens.challenge -import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box @@ -32,14 +31,12 @@ import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextDecoration import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.navigation.NavController import coil.compose.AsyncImage -import com.whyranoid.presentation.R import com.whyranoid.presentation.component.ChallengeGoalContent import com.whyranoid.presentation.component.UserIcon import com.whyranoid.presentation.component.bottomsheet.ChallengeExitModalBottomSheetContainer @@ -82,9 +79,17 @@ fun ChallengeDetailScreen( ChallengeDetailSideEffect.StartChallengeFailure -> { SingleToast.show(context, "챌린지를 시작할 수 없습니다.") } + + ChallengeDetailSideEffect.ChangeChallengeStatusSuccess -> { + SingleToast.show(context, "챌린지를 성공적으로 완료하였습니다.") + navController.popBackStack() + } + + ChallengeDetailSideEffect.ChangeChallengeStatusFailure -> { + SingleToast.show(context, "챌린지 완료에 실패하였습니다.") + } } } - ChallengeDetailContent(state, isChallenging, onNegativeButtonClicked = { navController.navigate( @@ -93,7 +98,11 @@ fun ChallengeDetailScreen( }, onStartChallengeButtonClicked = { viewModel.startChallenge(it) - }) + }, + onChallengeCompleteButtonClicked = { + viewModel.changeChallengeStatus(it) + } + ) } @OptIn(ExperimentalMaterialApi::class) @@ -102,7 +111,8 @@ fun ChallengeDetailContent( state: ChallengeDetailState, isChallenging: Boolean, onNegativeButtonClicked: (Long) -> Unit = {}, - onStartChallengeButtonClicked: (Int) -> Unit = { } + onStartChallengeButtonClicked: (Int) -> Unit = { }, + onChallengeCompleteButtonClicked: (Int) -> Unit = { } ) { val coroutineScope = rememberCoroutineScope() @@ -264,6 +274,13 @@ fun ChallengeDetailContent( textDecoration = TextDecoration.Underline ) Spacer(modifier = Modifier.height(40.dp)) + + + // Todo: remove + WalkiePositiveButton(text = "완료하기") { + onChallengeCompleteButtonClicked(challenge.id) + } + } } else { Spacer(modifier = Modifier.height(28.dp)) diff --git a/presentation/src/main/java/com/whyranoid/presentation/viewmodel/challenge/ChallengeDetailViewModel.kt b/presentation/src/main/java/com/whyranoid/presentation/viewmodel/challenge/ChallengeDetailViewModel.kt index e6a3ea68..81d6a7d8 100644 --- a/presentation/src/main/java/com/whyranoid/presentation/viewmodel/challenge/ChallengeDetailViewModel.kt +++ b/presentation/src/main/java/com/whyranoid/presentation/viewmodel/challenge/ChallengeDetailViewModel.kt @@ -2,6 +2,8 @@ package com.whyranoid.presentation.viewmodel.challenge import androidx.lifecycle.ViewModel import com.whyranoid.domain.model.challenge.Challenge +import com.whyranoid.domain.usecase.ChangeChallengeStatusUseCase +import com.whyranoid.domain.usecase.CompleteChallengeUseCase import com.whyranoid.domain.usecase.GetChallengeDetailUseCase import com.whyranoid.domain.usecase.StartChallengeUseCase import com.whyranoid.presentation.model.UiState @@ -15,6 +17,9 @@ sealed class ChallengeDetailSideEffect { object StartChallengeSuccess : ChallengeDetailSideEffect() object StartChallengeFailure : ChallengeDetailSideEffect() + + object ChangeChallengeStatusSuccess : ChallengeDetailSideEffect() + object ChangeChallengeStatusFailure : ChallengeDetailSideEffect() } data class ChallengeDetailState( @@ -23,7 +28,8 @@ data class ChallengeDetailState( class ChallengeDetailViewModel( private val getChallengeDetailUseCase: GetChallengeDetailUseCase, - private val startChallengeUseCase: StartChallengeUseCase + private val startChallengeUseCase: StartChallengeUseCase, + private val changeChallengeStatusUseCase: CompleteChallengeUseCase ) : ViewModel(), ContainerHost { override val container = @@ -49,5 +55,13 @@ class ChallengeDetailViewModel( } } + + fun changeChallengeStatus(challengeId: Int) = intent { + changeChallengeStatusUseCase(challengeId).onSuccess { + postSideEffect(ChallengeDetailSideEffect.ChangeChallengeStatusSuccess) + }.onFailure { + postSideEffect(ChallengeDetailSideEffect.ChangeChallengeStatusFailure) + } + } }