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/profile #51

Merged
merged 3 commits into from
Aug 22, 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
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fun BoardTopView(
indication = null,
onClick = onClickTooltip
)
.padding(end = 43.dp,top = 48.dp)
.padding(end = 43.dp,top = 56.dp)
.width(161.dp),
drawableResId = R.drawable.img_tooltip_mission_invitation_code,
contentScale = ContentScale.Crop
Expand All @@ -106,7 +106,7 @@ fun BoardTopView(
indication = null,
onClick = onClickTooltip
)
.padding(start = 8.dp, top = 48.dp)
.padding(start = 8.dp, top = 56.dp)
.width(161.dp),
drawableResId = R.drawable.img_tooltip_mission_detail,
contentScale = ContentScale.Crop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ fun BoardSetupSuccessScreen(
Text(
modifier = Modifier
.statusBarsPadding()
.padding(top = 48.dp, bottom = 52.dp),
.padding(top = 56.dp, bottom = 52.dp),
text = stringResource(id = R.string.onboarding_board_setup_success_title),
style = MissionMateTypography.heading_sm_bold,
color = ColorGray1_FF404249,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import com.goalpanzi.core.model.CharacterType
import com.goalpanzi.mission_mate.core.designsystem.component.MissionMateButtonType
import com.goalpanzi.mission_mate.core.designsystem.component.MissionMateTextButton
import com.goalpanzi.mission_mate.core.designsystem.component.MissionMateTextFieldGroup
Expand All @@ -59,12 +60,10 @@ import com.goalpanzi.mission_mate.core.designsystem.theme.ColorWhite_FFFFFFFF
import com.goalpanzi.mission_mate.core.designsystem.theme.MissionMateTypography
import com.goalpanzi.mission_mate.core.designsystem.theme.component.MissionMateTopAppBar
import com.goalpanzi.mission_mate.core.designsystem.theme.component.NavigationType
import com.goalpanzi.core.model.CharacterType
import com.goalpanzi.mission_mate.feature.profile.model.CharacterListItem
import com.goalpanzi.mission_mate.feature.profile.model.ProfileUiState
import com.luckyoct.feature.profile.R
import dagger.hilt.android.EntryPointAccessors
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.collectLatest

@Composable
Expand All @@ -87,7 +86,7 @@ fun ProfileRoute(
val viewModel = profileViewModel(profileSettingType = profileSettingType)
val context = LocalContext.current
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val isInvalidNickname by viewModel.isInvalidNickname.collectAsStateWithLifecycle()
val isNicknameDuplicated by viewModel.isNicknameDuplicated.collectAsStateWithLifecycle()
val isNotChangedProfileInput by viewModel.isNotChangedProfileInput.collectAsStateWithLifecycle()

val keyboardController = LocalSoftwareKeyboardController.current
Expand Down Expand Up @@ -131,8 +130,8 @@ fun ProfileRoute(
viewModel.saveProfile(it)
},
onBackClick = onBackClick,
isInvalidNickname = isInvalidNickname,
resetNicknameErrorState = { viewModel.resetNicknameErrorState() }
isNicknameDuplicated = isNicknameDuplicated,
resetNicknameErrorState = { viewModel.resetNicknameErrorState() },
)
}
}
Expand All @@ -146,7 +145,7 @@ fun ProfileContent(
onClickCharacter: (CharacterListItem) -> Unit = {},
onClickSave: (String) -> Unit = {},
onBackClick: (() -> Unit)? = null,
isInvalidNickname: Boolean,
isNicknameDuplicated: Boolean,
resetNicknameErrorState: () -> Unit
) {
Column(
Expand Down Expand Up @@ -175,8 +174,7 @@ fun ProfileContent(
isNotChangedProfileInput = isNotChangedProfileInput,
onClickCharacter = onClickCharacter,
onClickSave = onClickSave,
isInvalidNickname = isInvalidNickname,
resetNicknameErrorState = resetNicknameErrorState
isNicknameDuplicated = isNicknameDuplicated,
)
}
}
Expand All @@ -192,12 +190,17 @@ fun ColumnScope.ProfileScreen(
isNotChangedProfileInput: Boolean,
onClickCharacter: (CharacterListItem) -> Unit,
onClickSave: (String) -> Unit,
isInvalidNickname: Boolean,
resetNicknameErrorState: () -> Unit = {}
isNicknameDuplicated: Boolean,
) {
var nicknameInput by remember { mutableStateOf(initialNickname) }
val scrollState = rememberScrollState()
val regex = Regex("^[가-힣ㅏ-ㅣㄱ-ㅎa-zA-Z0-9]{1,6}$")
var invalidNicknameError by remember { mutableStateOf(false) }

LaunchedEffect(nicknameInput) {
if (nicknameInput.isEmpty()) return@LaunchedEffect
invalidNicknameError = (nicknameInput.length > 6 || regex.matches(nicknameInput).not())
}

Column(
modifier = modifier
Expand All @@ -216,7 +219,7 @@ fun ColumnScope.ProfileScreen(
),
modifier = modifier
.align(Alignment.CenterHorizontally)
.padding(top = 48.dp),
.padding(top = if (profileSettingType == ProfileSettingType.SETTING) 0.dp else 56.dp),
style = MissionMateTypography.heading_sm_bold,
color = ColorGray1_FF404249
)
Expand Down Expand Up @@ -245,15 +248,10 @@ fun ColumnScope.ProfileScreen(
.fillMaxWidth()
.wrapContentHeight(),
text = nicknameInput,
onValueChange = {
if (regex.matches(it) || it.isEmpty()) {
nicknameInput = it
}
resetNicknameErrorState()
},
onValueChange = { nicknameInput = it },
hintId = R.string.nickname_hint,
guidanceId = if (isInvalidNickname) R.string.err_duplicated_nickname else R.string.nickname_input_guide,
isError = isInvalidNickname
guidanceId = if (isNicknameDuplicated) R.string.err_duplicated_nickname else R.string.nickname_input_guide,
isError = invalidNicknameError || isNicknameDuplicated
)
}

