Skip to content

Commit

Permalink
[feat]: LO00 디자인 & 기능 QA (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
jinuemong authored Mar 6, 2024
1 parent 1c0cfc2 commit d2e9f31
Show file tree
Hide file tree
Showing 10 changed files with 202 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package ac.dnd.mour.android.presentation.ui.main.home.mypage

sealed interface MyPageIntent {
data object OnLogout : MyPageIntent
data object OnLoad : MyPageIntent
}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ private fun MyPageScreen(
handler: CoroutineExceptionHandler
) {

LaunchedEffectWithLifecycle(context = handler) {
intent(MyPageIntent.OnLoad)
}

val scope = rememberCoroutineScope()
val context = LocalContext.current
var isShowingLogoutDialog by remember { mutableStateOf(false) }
Expand All @@ -118,7 +122,7 @@ private fun MyPageScreen(
ContextCompat.startActivity(context, browserIntent, null)
}

fun navigateToTermsOfUse(){
fun navigateToTermsOfUse() {
val browserIntent =
Intent(
Intent.ACTION_VIEW,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class MyPageViewModel @Inject constructor(
fun onIntent(intent: MyPageIntent) {
when (intent) {
MyPageIntent.OnLogout -> logout()
MyPageIntent.OnLoad -> getProfile()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
package ac.dnd.mour.android.presentation.ui.main.home.mypage.profile

import ac.dnd.mour.android.domain.model.member.Profile

sealed interface MyPageProfileEvent {
sealed interface LoadProfile : MyPageProfileEvent {
data class Success(val profile: Profile) : LoadProfile
}

sealed interface Edit : MyPageProfileEvent {
data object Success : Edit
}

sealed interface CheckName : MyPageProfileEvent {
data object Success : CheckName
data object Fail : CheckName
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ sealed interface MyPageProfileIntent {
val profile: Profile,
val imageName: String
) : MyPageProfileIntent

data class CheckName(
val name: String
) : MyPageProfileIntent
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,88 @@ fun MyPageProfileScreen(
var currentImageUrl by remember { mutableStateOf(model.profile.profileImageUrl) }
var currentImageName by remember { mutableStateOf("") }
var isShowingEditSnackBar by remember { mutableStateOf(false) }
var isShowingInvalidNameSnackBar by remember { mutableStateOf(false) }
var isShowingInvalidDateSnackBar by remember { mutableStateOf(false) }

fun loadProfile(event: MyPageProfileEvent.LoadProfile) {
when (event) {
is MyPageProfileEvent.LoadProfile.Success -> {
event.profile.apply {
userNameText = nickname
userYearText = birth.year.toString()
userMonthText = birth.monthNumber.toString()
userDayText = birth.dayOfMonth.toString()
userGender = if (gender == "male") "남자" else "여자"
currentImageUrl = profileImageUrl
}
}
}
}

fun checkDate(birth: LocalDate): Boolean {
return if (birth.year != 1) {
true
} else {
scope.launch {
isShowingInvalidDateSnackBar = true
delay(1000L)
isShowingInvalidDateSnackBar = false
}
false
}
}

fun saveProfile() {
val birth = try {
LocalDate(
userYearText.toInt(),
userMonthText.toInt(),
userDayText.toInt()
)
} catch (e: Exception) {
LocalDate(1, 1, 1)
}
if (!isUserNameInValid && userNameText.isNotEmpty() && checkDate(birth)) {
intent(
MyPageProfileIntent.OnEdit(
Profile(
id = model.profile.id,
email = model.profile.email,
profileImageUrl = currentImageUrl,
name = model.profile.name,
nickname = userNameText,
gender = if (userGender == "남자") "male" else "female",
birth = birth
),
imageName = currentImageName
)
)
}
}

fun checkNicknameChange() {
if (model.profile.nickname != userNameText) {
intent(MyPageProfileIntent.CheckName(userNameText))
} else {
saveProfile()
}
}

fun checkNickName(event: MyPageProfileEvent.CheckName) {
when (event) {
is MyPageProfileEvent.CheckName.Success -> {
saveProfile()
}

is MyPageProfileEvent.CheckName.Fail -> {
scope.launch {
isShowingInvalidNameSnackBar = true
delay(1000L)
isShowingInvalidNameSnackBar = false
}
}
}
}

Box(
modifier = Modifier
Expand Down Expand Up @@ -183,7 +265,7 @@ fun MyPageProfileScreen(
}
Spacer(modifier = Modifier.height(60.dp))
Text(
text = "이름",
text = "닉네임",
style = Body1.merge(
color = Gray700,
fontWeight = FontWeight.SemiBold
Expand Down Expand Up @@ -335,31 +417,7 @@ fun MyPageProfileScreen(
type = ConfirmButtonType.Primary
),
onClick = {
val birth = try {
LocalDate(
userYearText.toInt(),
userMonthText.toInt(),
userDayText.toInt()
)
} catch (e: Exception) {
LocalDate(1, 1, 1)
}
if (!isUserNameInValid && userNameText.isNotEmpty() && birth.year != 1) {
intent(
MyPageProfileIntent.OnEdit(
Profile(
id = model.profile.id,
email = model.profile.email,
profileImageUrl = currentImageUrl,
name = model.profile.name,
nickname = userNameText,
gender = if (userGender == "남자") "male" else "female",
birth = birth
),
imageName = currentImageName
)
)
}
checkNicknameChange()
}
) {
Text(
Expand All @@ -381,6 +439,26 @@ fun MyPageProfileScreen(
SnackBarScreen("저장이 완료되었습니다.")
}
}

if (isShowingInvalidNameSnackBar) {
Box(
modifier = Modifier
.align(Alignment.BottomCenter)
.padding(bottom = 71.dp)
) {
SnackBarScreen("이미 존재하는 닉네임입니다.")
}
}

if (isShowingInvalidDateSnackBar) {
Box(
modifier = Modifier
.align(Alignment.BottomCenter)
.padding(bottom = 71.dp)
) {
SnackBarScreen("생년월일이 유효하지 않습니다.")
}
}
}

if (isShowingGalleryView) {
Expand All @@ -397,16 +475,21 @@ fun MyPageProfileScreen(
}



LaunchedEffectWithLifecycle(event, handler) {
event.eventObserve { event ->
when (event) {
is MyPageProfileEvent.LoadProfile -> loadProfile(event)

is MyPageProfileEvent.Edit -> {
scope.launch {
isShowingEditSnackBar = true
delay(1000L)
isShowingEditSnackBar = false
}
}

is MyPageProfileEvent.CheckName -> checkNickName(event)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ac.dnd.mour.android.presentation.ui.main.home.mypage.profile

import ac.dnd.mour.android.domain.model.error.ServerException
import ac.dnd.mour.android.domain.model.member.Profile
import ac.dnd.mour.android.domain.usecase.member.CheckNicknameUseCase
import ac.dnd.mour.android.domain.usecase.member.EditProfileUseCase
import ac.dnd.mour.android.domain.usecase.member.EditProfileWithUploadUseCase
import ac.dnd.mour.android.domain.usecase.member.GetProfileUseCase
Expand All @@ -24,6 +25,7 @@ class MyPageProfileViewModel @Inject constructor(
private val editProfileUseCase: EditProfileUseCase,
private val editProfileWithUploadUseCase: EditProfileWithUploadUseCase,
private val getProfileUseCase: GetProfileUseCase,
private val checkNicknameUseCase: CheckNicknameUseCase
) : BaseViewModel() {

private val _state: MutableStateFlow<MyPageProfileState> =
Expand Down Expand Up @@ -62,6 +64,10 @@ class MyPageProfileViewModel @Inject constructor(
)
}
}

is MyPageProfileIntent.CheckName -> {
checkUserNameValid(intent.name)
}
}
}

Expand All @@ -72,6 +78,7 @@ class MyPageProfileViewModel @Inject constructor(
.onSuccess {
_state.value = MyPageProfileState.Init
_profile.value = it
_event.emit(MyPageProfileEvent.LoadProfile.Success(it))
}
.onFailure { exception ->
_state.value = MyPageProfileState.Init
Expand Down Expand Up @@ -99,6 +106,7 @@ class MyPageProfileViewModel @Inject constructor(
)
.onSuccess {
_state.value = MyPageProfileState.Init
_profile.value = profile
_event.emit(MyPageProfileEvent.Edit.Success)
}
.onFailure { exception ->
Expand Down Expand Up @@ -147,4 +155,20 @@ class MyPageProfileViewModel @Inject constructor(
}
}
}

private fun checkUserNameValid(name: String) {
launch {
checkNicknameUseCase(name)
.onSuccess {
if (it) {
_event.emit(MyPageProfileEvent.CheckName.Success)
} else {
_event.emit(MyPageProfileEvent.CheckName.Fail)
}
}
.onFailure {
_event.emit(MyPageProfileEvent.CheckName.Fail)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ fun MyPageSettingWithdrawScreen(
) {
ConfirmButton(
modifier = Modifier.fillMaxWidth(),
properties = ConfirmButtonProperties(
properties = ConfirmButtonProperties(
size = ConfirmButtonSize.Xlarge,
type = ConfirmButtonType.Primary
type = if (isCheckAgree) ConfirmButtonType.Primary else ConfirmButtonType.Secondary
),
isEnabled = isCheckAgree,
onClick = {
Expand Down
Loading

0 comments on commit d2e9f31

Please sign in to comment.