diff --git a/feature/login/src/main/java/pokitmons/pokit/LoginViewModel.kt b/feature/login/src/main/java/pokitmons/pokit/LoginViewModel.kt index 7786edf6..80becb4b 100644 --- a/feature/login/src/main/java/pokitmons/pokit/LoginViewModel.kt +++ b/feature/login/src/main/java/pokitmons/pokit/LoginViewModel.kt @@ -1,6 +1,7 @@ package pokitmons.pokit import android.content.Context +import android.util.Log import androidx.compose.runtime.MutableState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateListOf @@ -43,6 +44,9 @@ class LoginViewModel @Inject constructor( } } } + + val nicknameRegex = Regex("^[a-zA-Z0-9가-힣]+$") + private var duplicateNicknameJob: Job? = null private val _isBottomSheetVisible: MutableState = mutableStateOf(false) @@ -147,6 +151,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 = listOf( context.getString(R.string.sports_and_leisure), diff --git a/feature/login/src/main/java/pokitmons/pokit/model/DuplicateNicknameState.kt b/feature/login/src/main/java/pokitmons/pokit/model/DuplicateNicknameState.kt index 62086325..e14a75c9 100644 --- a/feature/login/src/main/java/pokitmons/pokit/model/DuplicateNicknameState.kt +++ b/feature/login/src/main/java/pokitmons/pokit/model/DuplicateNicknameState.kt @@ -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 ) diff --git a/feature/login/src/main/java/pokitmons/pokit/nickname/InputNicknameScreen.kt b/feature/login/src/main/java/pokitmons/pokit/nickname/InputNicknameScreen.kt index 89c40626..65fddeba 100644 --- a/feature/login/src/main/java/pokitmons/pokit/nickname/InputNicknameScreen.kt +++ b/feature/login/src/main/java/pokitmons/pokit/nickname/InputNicknameScreen.kt @@ -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 @@ -65,17 +66,24 @@ 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 { + + } } } } @@ -89,7 +97,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() } ) } diff --git a/feature/login/src/main/res/values/strings.xml b/feature/login/src/main/res/values/strings.xml index 0012ad0b..a6459201 100644 --- a/feature/login/src/main/res/values/strings.xml +++ b/feature/login/src/main/res/values/strings.xml @@ -10,7 +10,7 @@ 내용을 입력해주세요. 한글, 영어, 숫자로만 입력이 가능합니다. 사용 중인 닉네임입니다. - 최대 20자까지 입력 가능합니다. + 최대 10자까지 입력 가능합니다. 어떤 분야에 관심이 있으세요? 최대 3개를 골라주시면,\n관련 콘텐츠를 추천해드릴게요! 스포츠/레저 diff --git a/feature/settings/src/main/res/values/strings.xml b/feature/settings/src/main/res/values/strings.xml index fd7fc692..af92a543 100644 --- a/feature/settings/src/main/res/values/strings.xml +++ b/feature/settings/src/main/res/values/strings.xml @@ -16,6 +16,6 @@ 저장 한글, 영어, 숫자로만 입력이 가능합니다. 사용 중인 닉네임입니다. - 최대 20자까지 입력 가능합니다. + 최대 10자까지 입력 가능합니다. 닉네임을 입력해주세요 \ No newline at end of file