Expand All @@ -262,20 +260,23 @@ fun ColumnScope.ProfileScreen(
.padding(bottom = 36.dp, start = 24.dp, end = 24.dp)
.fillMaxWidth(),
textId = R.string.save,
buttonType =
if (profileSettingType == ProfileSettingType.CREATE) {
if (nicknameInput.trim().isEmpty()) {
MissionMateButtonType.DISABLED
} else {
MissionMateButtonType.ACTIVE
buttonType = when (profileSettingType) {
ProfileSettingType.CREATE -> {
if (nicknameInput.trim().isEmpty() || invalidNicknameError) {
MissionMateButtonType.DISABLED
} else {
MissionMateButtonType.ACTIVE
}
}
} else {
if ((initialNickname == nicknameInput && isNotChangedProfileInput) ||
nicknameInput.trim().isEmpty()
) {
MissionMateButtonType.DISABLED
} else {
MissionMateButtonType.ACTIVE

ProfileSettingType.SETTING -> {
if ((initialNickname == nicknameInput && isNotChangedProfileInput) ||
nicknameInput.trim().isEmpty() || invalidNicknameError
) {
MissionMateButtonType.DISABLED
} else {
MissionMateButtonType.ACTIVE
}
}
},
onClick = { onClickSave(nicknameInput) }
Expand Down Expand Up @@ -409,8 +410,8 @@ fun ColumnScope.ProfileScreenPreview() {
),
onClickCharacter = {},
onClickSave = {},
isInvalidNickname = false,
isNotChangedProfileInput = false
isNicknameDuplicated = false,
isNotChangedProfileInput = false,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class ProfileViewModel @AssistedInject constructor(
private val _uiState = MutableStateFlow<ProfileUiState>(ProfileUiState.Loading)
val uiState = _uiState.asStateFlow()

private val _isInvalidNickname = MutableStateFlow(false)
val isInvalidNickname = _isInvalidNickname.asStateFlow()
private val _isNicknameDuplicated = MutableStateFlow(false)
val isNicknameDuplicated = _isNicknameDuplicated.asStateFlow()

private val _isNotChangedProfileInput = MutableStateFlow(true)
val isNotChangedProfileInput : StateFlow<Boolean> = _isNotChangedProfileInput.asStateFlow()
val isNotChangedProfileInput: StateFlow<Boolean> = _isNotChangedProfileInput.asStateFlow()

private val _isSaveSuccess = MutableSharedFlow<Boolean>()
val isSaveSuccess = _isSaveSuccess.asSharedFlow()
Expand Down Expand Up @@ -87,6 +87,20 @@ class ProfileViewModel @AssistedInject constructor(
}
}

// fun updateNickname(input: String) {
// viewModelScope.launch {
// _invalidNicknameError.emit(
// if (input.length > 6) {
// InvalidNicknameError.TooLong
// } else if (input.contains(Regex("[^가-힣a-zA-Z0-9]"))) {
// InvalidNicknameError.IncludeSpecial
// } else {
// InvalidNicknameError.Duplicated
// }
// )
// }
// }

fun selectCharacter(character: CharacterListItem) {
val state = uiState.value as? ProfileUiState.Success ?: return
_uiState.value = state.copy(
Expand All @@ -101,7 +115,7 @@ class ProfileViewModel @AssistedInject constructor(
}

fun resetNicknameErrorState() {
_isInvalidNickname.value = false
_isNicknameDuplicated.value = false
}

fun saveProfile(nickname: String) {
Expand All @@ -111,7 +125,7 @@ class ProfileViewModel @AssistedInject constructor(
it.isSelected
} ?: return@launch

when(
when (
val response = profileUseCase
.saveProfile(
nickname = nickname,
Expand All @@ -122,13 +136,14 @@ class ProfileViewModel @AssistedInject constructor(
is NetworkResult.Success -> {
_isSaveSuccess.emit(true)
}

is NetworkResult.Exception -> {}
is NetworkResult.Error -> {
if (response.code == 409) {
_isInvalidNickname.emit(true)
_isNicknameDuplicated.emit(true)
}
}
}
}
}
}
}
Loading