Skip to content

Commit

Permalink
Merge pull request #155 from YAPP-Github/QA/75-oboard-vote-data
Browse files Browse the repository at this point in the history
Qa/75 78 LoginScreen 실제 투표 데이터로 교체, 로고 위치 조정
  • Loading branch information
yangsooplus authored Feb 16, 2024
2 parents 75f1e29 + a3d0365 commit 94894b5
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 12 deletions.
9 changes: 9 additions & 0 deletions core/model/src/main/java/com/susu/core/model/OnboardVote.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.susu.core.model

import androidx.compose.runtime.Stable

@Stable
data class OnboardVote(
val mostContent: String,
val mostPercentage: Int,
)
7 changes: 7 additions & 0 deletions data/src/main/java/com/susu/data/data/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.susu.data.data.repository.FriendRepositoryImpl
import com.susu.data.data.repository.LedgerRecentSearchRepositoryImpl
import com.susu.data.data.repository.LedgerRepositoryImpl
import com.susu.data.data.repository.LoginRepositoryImpl
import com.susu.data.data.repository.OnboardRepositoryImpl
import com.susu.data.data.repository.ReportRepositoryImpl
import com.susu.data.data.repository.SignUpRepositoryImpl
import com.susu.data.data.repository.StatisticsRepositoryImpl
Expand All @@ -26,6 +27,7 @@ import com.susu.domain.repository.FriendRepository
import com.susu.domain.repository.LedgerRecentSearchRepository
import com.susu.domain.repository.LedgerRepository
import com.susu.domain.repository.LoginRepository
import com.susu.domain.repository.OnboardRepository
import com.susu.domain.repository.ReportRepository
import com.susu.domain.repository.SignUpRepository
import com.susu.domain.repository.StatisticsRepository
Expand Down Expand Up @@ -127,4 +129,9 @@ abstract class RepositoryModule {
abstract fun bindReportRepository(
reportRepositoryImpl: ReportRepositoryImpl,
): ReportRepository

@Binds
abstract fun bindOnboardRepository(
onboardRepositoryImpl: OnboardRepositoryImpl,
): OnboardRepository
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.susu.data.data.repository

import com.susu.core.model.OnboardVote
import com.susu.data.remote.api.OnboardService
import com.susu.domain.repository.OnboardRepository
import javax.inject.Inject

class OnboardRepositoryImpl @Inject constructor(
private val onboardService: OnboardService,
) : OnboardRepository {
override suspend fun getOnboardVote(): OnboardVote {
val result = onboardService.getOnboardVote().getOrThrow().options
val mostOption = result.maxBy { it.count }

return OnboardVote(
mostContent = mostOption.content,
mostPercentage = (mostOption.count.toFloat() / result.sumOf { it.count } * 100).toInt(),
)
}
}
10 changes: 10 additions & 0 deletions data/src/main/java/com/susu/data/remote/api/OnboardService.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.susu.data.remote.api

import com.susu.data.remote.model.response.OnboardVoteResponse
import com.susu.data.remote.retrofit.ApiResult
import retrofit2.http.GET

interface OnboardService {
@GET("votes/onboarding")
suspend fun getOnboardVote(): ApiResult<OnboardVoteResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.susu.data.remote.api.CategoryService
import com.susu.data.remote.api.EnvelopesService
import com.susu.data.remote.api.FriendService
import com.susu.data.remote.api.LedgerService
import com.susu.data.remote.api.OnboardService
import com.susu.data.remote.api.ReportService
import com.susu.data.remote.api.SignUpService
import com.susu.data.remote.api.StatisticsService
Expand Down Expand Up @@ -101,4 +102,10 @@ object ApiServiceModule {
fun providesBlockService(retrofit: Retrofit): BlockService {
return retrofit.create(BlockService::class.java)
}

@Singleton
@Provides
fun providesOnboardService(retrofit: Retrofit): OnboardService {
return retrofit.create(OnboardService::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.susu.data.remote.model.response

import kotlinx.serialization.Serializable

@Serializable
data class OnboardVoteResponse(
val options: List<OnboardVoteOption>,
)

@Serializable
data class OnboardVoteOption(
val content: String = "",
val count: Int = 0,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.susu.domain.repository

import com.susu.core.model.OnboardVote

interface OnboardRepository {
suspend fun getOnboardVote(): OnboardVote
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.susu.domain.usecase.loginsignup

import com.susu.core.common.runCatchingIgnoreCancelled
import com.susu.domain.repository.OnboardRepository
import javax.inject.Inject

class GetOnboardVoteUseCase @Inject constructor(
private val onboardRepository: OnboardRepository,
) {

suspend operator fun invoke() = runCatchingIgnoreCancelled {
onboardRepository.getOnboardVote()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fun LoginArchGraph(
) {
val fillAngle = remember { Animatable(fillFrom) }

LaunchedEffect(key1 = Unit) {
LaunchedEffect(key1 = fillUntil) {
fillAngle.animateTo(
targetValue = fillUntil,
animationSpec = tween(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.susu.feature.loginsignup.login

import com.susu.core.model.OnboardVote
import com.susu.core.ui.base.SideEffect
import com.susu.core.ui.base.UiState

Expand All @@ -11,4 +12,5 @@ sealed interface LoginEffect : SideEffect {

data class LoginState(
val isLoading: Boolean = false,
val onboardVote: OnboardVote? = null,
) : UiState
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import com.susu.core.designsystem.theme.Orange60
import com.susu.core.designsystem.theme.SusuTheme
import com.susu.core.ui.SnackbarToken
import com.susu.core.ui.SnsProviders
import com.susu.core.ui.extension.collectWithLifecycle
import com.susu.core.ui.extension.susuClickable
import com.susu.feature.loginsignup.R
import com.susu.feature.loginsignup.social.KakaoLoginHelper
Expand All @@ -65,16 +66,18 @@ fun LoginRoute(
}
}

LaunchedEffect(key1 = viewModel.sideEffect) {
viewModel.sideEffect.collect { sideEffect ->
when (sideEffect) {
is LoginEffect.ShowSnackBar -> onShowSnackBar(SnackbarToken(message = sideEffect.message))
LoginEffect.NavigateToReceived -> navigateToReceived()
LoginEffect.NavigateToSignUp -> navigateToSignUp()
}
viewModel.sideEffect.collectWithLifecycle { sideEffect ->
when (sideEffect) {
is LoginEffect.ShowSnackBar -> onShowSnackBar(SnackbarToken(message = sideEffect.message))
LoginEffect.NavigateToReceived -> navigateToReceived()
LoginEffect.NavigateToSignUp -> navigateToSignUp()
}
}

LaunchedEffect(key1 = Unit) {
viewModel.initData()
}

LoginScreen(
uiState = uiState,
transitionState = transitionState,
Expand Down Expand Up @@ -131,25 +134,48 @@ fun LoginScreen(
Spacer(modifier = Modifier.height(SusuTheme.spacing.spacing_xxxxs))
Text(text = stringResource(R.string.login_sub_header), style = SusuTheme.typography.title_m, color = Gray50)
Spacer(modifier = Modifier.height(64.dp))
LoginArchGraph(modifier = Modifier.size(200.dp))

LoginArchGraph(
modifier = Modifier.size(200.dp),
fillUntil = uiState.onboardVote?.let { it.mostPercentage.toFloat() / 100f } ?: 0.85f,
)

Spacer(modifier = Modifier.height(SusuTheme.spacing.spacing_xxxxl))

Row(
horizontalArrangement = Arrangement.spacedBy(SusuTheme.spacing.spacing_xxxxs),
) {
Text(text = stringResource(R.string.login_statistics_1), style = SusuTheme.typography.title_s)
LoginBlankText(text = "87%", state = transitionState) // TODO: 임시 하드코딩
LoginBlankText(
text = stringResource(
id = R.string.login_percentage_format,
uiState.onboardVote?.mostPercentage?.toString()
?: stringResource(id = R.string.login_statistics_unknown_percentage),
),
state = transitionState,
)
Text(text = stringResource(R.string.login_statistics_2), style = SusuTheme.typography.title_s)
}

Spacer(modifier = Modifier.height(SusuTheme.spacing.spacing_xxs))

Row(
horizontalArrangement = Arrangement.spacedBy(SusuTheme.spacing.spacing_xxxxs),
) {
LoginBlankText(text = "10만원", state = transitionState) // TODO: 임시 하드코딩
LoginBlankText(
text = uiState.onboardVote?.mostContent
?: stringResource(id = R.string.login_statistics_unknown_content),
state = transitionState,
)
Text(text = stringResource(R.string.login_statistics_3), style = SusuTheme.typography.title_s)
}

Spacer(modifier = Modifier.height(64.dp))

KakaoLoginButton(onClick = onLoginClick)
Spacer(modifier = Modifier.height(24.dp))

Spacer(modifier = Modifier.weight(1f))

Image(
modifier = Modifier.align(Alignment.CenterHorizontally),
painter = painterResource(id = com.susu.core.designsystem.R.drawable.ic_susu_logo_weak),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.susu.core.model.exception.UnknownException
import com.susu.core.ui.SnsProviders
import com.susu.core.ui.base.BaseViewModel
import com.susu.domain.usecase.loginsignup.CheckCanRegisterUseCase
import com.susu.domain.usecase.loginsignup.GetOnboardVoteUseCase
import com.susu.domain.usecase.loginsignup.LoginUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
Expand All @@ -14,8 +15,17 @@ import javax.inject.Inject
class LoginViewModel @Inject constructor(
private val checkCanRegisterUseCase: CheckCanRegisterUseCase,
private val loginUseCase: LoginUseCase,
private val getOnboardVoteUseCase: GetOnboardVoteUseCase,
) : BaseViewModel<LoginState, LoginEffect>(LoginState()) {

fun initData() = viewModelScope.launch {
getOnboardVoteUseCase().onSuccess {
intent { copy(onboardVote = it) }
}.onFailure {
intent { copy(onboardVote = null) }
}
}

fun login(provider: SnsProviders, oauthAccessToken: String) {
viewModelScope.launch {
intent { copy(isLoading = true) }
Expand Down
3 changes: 3 additions & 0 deletions feature/loginsignup/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
<string name="login_statistics_1">수수 가입자</string>
<string name="login_statistics_2">는</string>
<string name="login_statistics_3">이 적당하다고 답했어요</string>
<string name="login_percentage_format">%s%%</string>
<string name="login_statistics_unknown_content">\?만원</string>
<string name="login_statistics_unknown_percentage">\?</string>
<string name="signup_vote_question_1">친구의 결혼식,</string>
<string name="signup_vote_question_2">축의금</string>
<string name="signup_vote_question_3">"은 "</string>
Expand Down

0 comments on commit 94894b5

Please sign in to comment.