Skip to content

Commit

Permalink
Merge branch 'develop' into release/1.0.3
Browse files Browse the repository at this point in the history
# Conflicts:
#	feature/sent/src/main/java/com/susu/feature/envelopesearch/SentEnvelopeSearchViewModel.kt
  • Loading branch information
yangsooplus committed Jul 10, 2024
2 parents f260d3c + 68a729b commit dc9b2a1
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 37 deletions.
1 change: 1 addition & 0 deletions core/model/src/main/java/com/susu/core/model/Term.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ data class Term(
val id: Int,
val title: String,
val isEssential: Boolean,
val canRead: Boolean = true,
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ data class TermResponse(
val id: Int,
val title: String,
val isEssential: Boolean,
val isIncludeDetail: Boolean = true,
)

@Serializable
Expand All @@ -23,6 +24,7 @@ fun TermResponse.toModel(): Term = Term(
id = id,
title = title,
isEssential = isEssential,
canRead = isIncludeDetail,
)

fun TermDetailResponse.toModel(): TermDetail = TermDetail(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.susu.core.ui.Gender
import com.susu.core.ui.base.SideEffect
import com.susu.core.ui.base.UiState
import com.susu.feature.loginsignup.R
import kotlinx.collections.immutable.PersistentSet
import kotlinx.collections.immutable.persistentSetOf

sealed interface SignUpEffect : SideEffect {
data object NavigateToLogin : SignUpEffect
Expand All @@ -16,7 +18,7 @@ sealed interface SignUpEffect : SideEffect {
data class SignUpState(
val isLoading: Boolean = false,
val currentStep: SignUpStep = SignUpStep.TERMS,
val agreedTerms: List<Int> = emptyList(),
val agreedTerms: PersistentSet<Int> = persistentSetOf(),
val name: String = "",
val isNameValid: Boolean = true,
val gender: Gender = Gender.NONE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
Expand All @@ -44,6 +45,7 @@ import com.susu.feature.loginsignup.R
import com.susu.feature.loginsignup.signup.content.AdditionalContent
import com.susu.feature.loginsignup.signup.content.NameContent
import com.susu.feature.loginsignup.signup.content.TermsContent
import kotlinx.collections.immutable.toPersistentList

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand Down Expand Up @@ -76,7 +78,15 @@ fun SignUpRoute(
}
}

Box(modifier = Modifier.fillMaxSize().padding(padding)) {
LaunchedEffect(key1 = Unit) {
termViewModel.getTermList()
}

Box(
modifier = Modifier
.fillMaxSize()
.padding(padding),
) {
SignUpScreen(
uiState = uiState,
termState = termState,
Expand Down Expand Up @@ -119,7 +129,7 @@ fun SignUpRoute(
modifier = Modifier.fillMaxSize(),
descriptionText = targetState.description?.let { stringResource(id = it) } ?: "",
terms = termState.terms,
agreedTerms = uiState.agreedTerms,
agreedTerms = uiState.agreedTerms.toPersistentList(),
onDetailClick = {
termViewModel.updateCurrentTerm(it)
viewModel.goTermDetail()
Expand Down Expand Up @@ -241,7 +251,9 @@ fun SignUpScreen(
}
content()
SusuFilledButton(
modifier = Modifier.fillMaxWidth().imePadding(),
modifier = Modifier
.fillMaxWidth()
.imePadding(),
shape = RectangleShape,
color = FilledButtonColor.Black,
style = MediumButtonStyle.height60,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import com.susu.core.ui.base.BaseViewModel
import com.susu.domain.usecase.loginsignup.SignUpUseCase
import com.susu.feature.loginsignup.social.KakaoLoginHelper
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.persistentSetOf
import kotlinx.collections.immutable.toPersistentSet
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand Down Expand Up @@ -43,19 +45,19 @@ class SignUpViewModel @Inject constructor(
}

fun agreeTerm(termId: Int) {
intent { copy(agreedTerms = agreedTerms + termId) }
intent { copy(agreedTerms = agreedTerms.add(termId)) }
}

fun disagreeTerm(termId: Int) {
intent { copy(agreedTerms = agreedTerms - termId) }
intent { copy(agreedTerms = agreedTerms.remove(termId)) }
}

fun agreeAllTerms(entireTermIds: List<Int>) {
intent { copy(agreedTerms = entireTermIds) }
intent { copy(agreedTerms = entireTermIds.toPersistentSet()) }
}

fun disagreeAllTerms() {
intent { copy(agreedTerms = emptyList()) }
intent { copy(agreedTerms = persistentSetOf()) }
}

fun goNextStep() {
Expand Down Expand Up @@ -96,7 +98,7 @@ class SignUpViewModel @Inject constructor(
} else {
null
},
termAgreement = uiState.value.agreedTerms,
termAgreement = uiState.value.agreedTerms.toList(),
),
).onSuccess {
postSideEffect(SignUpEffect.NavigateToReceived)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import com.susu.core.model.Term
import com.susu.core.model.TermDetail
import com.susu.core.ui.base.SideEffect
import com.susu.core.ui.base.UiState
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf

sealed interface TermEffect : SideEffect {
data class ShowToast(val msg: String) : TermEffect
}

data class TermState(
val isLoading: Boolean = false,
val terms: List<Term> = emptyList(),
val terms: PersistentList<Term> = persistentListOf(),
val currentTerm: TermDetail = TermDetail(0, "", false, ""),
) : UiState
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.susu.core.ui.base.BaseViewModel
import com.susu.domain.usecase.loginsignup.GetTermDetailUseCase
import com.susu.domain.usecase.loginsignup.GetTermsUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.toPersistentList
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand All @@ -14,11 +15,11 @@ class TermViewModel @Inject constructor(
private val getTermDetailUseCase: GetTermDetailUseCase,
) : BaseViewModel<TermState, TermEffect>(TermState()) {

init {
fun getTermList() {
viewModelScope.launch {
intent { copy(isLoading = true) }
getTermsUseCase().onSuccess {
intent { copy(terms = it, isLoading = false) }
intent { copy(terms = it.toPersistentList(), isLoading = false) }
}.onFailure {
postSideEffect(TermEffect.ShowToast(it.message ?: "약관을 불러오지 못했어요"))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ fun TermsContent(
title = term.title,
checked = agreedTerms.contains(term.id),
isEssential = term.isEssential,
canRead = term.canRead,
onDetailClick = { onDetailClick(term.id) },
onCheckClick = {
onTermChecked(it, term.id)
Expand All @@ -79,11 +80,13 @@ fun TermListItem(
isEssential: Boolean = true,
canRead: Boolean = true,
onCheckClick: (Boolean) -> Unit = {},
onDetailClick: (() -> Unit)? = null,
onDetailClick: (() -> Unit) = {},
) {
Row(
modifier = if (onDetailClick != null) {
modifier.susuClickable(onClick = onDetailClick).padding(vertical = SusuTheme.spacing.spacing_m)
modifier = if (canRead) {
modifier
.susuClickable(onClick = onDetailClick)
.padding(vertical = SusuTheme.spacing.spacing_m)
} else {
modifier.padding(vertical = SusuTheme.spacing.spacing_m)
},
Expand Down Expand Up @@ -122,7 +125,11 @@ fun TermsContentPreview() {
TermsContent(
modifier = Modifier.fillMaxSize(),
descriptionText = "어쩌구저쩌구\n뭐를해주세요",
terms = listOf(Term(1, "노예 계약", true), Term(2, "농노 계약", true)),
terms = listOf(
Term(0, "14세 이상?", true, false),
Term(1, "노예 계약", true),
Term(2, "농노 계약", true),
),
)
}
}
Expand Down
1 change: 1 addition & 0 deletions feature/loginsignup/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@
<string name="login_snackbar_unknown_error">알 수 없는 에러가 발생했어요</string>
<string name="login_snackbar_kakao_server_error">카카오톡 서버에서 에러가 발생했어요</string>
<string name="signup_snackbar_kakao_login_error">카카오톡 로그인 에러가 발생했어요</string>
<string name="signup_term_over_14">만 14세 이상입니다.</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import com.susu.domain.usecase.friend.SearchFriendUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toPersistentList
import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand Down Expand Up @@ -52,35 +54,38 @@ class SentEnvelopeSearchViewModel @Inject constructor(
}

fun getEnvelopeList(search: String) = viewModelScope.launch {
if (search.isEmpty()) return@launch

val searchedFriends = searchFriendUseCase(search).getOrThrow()

// 친구 검색 결과가 존재하면 봉투 검색
val envelopesByFriend = if (searchedFriends.isNotEmpty()) {
searchSentEnvelopeListUseCase(
param = SearchSentEnvelopeListUseCase.Param(
friendIds = searchedFriends.map { it.friend.id.toInt() },
),
)
} else {
Result.success(emptyList())
val envelopesByFriend = async {
if (searchedFriends.isNotEmpty()) {
searchSentEnvelopeListUseCase(
param = SearchSentEnvelopeListUseCase.Param(
friendIds = searchedFriends.map { it.friend.id.toInt() },
),
).getOrDefault(emptyList())
} else {
emptyList()
}
}

// 숫자 형식일 경우는 금액으로 봉투 검색
val envelopesByAmount = search.toLongOrNull()?.let { amount ->
searchSentEnvelopeListUseCase(
param = SearchSentEnvelopeListUseCase.Param(
fromAmount = amount,
toAmount = amount,
),
)
} ?: Result.success(emptyList())
val envelopesByAmount = async {
search.toLongOrNull()?.let { amount ->
searchSentEnvelopeListUseCase(
param = SearchSentEnvelopeListUseCase.Param(
fromAmount = amount,
toAmount = amount,
),
).getOrDefault(emptyList())
} ?: emptyList()
}

// 두가지 조건을 검색 완료 시 결과를 통합 표시
if (envelopesByFriend.isSuccess && envelopesByAmount.isSuccess) {
val searchedEnvelopes =
envelopesByFriend.getOrDefault(emptyList()) + envelopesByAmount.getOrDefault(emptyList())
intent { copy(envelopeList = searchedEnvelopes.toPersistentList()) }
}
val result = awaitAll(envelopesByFriend, envelopesByAmount).flatten()
intent { copy(envelopeList = result.toPersistentList()) }
}

private fun updateRecentSearchList(searchList: List<String>) {
Expand Down

0 comments on commit dc9b2a1

Please sign in to comment.