Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] #59 20240828 QA #62

Merged
merged 5 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion feature/login/src/main/java/pokitmons/pokit/LoginViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class LoginViewModel @Inject constructor(
}
}
}

val nicknameRegex = Regex("^[a-zA-Z0-9가-힣]+$")

private var duplicateNicknameJob: Job? = null

private val _isBottomSheetVisible: MutableState<Boolean> = mutableStateOf(false)
Expand Down Expand Up @@ -134,7 +137,7 @@ class LoginViewModel @Inject constructor(
fun checkDuplicateNickname(nickname: String) {
duplicateNicknameJob?.cancel()
duplicateNicknameJob = viewModelScope.launch {
delay(1.second())
delay(0.5.second())
when (val duplicateNicknameResult = nicknameUseCase.checkDuplicateNickname(nickname)) {
is PokitResult.Success -> {
_inputNicknameState.update { duplicateNicknameState ->
Expand All @@ -147,6 +150,13 @@ class LoginViewModel @Inject constructor(
}
}

fun checkNicknameRegex(nickname: String): Boolean {
_inputNicknameState.update { duplicateNicknameState ->
duplicateNicknameState.copy(isRegex = nicknameRegex.matches(nickname))
}
return nicknameRegex.matches(nickname)
}

fun setCategories() {
val categoryNames: List<String> = listOf(
context.getString(R.string.sports_and_leisure),
Expand Down Expand Up @@ -195,6 +205,10 @@ class LoginViewModel @Inject constructor(
return (this * 1000L)
}

private fun Double.second(): Long {
return (this * 1000L).toLong()
}

private const val LIMIT_SELECTED_COUNT = 3
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package pokitmons.pokit.model

data class DuplicateNicknameState(
val nickname: String = "",
val isDuplicate: Boolean = true,
val isDuplicate: Boolean = false,
val isRegex: Boolean = false,
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pokitmons.pokit.nickname

import android.util.Log
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand Down Expand Up @@ -65,17 +66,23 @@ fun InputNicknameScreen(
inputText = inputNicknameState.nickname,
maxLength = NICKNAME_MAX_LENGTH,
sub = when {
inputNicknameState.nickname.length < NICKNAME_MAX_LENGTH -> stringResource(id = Login.string.input_restriction_message)
!inputNicknameState.isDuplicate -> stringResource(id = Login.string.nickname_already_in_use)
else -> stringResource(id = Login.string.input_max_length)
inputNicknameState.isDuplicate -> stringResource(id = Login.string.nickname_already_in_use)
inputNicknameState.isRegex -> stringResource(id = Login.string.input_restriction_message)
inputNicknameState.nickname.length < NICKNAME_MAX_LENGTH -> stringResource(id = Login.string.input_max_length)
else -> ""
},
isError = inputNicknameState.nickname.length > NICKNAME_MAX_LENGTH || !inputNicknameState.isDuplicate,
isError = inputNicknameState.nickname.length > NICKNAME_MAX_LENGTH || inputNicknameState.isDuplicate || inputNicknameState.isRegex,
hintText = stringResource(id = Login.string.input_nickname_hint),
onChangeText = { text ->
Log.d("!! : ", text)
if (text.length <= NICKNAME_MAX_LENGTH) {
viewModel.apply {
inputText(text)
checkDuplicateNickname(text)
if (checkNicknameRegex(text)) {
Log.d("!! : ", "else call")
checkDuplicateNickname(text)
} else {
}
}
}
}
Expand All @@ -89,7 +96,7 @@ fun InputNicknameScreen(
text = stringResource(id = pokitmons.pokit.login.R.string.next),
icon = null,
size = PokitButtonSize.LARGE,
enable = !inputNicknameState.isDuplicate,
enable = !inputNicknameState.isDuplicate && inputNicknameState.isRegex && inputNicknameState.nickname.length < NICKNAME_MAX_LENGTH,
onClick = { onNavigateToKeywordScreen() }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
Expand All @@ -34,12 +33,6 @@ fun SignUpSuccessScreen(
.background(color = Color.White)
.padding(start = 20.dp, end = 20.dp, top = 20.dp, bottom = 28.dp)
) {
Icon(
modifier = Modifier.padding(start = 4.dp),
painter = painterResource(id = coreDrawable.icon_24_arrow_left),
contentDescription = null
)

Column(
modifier = Modifier
.fillMaxWidth()
Expand Down
2 changes: 1 addition & 1 deletion feature/login/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<string name="input_nickname_hint">내용을 입력해주세요.</string>
<string name="input_restriction_message">한글, 영어, 숫자로만 입력이 가능합니다.</string>
<string name="nickname_already_in_use">사용 중인 닉네임입니다.</string>
<string name="input_max_length">최대 20자까지 입력 가능합니다.</string>
<string name="input_max_length">최대 10자까지 입력 가능합니다.</string>
<string name="keyword_title">어떤 분야에 관심이 있으세요?</string>
<string name="select_keyword">최대 3개를 골라주시면,\n관련 콘텐츠를 추천해드릴게요!</string>
<string name="sports_and_leisure">스포츠/레저</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SettingViewModel @Inject constructor(
fun checkDuplicateNickname(nickname: String) {
duplicateNicknameJob?.cancel()
duplicateNicknameJob = viewModelScope.launch {
delay(1.second())
delay(0.5.second())
when (val duplicateNicknameResult = nicknameUseCase.checkDuplicateNickname(nickname)) {
is PokitResult.Success -> {
_inputNicknameState.update { duplicateNicknameState ->
Expand Down Expand Up @@ -115,6 +115,10 @@ class SettingViewModel @Inject constructor(
private fun Int.second(): Long {
return (this * 1000L)
}

private fun Double.second(): Long {
return (this * 1000L).toLong()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ fun SettingsScreen(
SettingItem(title = stringResource(StringResource.nickname_settings)) {
onNavigateToEditNickname()
}
SettingItem(title = stringResource(StringResource.notification_settings)) {
// TODO 커스텀 토스트 메세지
}

// SettingItem(title = stringResource(StringResource.notification_settings)) {
// // TODO 커스텀 토스트 메세지
// }

DividerItem()

Expand Down
2 changes: 1 addition & 1 deletion feature/settings/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
<string name="save">저장</string>
<string name="input_restriction_message">한글, 영어, 숫자로만 입력이 가능합니다.</string>
<string name="nickname_already_in_use">사용 중인 닉네임입니다.</string>
<string name="input_max_length">최대 20자까지 입력 가능합니다.</string>
<string name="input_max_length">최대 10자까지 입력 가능합니다.</string>
<string name="input_nickname_hint">닉네임을 입력해주세요</string>
</resources>
Loading