Skip to content

Commit

Permalink
✨ 임시로 챌린지 완료 버튼 및 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
soopeach committed Nov 20, 2024
1 parent 40bc09c commit 7a3e8d9
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion app/src/main/java/com/whyranoid/walkie/KoinModules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -93,7 +98,11 @@ fun ChallengeDetailScreen(
},
onStartChallengeButtonClicked = {
viewModel.startChallenge(it)
})
},
onChallengeCompleteButtonClicked = {
viewModel.changeChallengeStatus(it)
}
)
}

@OptIn(ExperimentalMaterialApi::class)
Expand All @@ -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()
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -15,6 +17,9 @@ sealed class ChallengeDetailSideEffect {

object StartChallengeSuccess : ChallengeDetailSideEffect()
object StartChallengeFailure : ChallengeDetailSideEffect()

object ChangeChallengeStatusSuccess : ChallengeDetailSideEffect()
object ChangeChallengeStatusFailure : ChallengeDetailSideEffect()
}

data class ChallengeDetailState(
Expand All @@ -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<ChallengeDetailState, ChallengeDetailSideEffect> {

override val container =
Expand All @@ -49,5 +55,13 @@ class ChallengeDetailViewModel(
}

}

fun changeChallengeStatus(challengeId: Int) = intent {
changeChallengeStatusUseCase(challengeId).onSuccess {
postSideEffect(ChallengeDetailSideEffect.ChangeChallengeStatusSuccess)
}.onFailure {
postSideEffect(ChallengeDetailSideEffect.ChangeChallengeStatusFailure)
}
}
}

0 comments on commit 7a3e8d9

Please sign in to comment.