diff --git a/app/src/main/java/com/whyranoid/walkie/KoinModules.kt b/app/src/main/java/com/whyranoid/walkie/KoinModules.kt index 7111fb4..ac6d9f1 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 c81f345..496993f 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 e6a3ea6..81d6a7d 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) + } + } }